Skip to content

Commit

Permalink
Add some tests for changing the app version properties (#15338)
Browse files Browse the repository at this point in the history
* Revert "Set Version for Windows (#15238)"

This reverts commit 130f788.

* Add the test

* tbis

* oops
  • Loading branch information
mattleibow committed Jun 1, 2023
1 parent b907e96 commit bd31a9a
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 11 deletions.
8 changes: 8 additions & 0 deletions src/Core/src/nuget/buildTransitive/WinUI.targets
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
<!-- Workarounds for WinUI -->
<Project>

<!--
NOTE: workaround https://github.com/NuGet/Home/issues/6461
We should also follow Android, iOS, etc. workloads.
-->
<PropertyGroup>
<Version Condition=" '$(ApplicationDisplayVersion)' != '' ">$(ApplicationDisplayVersion)</Version>
</PropertyGroup>

<Target Name="_AddMauiPriFiles" AfterTargets="ResolveAssemblyReferences">
<ItemGroup>
<_ReferenceRelatedPaths
Expand Down
27 changes: 27 additions & 0 deletions src/TestUtils/src/Microsoft.Maui.IntegrationTests/TemplateTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,33 @@ public void BuildWithoutPackageReference(string id, string framework, string con
$"Project {Path.GetFileName(projectFile)} failed to build. Check test output/attachments for errors.");
}

[Test]
[TestCase("maui", "Debug", "2.0", "2")]
[TestCase("maui", "Release", "2.0", "2")]
[TestCase("maui", "Release", "0.3", "3")]
[TestCase("maui-blazor", "Debug", "2.0", "2")]
[TestCase("maui-blazor", "Release", "2.0", "2")]
[TestCase("maui-blazor", "Release", "0.3", "3")]
public void BuildWithDifferentVersionNumber(string id, string config, string display, string version)
{
var projectDir = TestDirectory;
var projectFile = Path.Combine(projectDir, $"{Path.GetFileName(projectDir)}.csproj");

Assert.IsTrue(DotnetInternal.New(id, projectDir),
$"Unable to create template {id}. Check test output for errors.");

EnableTizen(projectFile);
FileUtilities.ReplaceInFile(projectFile,
$"<ApplicationDisplayVersion>1.0</ApplicationDisplayVersion>",
$"<ApplicationDisplayVersion>{display}</ApplicationDisplayVersion>");
FileUtilities.ReplaceInFile(projectFile,
$"<ApplicationVersion>1</ApplicationVersion>",
$"<ApplicationVersion>{version}</ApplicationVersion>");

Assert.IsTrue(DotnetInternal.Build(projectFile, config, properties: BuildProps),
$"Project {Path.GetFileName(projectFile)} failed to build. Check test output/attachments for errors.");
}

void EnableTizen(string projectFile)
{
FileUtilities.ReplaceInFile(projectFile, new Dictionary<string, string>()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,14 @@ public static bool Build(string projectFile, string config, string target = "",
return Run("build", $"{buildArgs} -bl:\"{binlogPath}\"");
}

public static bool New(string shortName, string outputDirectory, string framework)
public static bool New(string shortName, string outputDirectory, string framework = "")
{
var output = RunForOutput("new", $"{shortName} -o \"{outputDirectory}\" -f {framework}", out int exitCode, timeoutInSeconds: 300);
var args = $"{shortName} -o \"{outputDirectory}\"";

if (!string.IsNullOrEmpty(framework))
args += $" -f {framework}";

var output = RunForOutput("new", args, out int exitCode, timeoutInSeconds: 300);
TestContext.WriteLine(output);
return exitCode == 0;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,4 @@
<_MauiUsingDefaultRuntimeIdentifier>true</_MauiUsingDefaultRuntimeIdentifier>
</PropertyGroup>

<!--
Workaround for https://github.com/NuGet/Home/issues/6461
By default, Android and iOS set the Version property, so we need to do the same for Windows.
This also has to be done outside of the NuGets as this affects the NuGet restore.
-->
<PropertyGroup Condition=" '$([MSBuild]::GetTargetPlatformIdentifier($(TargetFramework)))' == 'windows' and '$(OutputType)' == 'WinExe' ">
<Version Condition=" $([System.Version]::TryParse ('$(ApplicationDisplayVersion)', $([System.Version]::Parse('1.0')))) ">$(ApplicationDisplayVersion)</Version>
</PropertyGroup>

</Project>

0 comments on commit bd31a9a

Please sign in to comment.