From 610e245bd94efd1d7eeb96a518ce78faf588dd52 Mon Sep 17 00:00:00 2001 From: Sven Boemer Date: Thu, 20 Oct 2022 21:21:51 +0000 Subject: [PATCH 1/7] Use implicit package reference for ILC build package --- .../ProcessFrameworkReferences.cs | 8 +++++++- ...osoft.NET.Sdk.FrameworkReferenceResolution.targets | 11 ++++++++++- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/src/Tasks/Microsoft.NET.Build.Tasks/ProcessFrameworkReferences.cs b/src/Tasks/Microsoft.NET.Build.Tasks/ProcessFrameworkReferences.cs index 9447c16cbd02..9a093e2862f4 100644 --- a/src/Tasks/Microsoft.NET.Build.Tasks/ProcessFrameworkReferences.cs +++ b/src/Tasks/Microsoft.NET.Build.Tasks/ProcessFrameworkReferences.cs @@ -104,6 +104,9 @@ public class ProcessFrameworkReferences : TaskBase [Output] public ITaskItem[] TargetILCompilerPacks { get; set; } + [Output] + public ITaskItem[] ImplicitPackageReferences { get; set; } + // Runtime packs which aren't available for the specified RuntimeIdentifier [Output] public ITaskItem[] UnavailableRuntimePacks { get; set; } @@ -621,6 +624,9 @@ private bool AddAotOrR2RRuntimePackage(AotPackageType packageType, Version norma else { HostILCompilerPacks = new[] { newItem }; + var ilCompilerBuildPackageReference = new TaskItem(knownPack.ItemSpec); + ilCompilerBuildPackageReference.SetMetadata(MetadataKeys.Version, packVersion); + ImplicitPackageReferences = new[] { ilCompilerBuildPackageReference }; // ILCompiler supports cross target compilation. If there is a cross-target request, we need to download that package as well // We expect RuntimeIdentifier to be defined during publish but can allow during build if (RuntimeIdentifier != null) @@ -643,7 +649,7 @@ private bool AddAotOrR2RRuntimePackage(AotPackageType packageType, Version norma TargetILCompilerPacks = new[] { newItem2 }; } } - } + } return true; } diff --git a/src/Tasks/Microsoft.NET.Build.Tasks/targets/Microsoft.NET.Sdk.FrameworkReferenceResolution.targets b/src/Tasks/Microsoft.NET.Build.Tasks/targets/Microsoft.NET.Sdk.FrameworkReferenceResolution.targets index df564baca1a4..c66580e5e4e5 100644 --- a/src/Tasks/Microsoft.NET.Build.Tasks/targets/Microsoft.NET.Sdk.FrameworkReferenceResolution.targets +++ b/src/Tasks/Microsoft.NET.Build.Tasks/targets/Microsoft.NET.Sdk.FrameworkReferenceResolution.targets @@ -1,4 +1,4 @@ - + + <_ImplicitPackageReference Remove="@(PackageReference)" /> + + - - true - - From 5e33536cb5fdcabf157c0b5e7009f0b598805431 Mon Sep 17 00:00:00 2001 From: Sven Boemer Date: Fri, 21 Oct 2022 20:09:10 +0000 Subject: [PATCH 4/7] Remove SDK import --- .../Microsoft.NET.Build.Tasks/targets/Microsoft.NET.Sdk.props | 1 - 1 file changed, 1 deletion(-) diff --git a/src/Tasks/Microsoft.NET.Build.Tasks/targets/Microsoft.NET.Sdk.props b/src/Tasks/Microsoft.NET.Build.Tasks/targets/Microsoft.NET.Sdk.props index 73a182102d13..01db21f775ca 100644 --- a/src/Tasks/Microsoft.NET.Build.Tasks/targets/Microsoft.NET.Sdk.props +++ b/src/Tasks/Microsoft.NET.Build.Tasks/targets/Microsoft.NET.Sdk.props @@ -151,7 +151,6 @@ Copyright (c) .NET Foundation. All rights reserved. - From b798afc52bd43dad9f4c995ae437fc8bdfc43f3c Mon Sep 17 00:00:00 2001 From: Sven Boemer Date: Mon, 24 Oct 2022 23:29:05 +0000 Subject: [PATCH 5/7] Remove versions props --- eng/Version.Details.xml | 5 ----- eng/Versions.props | 1 - 2 files changed, 6 deletions(-) diff --git a/eng/Version.Details.xml b/eng/Version.Details.xml index ee45e28bdccd..c89e8f9467db 100644 --- a/eng/Version.Details.xml +++ b/eng/Version.Details.xml @@ -114,11 +114,6 @@ add4655706f2d15de40da6a97c9c22d74e34b0e2 - - https://github.com/dotnet/runtime - 6eb3ccb9507b74798c4bd3241587c4cf3b18866e - - https://github.com/dotnet/linker add4655706f2d15de40da6a97c9c22d74e34b0e2 diff --git a/eng/Versions.props b/eng/Versions.props index 0f12e2f92e0b..e8e72e1703ea 100644 --- a/eng/Versions.props +++ b/eng/Versions.props @@ -93,7 +93,6 @@ 8.0.0-alpha.1.22519.7 8.0.0-alpha.1.22519.7 8.0.0-alpha.1.22519.7 - 8.0.0-alpha.1.22519.7 From a52476228c370ceaee0bb581450cb3ba8cf8a340 Mon Sep 17 00:00:00 2001 From: Sven Boemer Date: Tue, 25 Oct 2022 17:52:53 +0000 Subject: [PATCH 6/7] Check explicit package reference version --- .../GivenThatWeWantToPublishAnAotApp.cs | 48 +++++++++++++++---- 1 file changed, 39 insertions(+), 9 deletions(-) diff --git a/src/Tests/Microsoft.NET.Publish.Tests/GivenThatWeWantToPublishAnAotApp.cs b/src/Tests/Microsoft.NET.Publish.Tests/GivenThatWeWantToPublishAnAotApp.cs index 78d198b4e1f2..05bad021b631 100644 --- a/src/Tests/Microsoft.NET.Publish.Tests/GivenThatWeWantToPublishAnAotApp.cs +++ b/src/Tests/Microsoft.NET.Publish.Tests/GivenThatWeWantToPublishAnAotApp.cs @@ -27,6 +27,8 @@ public class GivenThatWeWantToPublishAnAotApp : SdkTest { private readonly string RuntimeIdentifier = $"/p:RuntimeIdentifier={RuntimeInformation.RuntimeIdentifier}"; + private readonly string ExplicitPackageVersion = "7.0.0-rc.2.22456.11"; + public GivenThatWeWantToPublishAnAotApp(ITestOutputHelper log) : base(log) { } @@ -272,7 +274,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.2.22456.11")); + testProject.PackageReferences.Add(new TestPackageReference("Microsoft.DotNet.ILCompiler", ExplicitPackageVersion)); // 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 @@ -282,7 +284,7 @@ public void NativeAot_hw_runs_with_PackageReference_PublishAot_is_enabled(string } var testAsset = _testAssetsManager.CreateTestProject(testProject); - var publishCommand = new PublishCommand(Log, Path.Combine(testAsset.TestRoot, testProject.Name)); + var publishCommand= new PublishCommand(Log, Path.Combine(testAsset.TestRoot, testProject.Name)); publishCommand .Execute($"/p:RuntimeIdentifier={rid}") .Should().Pass() @@ -307,6 +309,8 @@ public void NativeAot_hw_runs_with_PackageReference_PublishAot_is_enabled(string var command = new RunExeCommand(Log, publishedExe) .Execute().Should().Pass() .And.HaveStdOutContaining("Hello World"); + + CheckIlcVersions(Path.Combine(testAsset.TestRoot, testProject.Name), targetFramework, ExplicitPackageVersion); } } @@ -322,7 +326,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.2.22456.11")); + testProject.PackageReferences.Add(new TestPackageReference("Microsoft.DotNet.ILCompiler", ExplicitPackageVersion)); // 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 @@ -373,7 +377,6 @@ public void NativeAot_hw_runs_with_cross_target_PublishAot_is_enabled(string tar var publishedExe = Path.Combine(publishDirectory, $"{testProject.Name}{Constants.ExeSuffix}"); File.Exists(publishedDll).Should().BeFalse(); File.Exists(publishedExe).Should().BeTrue(); - } } @@ -391,8 +394,8 @@ 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.2.22456.11")); - testProject.PackageReferences.Add(new TestPackageReference("runtime.win-x64.Microsoft.DotNet.ILCompiler", "7.0.0-rc.2.22456.11")); + testProject.PackageReferences.Add(new TestPackageReference("Microsoft.DotNet.ILCompiler", ExplicitPackageVersion)); + testProject.PackageReferences.Add(new TestPackageReference("runtime.win-x64.Microsoft.DotNet.ILCompiler", ExplicitPackageVersion)); var testAsset = _testAssetsManager.CreateTestProject(testProject); @@ -409,6 +412,8 @@ public void NativeAot_hw_runs_with_cross_PackageReference_PublishAot_is_enabled( var publishedExe = Path.Combine(publishDirectory, $"{testProject.Name}{Constants.ExeSuffix}"); File.Exists(publishedDll).Should().BeFalse(); File.Exists(publishedExe).Should().BeTrue(); + + CheckIlcVersions(Path.Combine(testAsset.TestRoot, testProject.Name), targetFramework, ExplicitPackageVersion); } } @@ -424,8 +429,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.2.22456.11")); - testProject.PackageReferences.Add(new TestPackageReference("runtime.win-x64.Microsoft.DotNet.ILCompiler", "7.0.0-rc.2.22456.11")); + testProject.PackageReferences.Add(new TestPackageReference("Microsoft.DotNet.ILCompiler", ExplicitPackageVersion)); + testProject.PackageReferences.Add(new TestPackageReference("runtime.win-x64.Microsoft.DotNet.ILCompiler", ExplicitPackageVersion)); var testAsset = _testAssetsManager.CreateTestProject(testProject); @@ -439,6 +444,7 @@ public void NativeAot_hw_runs_with_cross_PackageReference_PublishAot_is_empty(st var publishedDll = Path.Combine(publishDirectory, $"{projectName}.dll"); File.Exists(publishedDll).Should().BeTrue(); + CheckIlcVersions(Path.Combine(testAsset.TestRoot, testProject.Name), targetFramework, ExplicitPackageVersion); } } @@ -476,7 +482,7 @@ public void NativeAot_hw_fails_with_sdk6_PackageReference_PublishAot_is_enabled( 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")); + testProject.PackageReferences.Add(new TestPackageReference("Microsoft.DotNet.ILCompiler", ExplicitPackageVersion)); var testAsset = _testAssetsManager.CreateTestProject(testProject); @@ -700,6 +706,30 @@ public void It_publishes_with_implicit_rid_with_NativeAotApp(string targetFramew } } + private void CheckIlcVersions(string projectPath, string targetFramework, string expectedVersion) + { + // Compiler version matches expected version + var ilcToolsPathCommand = new GetValuesCommand(Log, projectPath, targetFramework, "IlcToolsPath") + { + DependsOnTargets = "WriteIlcRspFileForCompilation" + }; + ilcToolsPathCommand.Execute().Should().Pass(); + var ilcToolsPath = ilcToolsPathCommand.GetValues()[0]; + var ilcVersion = Path.GetFileName(Path.GetDirectoryName(Path.GetDirectoryName(ilcToolsPath))); + ilcVersion.Should().Be(ExplicitPackageVersion); + + // Compilation references (corelib) match expected version + var ilcReferenceCommand = new GetValuesCommand(Log, projectPath, targetFramework, "IlcReference", GetValuesCommand.ValueType.Item) + { + DependsOnTargets = "WriteIlcRspFileForCompilation" + }; + ilcReferenceCommand.Execute().Should().Pass(); + var ilcReference = ilcReferenceCommand.GetValues(); + var corelibReference = ilcReference.Where(r => Path.GetFileName(r).Equals("System.Private.CoreLib.dll")).Single(); + var ilcReferenceVersion = Path.GetFileName(Path.GetDirectoryName(Path.GetDirectoryName(corelibReference))); + ilcReferenceVersion.Should().Be(ExplicitPackageVersion); + } + private TestProject CreateHelloWorldTestProject(string targetFramework, string projectName, bool isExecutable) { var testProject = new TestProject() From c2309b633c2e9d4c8f4d5370e5b3cf2532e480b6 Mon Sep 17 00:00:00 2001 From: Sven Boemer Date: Tue, 25 Oct 2022 20:41:52 +0000 Subject: [PATCH 7/7] Fix test --- .../GivenThatWeWantToPublishAnAotApp.cs | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/Tests/Microsoft.NET.Publish.Tests/GivenThatWeWantToPublishAnAotApp.cs b/src/Tests/Microsoft.NET.Publish.Tests/GivenThatWeWantToPublishAnAotApp.cs index 05bad021b631..b1095087a0f5 100644 --- a/src/Tests/Microsoft.NET.Publish.Tests/GivenThatWeWantToPublishAnAotApp.cs +++ b/src/Tests/Microsoft.NET.Publish.Tests/GivenThatWeWantToPublishAnAotApp.cs @@ -443,8 +443,6 @@ public void NativeAot_hw_runs_with_cross_PackageReference_PublishAot_is_empty(st var publishDirectory = publishCommand.GetOutputDirectory(targetFramework: targetFramework, runtimeIdentifier: rid).FullName; var publishedDll = Path.Combine(publishDirectory, $"{projectName}.dll"); File.Exists(publishedDll).Should().BeTrue(); - - CheckIlcVersions(Path.Combine(testAsset.TestRoot, testProject.Name), targetFramework, ExplicitPackageVersion); } }