Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add some tests for changing the app version properties #15338

Merged
merged 4 commits into from
Jun 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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
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>