From 2b4c48d77cfddc79c6a7a8e2cd88927e71c449b0 Mon Sep 17 00:00:00 2001 From: Lakshan Fernando Date: Wed, 7 Sep 2022 09:14:24 -0700 Subject: [PATCH 1/3] Fix Test to match runtime changes --- .../GivenThatWeWantToPublishAnAotApp.cs | 34 ++++++++----------- 1 file changed, 14 insertions(+), 20 deletions(-) diff --git a/src/Tests/Microsoft.NET.Publish.Tests/GivenThatWeWantToPublishAnAotApp.cs b/src/Tests/Microsoft.NET.Publish.Tests/GivenThatWeWantToPublishAnAotApp.cs index f4a88b1db5f8..631e0bc2b77a 100644 --- a/src/Tests/Microsoft.NET.Publish.Tests/GivenThatWeWantToPublishAnAotApp.cs +++ b/src/Tests/Microsoft.NET.Publish.Tests/GivenThatWeWantToPublishAnAotApp.cs @@ -272,7 +272,7 @@ public void NativeAot_hw_runs_with_PackageReference_PublishAot_is_enabled(string testProject.AdditionalProperties["PublishAot"] = "true"; // This will add a reference to a package that will also be automatically imported by the SDK - testProject.PackageReferences.Add(new TestPackageReference("Microsoft.DotNet.ILCompiler", "7.0.0-rc.1.22416.1")); + testProject.PackageReferences.Add(new TestPackageReference("Microsoft.DotNet.ILCompiler", "7.0.0-rc.2.22456.11")); // Linux symbol files are embedded and require additional steps to be stripped to a separate file // assumes /bin (or /usr/bin) are in the PATH @@ -285,12 +285,10 @@ public void NativeAot_hw_runs_with_PackageReference_PublishAot_is_enabled(string var publishCommand = new PublishCommand(Log, Path.Combine(testAsset.TestRoot, testProject.Name)); publishCommand .Execute($"/p:RuntimeIdentifier={rid}") - .Should().Pass(); + .Should().Pass() // Having an explicit package reference will generate a warning - // Comment back after the below issue is fixed - // https://github.com/dotnet/sdk/issues/27533 - //.And.HaveStdOutContaining("warning") - //.And.HaveStdOutContaining("Microsoft.DotNet.ILCompiler"); + .And.HaveStdOutContaining("warning") + .And.HaveStdOutContaining("Microsoft.DotNet.ILCompiler"); var publishDirectory = publishCommand.GetOutputDirectory(targetFramework: targetFramework, runtimeIdentifier: rid).FullName; var sharedLibSuffix = RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ? ".dll" : ".so"; @@ -324,7 +322,7 @@ public void NativeAot_hw_runs_with_PackageReference_PublishAot_is_empty(string t var testProject = CreateHelloWorldTestProject(targetFramework, projectName, true); // This will add a reference to a package that will also be automatically imported by the SDK - testProject.PackageReferences.Add(new TestPackageReference("Microsoft.DotNet.ILCompiler", "7.0.0-rc.1.22416.1")); + testProject.PackageReferences.Add(new TestPackageReference("Microsoft.DotNet.ILCompiler", "7.0.0-rc.2.22456.11")); // Linux symbol files are embedded and require additional steps to be stripped to a separate file // assumes /bin (or /usr/bin) are in the PATH @@ -344,9 +342,7 @@ public void NativeAot_hw_runs_with_PackageReference_PublishAot_is_empty(string t var publishedExe = Path.Combine(publishDirectory, $"{testProject.Name}{Constants.ExeSuffix}"); // Not setting PublishAot to true will be a normal publish - // Comment back after the below issue is fixed - // https://github.com/dotnet/sdk/issues/27533 - // File.Exists(publishedDll).Should().BeTrue(); + File.Exists(publishedDll).Should().BeTrue(); var command = new RunExeCommand(Log, publishedExe) .Execute().Should().Pass() @@ -395,20 +391,18 @@ public void NativeAot_hw_runs_with_cross_PackageReference_PublishAot_is_enabled( testProject.AdditionalProperties["PublishAot"] = "true"; // This will add a reference to a package that will also be automatically imported by the SDK - testProject.PackageReferences.Add(new TestPackageReference("Microsoft.DotNet.ILCompiler", "7.0.0-rc.1.22416.1")); - testProject.PackageReferences.Add(new TestPackageReference("runtime.win-x64.Microsoft.DotNet.ILCompiler", "7.0.0-rc.1.22416.1")); + testProject.PackageReferences.Add(new TestPackageReference("Microsoft.DotNet.ILCompiler", "7.0.0-rc.2.22456.11")); + testProject.PackageReferences.Add(new TestPackageReference("runtime.win-x64.Microsoft.DotNet.ILCompiler", "7.0.0-rc.2.22456.11")); var testAsset = _testAssetsManager.CreateTestProject(testProject); var publishCommand = new PublishCommand(Log, Path.Combine(testAsset.TestRoot, testProject.Name)); publishCommand .Execute($"/p:RuntimeIdentifier={rid}") - .Should().Pass(); + .Should().Pass() // Having an explicit package reference will generate a warning - // Comment back after the below issue is fixed - // https://github.com/dotnet/sdk/issues/27533 - //.And.HaveStdOutContaining("warning") - //.And.HaveStdOutContaining("Microsoft.DotNet.ILCompiler"); + .And.HaveStdOutContaining("warning") + .And.HaveStdOutContaining("Microsoft.DotNet.ILCompiler"); var publishDirectory = publishCommand.GetOutputDirectory(targetFramework: targetFramework, runtimeIdentifier: rid).FullName; var publishedDll = Path.Combine(publishDirectory, $"{projectName}.dll"); @@ -430,8 +424,8 @@ public void NativeAot_hw_runs_with_cross_PackageReference_PublishAot_is_empty(st var testProject = CreateHelloWorldTestProject(targetFramework, projectName, true); // This will add a reference to a package that will also be automatically imported by the SDK - testProject.PackageReferences.Add(new TestPackageReference("Microsoft.DotNet.ILCompiler", "7.0.0-rc.1.22416.1")); - testProject.PackageReferences.Add(new TestPackageReference("runtime.win-x64.Microsoft.DotNet.ILCompiler", "7.0.0-rc.1.22416.1")); + testProject.PackageReferences.Add(new TestPackageReference("Microsoft.DotNet.ILCompiler", "7.0.0-rc.2.22456.11")); + testProject.PackageReferences.Add(new TestPackageReference("runtime.win-x64.Microsoft.DotNet.ILCompiler", "7.0.0-rc.2.22456.11")); var testAsset = _testAssetsManager.CreateTestProject(testProject); @@ -445,7 +439,7 @@ public void NativeAot_hw_runs_with_cross_PackageReference_PublishAot_is_empty(st // https://github.com/dotnet/sdk/issues/27533 var publishDirectory = publishCommand.GetOutputDirectory(targetFramework: targetFramework, runtimeIdentifier: rid).FullName; var publishedDll = Path.Combine(publishDirectory, $"{projectName}.dll"); - // File.Exists(publishedDll).Should().BeTrue(); + File.Exists(publishedDll).Should().BeTrue(); } } From 94f015f345619aa1f4ca3a2ccfd6d5e1ffece16e Mon Sep 17 00:00:00 2001 From: Lakshan Fernando Date: Wed, 7 Sep 2022 15:03:46 -0700 Subject: [PATCH 2/3] Additional scenario with targetFX 6 --- .../GivenThatWeWantToPublishAnAotApp.cs | 24 +++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/src/Tests/Microsoft.NET.Publish.Tests/GivenThatWeWantToPublishAnAotApp.cs b/src/Tests/Microsoft.NET.Publish.Tests/GivenThatWeWantToPublishAnAotApp.cs index 631e0bc2b77a..0890a4871ff1 100644 --- a/src/Tests/Microsoft.NET.Publish.Tests/GivenThatWeWantToPublishAnAotApp.cs +++ b/src/Tests/Microsoft.NET.Publish.Tests/GivenThatWeWantToPublishAnAotApp.cs @@ -435,8 +435,6 @@ public void NativeAot_hw_runs_with_cross_PackageReference_PublishAot_is_empty(st .Should().Pass(); // Not setting PublishAot to true will be a normal publish - // Comment back after the below issue is fixed - // https://github.com/dotnet/sdk/issues/27533 var publishDirectory = publishCommand.GetOutputDirectory(targetFramework: targetFramework, runtimeIdentifier: rid).FullName; var publishedDll = Path.Combine(publishDirectory, $"{projectName}.dll"); File.Exists(publishedDll).Should().BeTrue(); @@ -444,6 +442,28 @@ public void NativeAot_hw_runs_with_cross_PackageReference_PublishAot_is_empty(st } } + [RequiresMSBuildVersionTheory("17.0.0.32901")] + [InlineData(ToolsetInfo.CurrentTargetFramework)] + public void NativeAot_hw_fails_with_sdk6_PublishAot_is_enabled(string targetFramework) + { + if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) + { + var projectName = "HellowWorldNativeAotApp"; + var rid = EnvironmentInfo.GetCompatibleRid(targetFramework); + + var testProject = CreateHelloWorldTestProject("net6.0", projectName, true); + testProject.AdditionalProperties["PublishAot"] = "true"; + + var testAsset = _testAssetsManager.CreateTestProject(testProject); + + var publishCommand = new PublishCommand(Log, Path.Combine(testAsset.TestRoot, testProject.Name)); + publishCommand + .Execute($"/p:RuntimeIdentifier={rid}") + .Should().Fail() + .And.HaveStdOutContaining("error NETSDK1183:"); + } + } + [RequiresMSBuildVersionTheory("17.0.0.32901")] [InlineData(ToolsetInfo.CurrentTargetFramework)] public void Only_Aot_warnings_are_produced_if_EnableAotAnalyzer_is_set(string targetFramework) From 6beb9533deaec7239815db7b35a2525e69bebe71 Mon Sep 17 00:00:00 2001 From: Lakshan Fernando Date: Thu, 8 Sep 2022 07:32:03 -0700 Subject: [PATCH 3/3] scenario with targetFX 6 and explicit package reference --- .../GivenThatWeWantToPublishAnAotApp.cs | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/src/Tests/Microsoft.NET.Publish.Tests/GivenThatWeWantToPublishAnAotApp.cs b/src/Tests/Microsoft.NET.Publish.Tests/GivenThatWeWantToPublishAnAotApp.cs index 0890a4871ff1..a9ded850e964 100644 --- a/src/Tests/Microsoft.NET.Publish.Tests/GivenThatWeWantToPublishAnAotApp.cs +++ b/src/Tests/Microsoft.NET.Publish.Tests/GivenThatWeWantToPublishAnAotApp.cs @@ -464,6 +464,30 @@ public void NativeAot_hw_fails_with_sdk6_PublishAot_is_enabled(string targetFram } } + [RequiresMSBuildVersionTheory("17.0.0.32901")] + [InlineData(ToolsetInfo.CurrentTargetFramework)] + public void NativeAot_hw_fails_with_sdk6_PackageReference_PublishAot_is_enabled(string targetFramework) + { + if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) + { + var projectName = "HellowWorldNativeAotApp"; + var rid = EnvironmentInfo.GetCompatibleRid(targetFramework); + + var testProject = CreateHelloWorldTestProject("net6.0", projectName, true); + testProject.AdditionalProperties["PublishAot"] = "true"; + + testProject.PackageReferences.Add(new TestPackageReference("Microsoft.DotNet.ILCompiler", "7.0.0-rc.2.22456.11")); + + var testAsset = _testAssetsManager.CreateTestProject(testProject); + + var publishCommand = new PublishCommand(Log, Path.Combine(testAsset.TestRoot, testProject.Name)); + publishCommand + .Execute($"/p:RuntimeIdentifier={rid}") + .Should().Fail() + .And.HaveStdOutContaining("error NETSDK1183:"); + } + } + [RequiresMSBuildVersionTheory("17.0.0.32901")] [InlineData(ToolsetInfo.CurrentTargetFramework)] public void Only_Aot_warnings_are_produced_if_EnableAotAnalyzer_is_set(string targetFramework)