From a76b37ac9b2206408aacbf33508479e408ce1cda Mon Sep 17 00:00:00 2001 From: Lakshan Fernando Date: Mon, 22 Aug 2022 07:23:39 -0700 Subject: [PATCH 1/6] Update AO test --- .../GivenThatWeWantToPublishAnAotApp.cs | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/Tests/Microsoft.NET.Publish.Tests/GivenThatWeWantToPublishAnAotApp.cs b/src/Tests/Microsoft.NET.Publish.Tests/GivenThatWeWantToPublishAnAotApp.cs index c674294f09e1..9fe7531c6f47 100644 --- a/src/Tests/Microsoft.NET.Publish.Tests/GivenThatWeWantToPublishAnAotApp.cs +++ b/src/Tests/Microsoft.NET.Publish.Tests/GivenThatWeWantToPublishAnAotApp.cs @@ -25,6 +25,10 @@ namespace Microsoft.NET.Publish.Tests { public class GivenThatWeWantToPublishAnAotApp : SdkTest { + /// + /// The test scenarios in a broad sense are covered below, + /// https://github.com/dotnet/runtime/issues/72415#issuecomment-1205540035 + /// private readonly string RuntimeIdentifier = $"/p:RuntimeIdentifier={RuntimeInformation.RuntimeIdentifier}"; public GivenThatWeWantToPublishAnAotApp(ITestOutputHelper log) : base(log) @@ -272,6 +276,8 @@ 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 + // The final ILCompiler packages that are used should be the onm defined in the explicit package reference but we + // don't have an easy way to validate the version testProject.PackageReferences.Add(new TestPackageReference("Microsoft.DotNet.ILCompiler", "7.0.0-rc.1.22416.1")); // Linux symbol files are embedded and require additional steps to be stripped to a separate file @@ -361,18 +367,17 @@ public void NativeAot_hw_runs_with_cross_PackageReference_PublishAot_is_enabled( if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows) && (RuntimeInformation.OSArchitecture == System.Runtime.InteropServices.Architecture.X64)) { var projectName = "HellowWorldNativeAotApp"; + // Setting a cross target RID will ensure that the SDK will download 2 runtime packages, host and target var rid = "win-arm64"; var testProject = CreateHelloWorldTestProject(targetFramework, projectName, true); 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")); - var testAsset = _testAssetsManager.CreateTestProject(testProject); var publishCommand = new PublishCommand(Log, Path.Combine(testAsset.TestRoot, testProject.Name)); + + // We dont have a way of executing the application in this scenario but publish should succeed publishCommand .Execute($"/p:RuntimeIdentifier={rid}") .Should().Pass(); From e329e1d212b9d8aaa4a622204d0c336bf05af96f Mon Sep 17 00:00:00 2001 From: Lakshan Fernando Date: Tue, 23 Aug 2022 08:52:47 -0700 Subject: [PATCH 2/6] Fix typo in AotNoValidRuntimePackageError --- src/Tasks/Common/Resources/Strings.resx | 2 +- src/Tasks/Common/Resources/xlf/Strings.cs.xlf | 2 +- src/Tasks/Common/Resources/xlf/Strings.de.xlf | 2 +- src/Tasks/Common/Resources/xlf/Strings.es.xlf | 2 +- src/Tasks/Common/Resources/xlf/Strings.fr.xlf | 2 +- src/Tasks/Common/Resources/xlf/Strings.it.xlf | 2 +- src/Tasks/Common/Resources/xlf/Strings.ja.xlf | 2 +- src/Tasks/Common/Resources/xlf/Strings.ko.xlf | 2 +- src/Tasks/Common/Resources/xlf/Strings.pl.xlf | 4 ++-- src/Tasks/Common/Resources/xlf/Strings.pt-BR.xlf | 2 +- src/Tasks/Common/Resources/xlf/Strings.ru.xlf | 2 +- src/Tasks/Common/Resources/xlf/Strings.tr.xlf | 2 +- src/Tasks/Common/Resources/xlf/Strings.zh-Hans.xlf | 2 +- src/Tasks/Common/Resources/xlf/Strings.zh-Hant.xlf | 2 +- 14 files changed, 15 insertions(+), 15 deletions(-) diff --git a/src/Tasks/Common/Resources/Strings.resx b/src/Tasks/Common/Resources/Strings.resx index e6caab7c7c7f..7afca8b8de79 100644 --- a/src/Tasks/Common/Resources/Strings.resx +++ b/src/Tasks/Common/Resources/Strings.resx @@ -837,7 +837,7 @@ You may need to build the project on another operating system or architecture, o NETSDK1183: Unable to optimize assemblies for Ahead of time compilation: a valid runtime package was not found. Either set the PublishAot property to false, or use a supported runtime identifier when publishing. When targeting .NET 7 or higher, make sure to restore packages with the PublishAot property set to true. - {StrBegin="NETSDK1094: "} + {StrBegin="NETSDK1183: "} NETSDK1184: The Targeting Pack for FrameworkReference '{0}' was not available. This may be because DisableTransitiveFrameworkReferenceDownloads was set to true. diff --git a/src/Tasks/Common/Resources/xlf/Strings.cs.xlf b/src/Tasks/Common/Resources/xlf/Strings.cs.xlf index 8d7e270b7097..ec30fa91e4e1 100644 --- a/src/Tasks/Common/Resources/xlf/Strings.cs.xlf +++ b/src/Tasks/Common/Resources/xlf/Strings.cs.xlf @@ -10,7 +10,7 @@ NETSDK1183: Unable to optimize assemblies for Ahead of time compilation: a valid runtime package was not found. Either set the PublishAot property to false, or use a supported runtime identifier when publishing. When targeting .NET 7 or higher, make sure to restore packages with the PublishAot property set to true. NETSDK1183: Unable to optimize assemblies for Ahead of time compilation: a valid runtime package was not found. Either set the PublishAot property to false, or use a supported runtime identifier when publishing. When targeting .NET 7 or higher, make sure to restore packages with the PublishAot property set to true. - {StrBegin="NETSDK1094: "} + {StrBegin="NETSDK1183: "} NETSDK1070: The application configuration file must have root configuration element. diff --git a/src/Tasks/Common/Resources/xlf/Strings.de.xlf b/src/Tasks/Common/Resources/xlf/Strings.de.xlf index d9eb3a393f3f..0f73f89d83e6 100644 --- a/src/Tasks/Common/Resources/xlf/Strings.de.xlf +++ b/src/Tasks/Common/Resources/xlf/Strings.de.xlf @@ -10,7 +10,7 @@ NETSDK1183: Unable to optimize assemblies for Ahead of time compilation: a valid runtime package was not found. Either set the PublishAot property to false, or use a supported runtime identifier when publishing. When targeting .NET 7 or higher, make sure to restore packages with the PublishAot property set to true. NETSDK1183: Unable to optimize assemblies for Ahead of time compilation: a valid runtime package was not found. Either set the PublishAot property to false, or use a supported runtime identifier when publishing. When targeting .NET 7 or higher, make sure to restore packages with the PublishAot property set to true. - {StrBegin="NETSDK1094: "} + {StrBegin="NETSDK1183: "} NETSDK1070: The application configuration file must have root configuration element. diff --git a/src/Tasks/Common/Resources/xlf/Strings.es.xlf b/src/Tasks/Common/Resources/xlf/Strings.es.xlf index 2aa33940bd30..687c42d71702 100644 --- a/src/Tasks/Common/Resources/xlf/Strings.es.xlf +++ b/src/Tasks/Common/Resources/xlf/Strings.es.xlf @@ -10,7 +10,7 @@ NETSDK1183: Unable to optimize assemblies for Ahead of time compilation: a valid runtime package was not found. Either set the PublishAot property to false, or use a supported runtime identifier when publishing. When targeting .NET 7 or higher, make sure to restore packages with the PublishAot property set to true. NETSDK1183: Unable to optimize assemblies for Ahead of time compilation: a valid runtime package was not found. Either set the PublishAot property to false, or use a supported runtime identifier when publishing. When targeting .NET 7 or higher, make sure to restore packages with the PublishAot property set to true. - {StrBegin="NETSDK1094: "} + {StrBegin="NETSDK1183: "} NETSDK1070: The application configuration file must have root configuration element. diff --git a/src/Tasks/Common/Resources/xlf/Strings.fr.xlf b/src/Tasks/Common/Resources/xlf/Strings.fr.xlf index 25cc4ea000a2..95409a5d12a4 100644 --- a/src/Tasks/Common/Resources/xlf/Strings.fr.xlf +++ b/src/Tasks/Common/Resources/xlf/Strings.fr.xlf @@ -10,7 +10,7 @@ NETSDK1183: Unable to optimize assemblies for Ahead of time compilation: a valid runtime package was not found. Either set the PublishAot property to false, or use a supported runtime identifier when publishing. When targeting .NET 7 or higher, make sure to restore packages with the PublishAot property set to true. NETSDK1183: Unable to optimize assemblies for Ahead of time compilation: a valid runtime package was not found. Either set the PublishAot property to false, or use a supported runtime identifier when publishing. When targeting .NET 7 or higher, make sure to restore packages with the PublishAot property set to true. - {StrBegin="NETSDK1094: "} + {StrBegin="NETSDK1183: "} NETSDK1070: The application configuration file must have root configuration element. diff --git a/src/Tasks/Common/Resources/xlf/Strings.it.xlf b/src/Tasks/Common/Resources/xlf/Strings.it.xlf index 11542802ea25..bdef216fa253 100644 --- a/src/Tasks/Common/Resources/xlf/Strings.it.xlf +++ b/src/Tasks/Common/Resources/xlf/Strings.it.xlf @@ -10,7 +10,7 @@ NETSDK1183: Unable to optimize assemblies for Ahead of time compilation: a valid runtime package was not found. Either set the PublishAot property to false, or use a supported runtime identifier when publishing. When targeting .NET 7 or higher, make sure to restore packages with the PublishAot property set to true. NETSDK1183: Unable to optimize assemblies for Ahead of time compilation: a valid runtime package was not found. Either set the PublishAot property to false, or use a supported runtime identifier when publishing. When targeting .NET 7 or higher, make sure to restore packages with the PublishAot property set to true. - {StrBegin="NETSDK1094: "} + {StrBegin="NETSDK1183: "} NETSDK1070: The application configuration file must have root configuration element. diff --git a/src/Tasks/Common/Resources/xlf/Strings.ja.xlf b/src/Tasks/Common/Resources/xlf/Strings.ja.xlf index 1606ae08aff0..16ed1f789583 100644 --- a/src/Tasks/Common/Resources/xlf/Strings.ja.xlf +++ b/src/Tasks/Common/Resources/xlf/Strings.ja.xlf @@ -10,7 +10,7 @@ NETSDK1183: Unable to optimize assemblies for Ahead of time compilation: a valid runtime package was not found. Either set the PublishAot property to false, or use a supported runtime identifier when publishing. When targeting .NET 7 or higher, make sure to restore packages with the PublishAot property set to true. NETSDK1183: Unable to optimize assemblies for Ahead of time compilation: a valid runtime package was not found. Either set the PublishAot property to false, or use a supported runtime identifier when publishing. When targeting .NET 7 or higher, make sure to restore packages with the PublishAot property set to true. - {StrBegin="NETSDK1094: "} + {StrBegin="NETSDK1183: "} NETSDK1070: The application configuration file must have root configuration element. diff --git a/src/Tasks/Common/Resources/xlf/Strings.ko.xlf b/src/Tasks/Common/Resources/xlf/Strings.ko.xlf index e0dd18eba9a9..92460cb2a4d1 100644 --- a/src/Tasks/Common/Resources/xlf/Strings.ko.xlf +++ b/src/Tasks/Common/Resources/xlf/Strings.ko.xlf @@ -10,7 +10,7 @@ NETSDK1183: Unable to optimize assemblies for Ahead of time compilation: a valid runtime package was not found. Either set the PublishAot property to false, or use a supported runtime identifier when publishing. When targeting .NET 7 or higher, make sure to restore packages with the PublishAot property set to true. NETSDK1183: Unable to optimize assemblies for Ahead of time compilation: a valid runtime package was not found. Either set the PublishAot property to false, or use a supported runtime identifier when publishing. When targeting .NET 7 or higher, make sure to restore packages with the PublishAot property set to true. - {StrBegin="NETSDK1094: "} + {StrBegin="NETSDK1183: "} NETSDK1070: The application configuration file must have root configuration element. diff --git a/src/Tasks/Common/Resources/xlf/Strings.pl.xlf b/src/Tasks/Common/Resources/xlf/Strings.pl.xlf index a6f4b97ede58..e1027e9272d5 100644 --- a/src/Tasks/Common/Resources/xlf/Strings.pl.xlf +++ b/src/Tasks/Common/Resources/xlf/Strings.pl.xlf @@ -9,8 +9,8 @@ NETSDK1183: Unable to optimize assemblies for Ahead of time compilation: a valid runtime package was not found. Either set the PublishAot property to false, or use a supported runtime identifier when publishing. When targeting .NET 7 or higher, make sure to restore packages with the PublishAot property set to true. - NETSDK1094: Nie można zoptymalizować zestawów pod kątem kompilacji z wyprzedzeniem: nie znaleziono prawidłowego pakietu środowiska uruchomieniowego. Ustaw właściwość PublishAot na wartość false lub użyj obsługiwanego identyfikatora środowiska uruchomieniowego podczas publikowania. W przypadku określania wartości docelowej platformy .NET 7 lub nowszej należy przywrócić pakiety z właściwością PublishAot ustawioną na wartość true. - {StrBegin="NETSDK1094: "} + NETSDK1094: Nie można zoptymalizować zestawów pod kątem kompilacji z wyprzedzeniem: nie znaleziono prawidłowego pakietu środowiska uruchomieniowego. Ustaw właściwość PublishAot na wartość false lub użyj obsługiwanego identyfikatora środowiska uruchomieniowego podczas publikowania. W przypadku określania wartości docelowej platformy .NET 7 lub nowszej należy przywrócić pakiety z właściwością PublishAot ustawioną na wartość true. + {StrBegin="NETSDK1183: "} NETSDK1070: The application configuration file must have root configuration element. diff --git a/src/Tasks/Common/Resources/xlf/Strings.pt-BR.xlf b/src/Tasks/Common/Resources/xlf/Strings.pt-BR.xlf index 5678d3d16519..81f104a398f8 100644 --- a/src/Tasks/Common/Resources/xlf/Strings.pt-BR.xlf +++ b/src/Tasks/Common/Resources/xlf/Strings.pt-BR.xlf @@ -10,7 +10,7 @@ NETSDK1183: Unable to optimize assemblies for Ahead of time compilation: a valid runtime package was not found. Either set the PublishAot property to false, or use a supported runtime identifier when publishing. When targeting .NET 7 or higher, make sure to restore packages with the PublishAot property set to true. NETSDK1183: Unable to optimize assemblies for Ahead of time compilation: a valid runtime package was not found. Either set the PublishAot property to false, or use a supported runtime identifier when publishing. When targeting .NET 7 or higher, make sure to restore packages with the PublishAot property set to true. - {StrBegin="NETSDK1094: "} + {StrBegin="NETSDK1183: "} NETSDK1070: The application configuration file must have root configuration element. diff --git a/src/Tasks/Common/Resources/xlf/Strings.ru.xlf b/src/Tasks/Common/Resources/xlf/Strings.ru.xlf index 10c14ba29892..b459d4ce4ac4 100644 --- a/src/Tasks/Common/Resources/xlf/Strings.ru.xlf +++ b/src/Tasks/Common/Resources/xlf/Strings.ru.xlf @@ -10,7 +10,7 @@ NETSDK1183: Unable to optimize assemblies for Ahead of time compilation: a valid runtime package was not found. Either set the PublishAot property to false, or use a supported runtime identifier when publishing. When targeting .NET 7 or higher, make sure to restore packages with the PublishAot property set to true. NETSDK1183: Unable to optimize assemblies for Ahead of time compilation: a valid runtime package was not found. Either set the PublishAot property to false, or use a supported runtime identifier when publishing. When targeting .NET 7 or higher, make sure to restore packages with the PublishAot property set to true. - {StrBegin="NETSDK1094: "} + {StrBegin="NETSDK1183: "} NETSDK1070: The application configuration file must have root configuration element. diff --git a/src/Tasks/Common/Resources/xlf/Strings.tr.xlf b/src/Tasks/Common/Resources/xlf/Strings.tr.xlf index ab7e8b9f1b8d..cbf95636c58a 100644 --- a/src/Tasks/Common/Resources/xlf/Strings.tr.xlf +++ b/src/Tasks/Common/Resources/xlf/Strings.tr.xlf @@ -10,7 +10,7 @@ NETSDK1183: Unable to optimize assemblies for Ahead of time compilation: a valid runtime package was not found. Either set the PublishAot property to false, or use a supported runtime identifier when publishing. When targeting .NET 7 or higher, make sure to restore packages with the PublishAot property set to true. NETSDK1183: Unable to optimize assemblies for Ahead of time compilation: a valid runtime package was not found. Either set the PublishAot property to false, or use a supported runtime identifier when publishing. When targeting .NET 7 or higher, make sure to restore packages with the PublishAot property set to true. - {StrBegin="NETSDK1094: "} + {StrBegin="NETSDK1183: "} NETSDK1070: The application configuration file must have root configuration element. diff --git a/src/Tasks/Common/Resources/xlf/Strings.zh-Hans.xlf b/src/Tasks/Common/Resources/xlf/Strings.zh-Hans.xlf index b5c55712c2a4..3759a269c009 100644 --- a/src/Tasks/Common/Resources/xlf/Strings.zh-Hans.xlf +++ b/src/Tasks/Common/Resources/xlf/Strings.zh-Hans.xlf @@ -10,7 +10,7 @@ NETSDK1183: Unable to optimize assemblies for Ahead of time compilation: a valid runtime package was not found. Either set the PublishAot property to false, or use a supported runtime identifier when publishing. When targeting .NET 7 or higher, make sure to restore packages with the PublishAot property set to true. NETSDK1183: Unable to optimize assemblies for Ahead of time compilation: a valid runtime package was not found. Either set the PublishAot property to false, or use a supported runtime identifier when publishing. When targeting .NET 7 or higher, make sure to restore packages with the PublishAot property set to true. - {StrBegin="NETSDK1094: "} + {StrBegin="NETSDK1183: "} NETSDK1070: The application configuration file must have root configuration element. diff --git a/src/Tasks/Common/Resources/xlf/Strings.zh-Hant.xlf b/src/Tasks/Common/Resources/xlf/Strings.zh-Hant.xlf index a1b0bfcc0951..790b6b293eb0 100644 --- a/src/Tasks/Common/Resources/xlf/Strings.zh-Hant.xlf +++ b/src/Tasks/Common/Resources/xlf/Strings.zh-Hant.xlf @@ -10,7 +10,7 @@ NETSDK1183: Unable to optimize assemblies for Ahead of time compilation: a valid runtime package was not found. Either set the PublishAot property to false, or use a supported runtime identifier when publishing. When targeting .NET 7 or higher, make sure to restore packages with the PublishAot property set to true. NETSDK1183: Unable to optimize assemblies for Ahead of time compilation: a valid runtime package was not found. Either set the PublishAot property to false, or use a supported runtime identifier when publishing. When targeting .NET 7 or higher, make sure to restore packages with the PublishAot property set to true. - {StrBegin="NETSDK1094: "} + {StrBegin="NETSDK1183: "} NETSDK1070: The application configuration file must have root configuration element. From 3538a4cc3e85901aae67f5d4144c39a4158a0e9f Mon Sep 17 00:00:00 2001 From: Lakshan Fernando Date: Tue, 23 Aug 2022 10:04:09 -0700 Subject: [PATCH 3/6] Apply suggestions from code review Co-authored-by: Sven Boemer --- .../GivenThatWeWantToPublishAnAotApp.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Tests/Microsoft.NET.Publish.Tests/GivenThatWeWantToPublishAnAotApp.cs b/src/Tests/Microsoft.NET.Publish.Tests/GivenThatWeWantToPublishAnAotApp.cs index 9fe7531c6f47..eb4f49e8d27d 100644 --- a/src/Tests/Microsoft.NET.Publish.Tests/GivenThatWeWantToPublishAnAotApp.cs +++ b/src/Tests/Microsoft.NET.Publish.Tests/GivenThatWeWantToPublishAnAotApp.cs @@ -276,7 +276,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 - // The final ILCompiler packages that are used should be the onm defined in the explicit package reference but we + // The final ILCompiler packages that are used should be the ones defined in the explicit package reference but we // don't have an easy way to validate the version testProject.PackageReferences.Add(new TestPackageReference("Microsoft.DotNet.ILCompiler", "7.0.0-rc.1.22416.1")); @@ -377,7 +377,7 @@ public void NativeAot_hw_runs_with_cross_PackageReference_PublishAot_is_enabled( var publishCommand = new PublishCommand(Log, Path.Combine(testAsset.TestRoot, testProject.Name)); - // We dont have a way of executing the application in this scenario but publish should succeed + // We don't have a way of executing the application in this scenario but publish should succeed publishCommand .Execute($"/p:RuntimeIdentifier={rid}") .Should().Pass(); From 79c16a25d615b97080df5c8f2c219873ff81a21b Mon Sep 17 00:00:00 2001 From: Lakshan Fernando Date: Thu, 25 Aug 2022 08:38:42 -0700 Subject: [PATCH 4/6] FB --- .../GivenThatWeWantToPublishAnAotApp.cs | 29 +++++++++++++++++-- 1 file changed, 26 insertions(+), 3 deletions(-) diff --git a/src/Tests/Microsoft.NET.Publish.Tests/GivenThatWeWantToPublishAnAotApp.cs b/src/Tests/Microsoft.NET.Publish.Tests/GivenThatWeWantToPublishAnAotApp.cs index eb4f49e8d27d..9c7ee55cbc28 100644 --- a/src/Tests/Microsoft.NET.Publish.Tests/GivenThatWeWantToPublishAnAotApp.cs +++ b/src/Tests/Microsoft.NET.Publish.Tests/GivenThatWeWantToPublishAnAotApp.cs @@ -27,7 +27,7 @@ public class GivenThatWeWantToPublishAnAotApp : SdkTest { /// /// The test scenarios in a broad sense are covered below, - /// https://github.com/dotnet/runtime/issues/72415#issuecomment-1205540035 + /// https://github.com/dotnet/runtime/blob/main/src/coreclr/nativeaot/docs/compiling.md /// private readonly string RuntimeIdentifier = $"/p:RuntimeIdentifier={RuntimeInformation.RuntimeIdentifier}"; @@ -362,7 +362,7 @@ public void NativeAot_hw_runs_with_PackageReference_PublishAot_is_empty(string t [RequiresMSBuildVersionTheory("17.0.0.32901")] [InlineData(ToolsetInfo.CurrentTargetFramework)] - public void NativeAot_hw_runs_with_cross_PackageReference_PublishAot_is_enabled(string targetFramework) + public void NativeAot_hw_runs_with_cross_target_PublishAot_is_enabled(string targetFramework) { if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows) && (RuntimeInformation.OSArchitecture == System.Runtime.InteropServices.Architecture.X64)) { @@ -397,7 +397,30 @@ public void NativeAot_hw_runs_with_cross_PackageReference_PublishAot_is_empty(st // 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")); + + var testAsset = _testAssetsManager.CreateTestProject(testProject); + + var publishCommand = new PublishCommand(Log, Path.Combine(testAsset.TestRoot, testProject.Name)); + publishCommand + .Execute($"/p:RuntimeIdentifier={rid}") + .Should().Pass(); + } + } + + [RequiresMSBuildVersionTheory("17.0.0.32901")] + [InlineData(ToolsetInfo.CurrentTargetFramework)] + public void NativeAot_hw_runs_with_cross_PackageReference_PublishAot_is_enabled(string targetFramework) + { + if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows) && (RuntimeInformation.OSArchitecture == System.Runtime.InteropServices.Architecture.X64)) + { + var projectName = "HellowWorldNativeAotApp"; + var rid = "win-arm64"; + + var testProject = CreateHelloWorldTestProject(targetFramework, projectName, true); + 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")); var testAsset = _testAssetsManager.CreateTestProject(testProject); From 93dba572058764bb5009e23938623f52dd92b417 Mon Sep 17 00:00:00 2001 From: Lakshan Fernando Date: Mon, 29 Aug 2022 11:59:50 -0700 Subject: [PATCH 5/6] fix test --- .../GivenThatWeWantToPublishAnAotApp.cs | 57 +++++++++++-------- 1 file changed, 34 insertions(+), 23 deletions(-) diff --git a/src/Tests/Microsoft.NET.Publish.Tests/GivenThatWeWantToPublishAnAotApp.cs b/src/Tests/Microsoft.NET.Publish.Tests/GivenThatWeWantToPublishAnAotApp.cs index 9c7ee55cbc28..bd262e34a626 100644 --- a/src/Tests/Microsoft.NET.Publish.Tests/GivenThatWeWantToPublishAnAotApp.cs +++ b/src/Tests/Microsoft.NET.Publish.Tests/GivenThatWeWantToPublishAnAotApp.cs @@ -25,10 +25,6 @@ namespace Microsoft.NET.Publish.Tests { public class GivenThatWeWantToPublishAnAotApp : SdkTest { - /// - /// The test scenarios in a broad sense are covered below, - /// https://github.com/dotnet/runtime/blob/main/src/coreclr/nativeaot/docs/compiling.md - /// private readonly string RuntimeIdentifier = $"/p:RuntimeIdentifier={RuntimeInformation.RuntimeIdentifier}"; public GivenThatWeWantToPublishAnAotApp(ITestOutputHelper log) : base(log) @@ -276,8 +272,6 @@ 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 - // The final ILCompiler packages that are used should be the ones defined in the explicit package reference but we - // don't have an easy way to validate the version testProject.PackageReferences.Add(new TestPackageReference("Microsoft.DotNet.ILCompiler", "7.0.0-rc.1.22416.1")); // Linux symbol files are embedded and require additional steps to be stripped to a separate file @@ -292,6 +286,11 @@ public void NativeAot_hw_runs_with_PackageReference_PublishAot_is_enabled(string publishCommand .Execute($"/p:RuntimeIdentifier={rid}") .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"); var publishDirectory = publishCommand.GetOutputDirectory(targetFramework: targetFramework, runtimeIdentifier: rid).FullName; var sharedLibSuffix = RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ? ".dll" : ".so"; @@ -341,25 +340,20 @@ public void NativeAot_hw_runs_with_PackageReference_PublishAot_is_empty(string t .Should().Pass(); var publishDirectory = publishCommand.GetOutputDirectory(targetFramework: targetFramework, runtimeIdentifier: rid).FullName; - var sharedLibSuffix = RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ? ".dll" : ".so"; - var publishedDll = Path.Combine(publishDirectory, $"{projectName}{sharedLibSuffix}"); + var publishedDll = Path.Combine(publishDirectory, $"{projectName}.dll"); var publishedExe = Path.Combine(publishDirectory, $"{testProject.Name}{Constants.ExeSuffix}"); - var symbolSuffix = RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ? ".pdb" : ".dbg"; - var publishedDebugFile = Path.Combine(publishDirectory, $"{testProject.Name}{symbolSuffix}"); - // NativeAOT published dir should not contain a non-host stand alone package - File.Exists(publishedDll).Should().BeFalse(); - // The exe exist and should be native - File.Exists(publishedExe).Should().BeTrue(); - File.Exists(publishedDebugFile).Should().BeTrue(); - IsNativeImage(publishedExe).Should().BeTrue(); + // 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(); var command = new RunExeCommand(Log, publishedExe) .Execute().Should().Pass() .And.HaveStdOutContaining("Hello World"); } } - + [RequiresMSBuildVersionTheory("17.0.0.32901")] [InlineData(ToolsetInfo.CurrentTargetFramework)] public void NativeAot_hw_runs_with_cross_target_PublishAot_is_enabled(string targetFramework) @@ -367,7 +361,6 @@ public void NativeAot_hw_runs_with_cross_target_PublishAot_is_enabled(string tar if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows) && (RuntimeInformation.OSArchitecture == System.Runtime.InteropServices.Architecture.X64)) { var projectName = "HellowWorldNativeAotApp"; - // Setting a cross target RID will ensure that the SDK will download 2 runtime packages, host and target var rid = "win-arm64"; var testProject = CreateHelloWorldTestProject(targetFramework, projectName, true); @@ -376,17 +369,16 @@ public void NativeAot_hw_runs_with_cross_target_PublishAot_is_enabled(string tar var testAsset = _testAssetsManager.CreateTestProject(testProject); var publishCommand = new PublishCommand(Log, Path.Combine(testAsset.TestRoot, testProject.Name)); - - // We don't have a way of executing the application in this scenario but publish should succeed publishCommand .Execute($"/p:RuntimeIdentifier={rid}") .Should().Pass(); } } + [RequiresMSBuildVersionTheory("17.0.0.32901")] [InlineData(ToolsetInfo.CurrentTargetFramework)] - public void NativeAot_hw_runs_with_cross_PackageReference_PublishAot_is_empty(string targetFramework) + public void NativeAot_hw_runs_with_cross_PackageReference_PublishAot_is_enabled(string targetFramework) { if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows) && (RuntimeInformation.OSArchitecture == System.Runtime.InteropServices.Architecture.X64)) { @@ -394,9 +386,11 @@ public void NativeAot_hw_runs_with_cross_PackageReference_PublishAot_is_empty(st var rid = "win-arm64"; var testProject = CreateHelloWorldTestProject(targetFramework, projectName, true); + 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")); var testAsset = _testAssetsManager.CreateTestProject(testProject); @@ -404,12 +398,21 @@ public void NativeAot_hw_runs_with_cross_PackageReference_PublishAot_is_empty(st publishCommand .Execute($"/p:RuntimeIdentifier={rid}") .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"); + + var publishDirectory = publishCommand.GetOutputDirectory(targetFramework: targetFramework, runtimeIdentifier: rid).FullName; + var publishedDll = Path.Combine(publishDirectory, $"{projectName}.dll"); + File.Exists(publishedDll).Should().BeFalse(); } } [RequiresMSBuildVersionTheory("17.0.0.32901")] [InlineData(ToolsetInfo.CurrentTargetFramework)] - public void NativeAot_hw_runs_with_cross_PackageReference_PublishAot_is_enabled(string targetFramework) + public void NativeAot_hw_runs_with_cross_PackageReference_PublishAot_is_empty(string targetFramework) { if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows) && (RuntimeInformation.OSArchitecture == System.Runtime.InteropServices.Architecture.X64)) { @@ -417,10 +420,10 @@ public void NativeAot_hw_runs_with_cross_PackageReference_PublishAot_is_enabled( var rid = "win-arm64"; var testProject = CreateHelloWorldTestProject(targetFramework, projectName, true); - 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")); var testAsset = _testAssetsManager.CreateTestProject(testProject); @@ -428,6 +431,14 @@ public void NativeAot_hw_runs_with_cross_PackageReference_PublishAot_is_enabled( publishCommand .Execute($"/p:RuntimeIdentifier={rid}") .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(); + } } From 6e1cc04543f1cee0830a1fde254d167fb60ad6b7 Mon Sep 17 00:00:00 2001 From: Lakshan Fernando Date: Tue, 30 Aug 2022 09:58:23 -0700 Subject: [PATCH 6/6] FB --- .../GivenThatWeWantToPublishAnAotApp.cs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/Tests/Microsoft.NET.Publish.Tests/GivenThatWeWantToPublishAnAotApp.cs b/src/Tests/Microsoft.NET.Publish.Tests/GivenThatWeWantToPublishAnAotApp.cs index bd262e34a626..f4a88b1db5f8 100644 --- a/src/Tests/Microsoft.NET.Publish.Tests/GivenThatWeWantToPublishAnAotApp.cs +++ b/src/Tests/Microsoft.NET.Publish.Tests/GivenThatWeWantToPublishAnAotApp.cs @@ -372,6 +372,12 @@ public void NativeAot_hw_runs_with_cross_target_PublishAot_is_enabled(string tar publishCommand .Execute($"/p:RuntimeIdentifier={rid}") .Should().Pass(); + var publishDirectory = publishCommand.GetOutputDirectory(targetFramework: targetFramework, runtimeIdentifier: rid).FullName; + var publishedDll = Path.Combine(publishDirectory, $"{projectName}.dll"); + var publishedExe = Path.Combine(publishDirectory, $"{testProject.Name}{Constants.ExeSuffix}"); + File.Exists(publishedDll).Should().BeFalse(); + File.Exists(publishedExe).Should().BeTrue(); + } } @@ -406,7 +412,9 @@ public void NativeAot_hw_runs_with_cross_PackageReference_PublishAot_is_enabled( var publishDirectory = publishCommand.GetOutputDirectory(targetFramework: targetFramework, runtimeIdentifier: rid).FullName; var publishedDll = Path.Combine(publishDirectory, $"{projectName}.dll"); + var publishedExe = Path.Combine(publishDirectory, $"{testProject.Name}{Constants.ExeSuffix}"); File.Exists(publishedDll).Should().BeFalse(); + File.Exists(publishedExe).Should().BeTrue(); } }