Skip to content

Commit dac29ee

Browse files
authored
Use implicit package reference for ILC build package (#28690)
This removes the bundled ILCompiler bits from the SDK, and instead uses implicit PackageReference to import targets that correctly match the ILCompiler package version. Also adds validation that the explict PackageReference scenario uses the expected ILCompiler host and target bits. It doesn't include 8.0 tests.
1 parent 5c54021 commit dac29ee

File tree

8 files changed

+55
-29
lines changed

8 files changed

+55
-29
lines changed

eng/Version.Details.xml

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -114,11 +114,6 @@
114114
<Sha>4db6ac94ffa8bf6dae8ad9c5c68f94b58de917fd</Sha>
115115
<SourceBuild RepoName="linker" ManagedOnly="true" />
116116
</Dependency>
117-
<Dependency Name="Microsoft.DotNet.ILCompiler" Version="8.0.0-alpha.1.22524.5">
118-
<Uri>https://github.com/dotnet/runtime</Uri>
119-
<Sha>5108757b997c59ab8ba1fc5309ab0d4e730e2b77</Sha>
120-
<SourceBuildTarball RepoName="runtime" ManagedOnly="true" />
121-
</Dependency>
122117
<Dependency Name="Microsoft.NET.ILLink.Analyzers" Version="7.0.100-1.22525.3">
123118
<Uri>https://github.com/dotnet/linker</Uri>
124119
<Sha>4db6ac94ffa8bf6dae8ad9c5c68f94b58de917fd</Sha>

eng/Versions.props

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,6 @@
9393
<SystemCodeDomPackageVersion>8.0.0-alpha.1.22524.5</SystemCodeDomPackageVersion>
9494
<SystemTextEncodingCodePagesPackageVersion>8.0.0-alpha.1.22524.5</SystemTextEncodingCodePagesPackageVersion>
9595
<SystemResourcesExtensionsPackageVersion>8.0.0-alpha.1.22524.5</SystemResourcesExtensionsPackageVersion>
96-
<MicrosoftDotNetILCompilerPackageVersion>8.0.0-alpha.1.22524.5</MicrosoftDotNetILCompilerPackageVersion>
9796
</PropertyGroup>
9897
<PropertyGroup>
9998
<!-- Dependencies from https://github.com/dotnet/format -->

src/Layout/redist/targets/BundledSdks.targets

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,5 @@
55
<BundledSdk Include="FSharp.NET.Sdk" Version="1.0.4-bundled-0100" />
66
<BundledSdk Include="Microsoft.Docker.Sdk" Version="1.1.0" />
77
<BundledSdk Include="Microsoft.NET.ILLink.Tasks" Version="$(MicrosoftNETILLinkTasksPackageVersion)" />
8-
<BundledSdk Include="Microsoft.DotNet.ILCompiler" Version="$(MicrosoftDotNetILCompilerPackageVersion)" />
98
</ItemGroup>
109
</Project>

src/Tasks/Microsoft.NET.Build.Tasks/ProcessFrameworkReferences.cs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,9 @@ public class ProcessFrameworkReferences : TaskBase
104104
[Output]
105105
public ITaskItem[] TargetILCompilerPacks { get; set; }
106106

107+
[Output]
108+
public ITaskItem[] ImplicitPackageReferences { get; set; }
109+
107110
// Runtime packs which aren't available for the specified RuntimeIdentifier
108111
[Output]
109112
public ITaskItem[] UnavailableRuntimePacks { get; set; }
@@ -621,6 +624,9 @@ private bool AddAotOrR2RRuntimePackage(AotPackageType packageType, Version norma
621624
else
622625
{
623626
HostILCompilerPacks = new[] { newItem };
627+
var ilCompilerBuildPackageReference = new TaskItem(knownPack.ItemSpec);
628+
ilCompilerBuildPackageReference.SetMetadata(MetadataKeys.Version, packVersion);
629+
ImplicitPackageReferences = new[] { ilCompilerBuildPackageReference };
624630
// ILCompiler supports cross target compilation. If there is a cross-target request, we need to download that package as well
625631
// We expect RuntimeIdentifier to be defined during publish but can allow during build
626632
if (RuntimeIdentifier != null)
@@ -633,17 +639,13 @@ private bool AddAotOrR2RRuntimePackage(AotPackageType packageType, Version norma
633639
if (!hostRuntimeIdentifier.Equals(targetRuntimeIdentifier))
634640
{
635641
var runtimeIlcPackName = packPattern.Replace("**RID**", targetRuntimeIdentifier);
636-
TaskItem targetIlcPackToDownload = new TaskItem(runtimeIlcPackName);
637-
targetIlcPackToDownload.SetMetadata(MetadataKeys.Version, packVersion);
638-
packagesToDownload.Add(targetIlcPackToDownload);
639-
640642
var newItem2 = new TaskItem(runtimeIlcPackName);
641643
newItem2.SetMetadata(MetadataKeys.NuGetPackageId, runtimeIlcPackName);
642644
newItem2.SetMetadata(MetadataKeys.NuGetPackageVersion, packVersion);
643645
TargetILCompilerPacks = new[] { newItem2 };
644646
}
645647
}
646-
}
648+
}
647649

648650
return true;
649651
}

src/Tasks/Microsoft.NET.Build.Tasks/targets/Microsoft.NET.Sdk.FrameworkReferenceResolution.targets

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<!--
1+
<!--
22
***********************************************************************************************
33
Microsoft.NET.Sdk.FrameworkReferenceResolution.targets
44
@@ -123,6 +123,7 @@ Copyright (c) .NET Foundation. All rights reserved.
123123
<Output TaskParameter="HostILCompilerPacks" ItemName="HostILCompilerPack" />
124124
<Output TaskParameter="TargetILCompilerPacks" ItemName="TargetILCompilerPack" />
125125
<Output TaskParameter="UnavailableRuntimePacks" ItemName="UnavailableRuntimePack" />
126+
<Output TaskParameter="ImplicitPackageReferences" ItemName="_ImplicitPackageReference" />
126127

127128
</ProcessFrameworkReferences>
128129

@@ -175,6 +176,14 @@ Copyright (c) .NET Foundation. All rights reserved.
175176
PrivateAssets="all"
176177
ExcludeAssets="all" />
177178
</ItemGroup>
179+
180+
<!-- Add implicit package references that don't already exist in PackageReference. -->
181+
<ItemGroup>
182+
<_ImplicitPackageReference Remove="@(PackageReference)" />
183+
<PackageReference Include="@(_ImplicitPackageReference)"
184+
IsImplicitlyDefined="true"
185+
PrivateAssets="all" />
186+
</ItemGroup>
178187
</Target>
179188

180189
<!--

src/Tasks/Microsoft.NET.Build.Tasks/targets/Microsoft.NET.Sdk.props

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,6 @@ Copyright (c) .NET Foundation. All rights reserved.
151151
<Import Project="$(MSBuildThisFileDirectory)Microsoft.NET.Sdk.CSharp.props" Condition="'$(MSBuildProjectExtension)' == '.csproj'" />
152152
<Import Project="$(MSBuildThisFileDirectory)Microsoft.NET.Sdk.VisualBasic.props" Condition="'$(MSBuildProjectExtension)' == '.vbproj'" />
153153
<Import Project="$(MSBuildThisFileDirectory)Microsoft.NET.Sdk.FSharp.props" Condition="'$(MSBuildProjectExtension)' == '.fsproj'" />
154-
<Import Project="Sdk.props" Sdk="Microsoft.DotNet.ILCompiler" />
155154
<Import Project="Sdk.props" Sdk="Microsoft.NET.ILLink.Tasks" />
156155

157156
<Import Project="$(MSBuildThisFileDirectory)Microsoft.NET.PackTool.props" />

src/Tasks/Microsoft.NET.Build.Tasks/targets/Microsoft.NET.Sdk.targets

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1158,11 +1158,6 @@ Copyright (c) .NET Foundation. All rights reserved.
11581158
<ProjectCapability Remove="ReferenceManagerAssemblies" />
11591159
</ItemGroup>
11601160

1161-
<!-- Temporary workaround for https://github.com/dotnet/runtime/issues/75468. Delete once the issue is fixed. -->
1162-
<PropertyGroup>
1163-
<LinkStandardCPlusPlusLibrary Condition="'$(OS)' != 'Windows_NT' and '$(LinkStandardCPlusPlusLibrary)' == ''">true</LinkStandardCPlusPlusLibrary>
1164-
</PropertyGroup>
1165-
11661161
<Import Project="$(MSBuildThisFileDirectory)Microsoft.NET.DisableStandardFrameworkResolution.targets" Condition="'$(DisableStandardFrameworkResolution)' == 'true'" />
11671162
<Import Project="$(MSBuildThisFileDirectory)Microsoft.NET.DesignerSupport.targets" />
11681163
<Import Project="$(MSBuildThisFileDirectory)Microsoft.NET.GenerateAssemblyInfo.targets" Condition="'$(UsingNETSdkDefaults)' == 'true'"/>

src/Tests/Microsoft.NET.Publish.Tests/GivenThatWeWantToPublishAnAotApp.cs

Lines changed: 38 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ public class GivenThatWeWantToPublishAnAotApp : SdkTest
2727
{
2828
private readonly string RuntimeIdentifier = $"/p:RuntimeIdentifier={RuntimeInformation.RuntimeIdentifier}";
2929

30+
private readonly string ExplicitPackageVersion = "7.0.0-rc.2.22456.11";
31+
3032
public GivenThatWeWantToPublishAnAotApp(ITestOutputHelper log) : base(log)
3133
{
3234
}
@@ -272,7 +274,7 @@ public void NativeAot_hw_runs_with_PackageReference_PublishAot_is_enabled(string
272274
testProject.AdditionalProperties["PublishAot"] = "true";
273275

274276
// This will add a reference to a package that will also be automatically imported by the SDK
275-
testProject.PackageReferences.Add(new TestPackageReference("Microsoft.DotNet.ILCompiler", "7.0.0-rc.2.22456.11"));
277+
testProject.PackageReferences.Add(new TestPackageReference("Microsoft.DotNet.ILCompiler", ExplicitPackageVersion));
276278

277279
// Linux symbol files are embedded and require additional steps to be stripped to a separate file
278280
// assumes /bin (or /usr/bin) are in the PATH
@@ -282,7 +284,7 @@ public void NativeAot_hw_runs_with_PackageReference_PublishAot_is_enabled(string
282284
}
283285
var testAsset = _testAssetsManager.CreateTestProject(testProject);
284286

285-
var publishCommand = new PublishCommand(Log, Path.Combine(testAsset.TestRoot, testProject.Name));
287+
var publishCommand= new PublishCommand(Log, Path.Combine(testAsset.TestRoot, testProject.Name));
286288
publishCommand
287289
.Execute($"/p:RuntimeIdentifier={rid}")
288290
.Should().Pass()
@@ -307,6 +309,8 @@ public void NativeAot_hw_runs_with_PackageReference_PublishAot_is_enabled(string
307309
var command = new RunExeCommand(Log, publishedExe)
308310
.Execute().Should().Pass()
309311
.And.HaveStdOutContaining("Hello World");
312+
313+
CheckIlcVersions(Path.Combine(testAsset.TestRoot, testProject.Name), targetFramework, ExplicitPackageVersion);
310314
}
311315
}
312316

@@ -322,7 +326,7 @@ public void NativeAot_hw_runs_with_PackageReference_PublishAot_is_empty(string t
322326
var testProject = CreateHelloWorldTestProject(targetFramework, projectName, true);
323327

324328
// This will add a reference to a package that will also be automatically imported by the SDK
325-
testProject.PackageReferences.Add(new TestPackageReference("Microsoft.DotNet.ILCompiler", "7.0.0-rc.2.22456.11"));
329+
testProject.PackageReferences.Add(new TestPackageReference("Microsoft.DotNet.ILCompiler", ExplicitPackageVersion));
326330

327331
// Linux symbol files are embedded and require additional steps to be stripped to a separate file
328332
// 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
373377
var publishedExe = Path.Combine(publishDirectory, $"{testProject.Name}{Constants.ExeSuffix}");
374378
File.Exists(publishedDll).Should().BeFalse();
375379
File.Exists(publishedExe).Should().BeTrue();
376-
377380
}
378381
}
379382

@@ -391,8 +394,8 @@ public void NativeAot_hw_runs_with_cross_PackageReference_PublishAot_is_enabled(
391394
testProject.AdditionalProperties["PublishAot"] = "true";
392395

393396
// This will add a reference to a package that will also be automatically imported by the SDK
394-
testProject.PackageReferences.Add(new TestPackageReference("Microsoft.DotNet.ILCompiler", "7.0.0-rc.2.22456.11"));
395-
testProject.PackageReferences.Add(new TestPackageReference("runtime.win-x64.Microsoft.DotNet.ILCompiler", "7.0.0-rc.2.22456.11"));
397+
testProject.PackageReferences.Add(new TestPackageReference("Microsoft.DotNet.ILCompiler", ExplicitPackageVersion));
398+
testProject.PackageReferences.Add(new TestPackageReference("runtime.win-x64.Microsoft.DotNet.ILCompiler", ExplicitPackageVersion));
396399

397400
var testAsset = _testAssetsManager.CreateTestProject(testProject);
398401

@@ -409,6 +412,8 @@ public void NativeAot_hw_runs_with_cross_PackageReference_PublishAot_is_enabled(
409412
var publishedExe = Path.Combine(publishDirectory, $"{testProject.Name}{Constants.ExeSuffix}");
410413
File.Exists(publishedDll).Should().BeFalse();
411414
File.Exists(publishedExe).Should().BeTrue();
415+
416+
CheckIlcVersions(Path.Combine(testAsset.TestRoot, testProject.Name), targetFramework, ExplicitPackageVersion);
412417
}
413418
}
414419

@@ -424,8 +429,8 @@ public void NativeAot_hw_runs_with_cross_PackageReference_PublishAot_is_empty(st
424429
var testProject = CreateHelloWorldTestProject(targetFramework, projectName, true);
425430

426431
// This will add a reference to a package that will also be automatically imported by the SDK
427-
testProject.PackageReferences.Add(new TestPackageReference("Microsoft.DotNet.ILCompiler", "7.0.0-rc.2.22456.11"));
428-
testProject.PackageReferences.Add(new TestPackageReference("runtime.win-x64.Microsoft.DotNet.ILCompiler", "7.0.0-rc.2.22456.11"));
432+
testProject.PackageReferences.Add(new TestPackageReference("Microsoft.DotNet.ILCompiler", ExplicitPackageVersion));
433+
testProject.PackageReferences.Add(new TestPackageReference("runtime.win-x64.Microsoft.DotNet.ILCompiler", ExplicitPackageVersion));
429434

430435
var testAsset = _testAssetsManager.CreateTestProject(testProject);
431436

@@ -438,7 +443,6 @@ public void NativeAot_hw_runs_with_cross_PackageReference_PublishAot_is_empty(st
438443
var publishDirectory = publishCommand.GetOutputDirectory(targetFramework: targetFramework, runtimeIdentifier: rid).FullName;
439444
var publishedDll = Path.Combine(publishDirectory, $"{projectName}.dll");
440445
File.Exists(publishedDll).Should().BeTrue();
441-
442446
}
443447
}
444448

@@ -476,7 +480,7 @@ public void NativeAot_hw_fails_with_sdk6_PackageReference_PublishAot_is_enabled(
476480
var testProject = CreateHelloWorldTestProject("net6.0", projectName, true);
477481
testProject.AdditionalProperties["PublishAot"] = "true";
478482

479-
testProject.PackageReferences.Add(new TestPackageReference("Microsoft.DotNet.ILCompiler", "7.0.0-rc.2.22456.11"));
483+
testProject.PackageReferences.Add(new TestPackageReference("Microsoft.DotNet.ILCompiler", ExplicitPackageVersion));
480484

481485
var testAsset = _testAssetsManager.CreateTestProject(testProject);
482486

@@ -700,6 +704,30 @@ public void It_publishes_with_implicit_rid_with_NativeAotApp(string targetFramew
700704
}
701705
}
702706

707+
private void CheckIlcVersions(string projectPath, string targetFramework, string expectedVersion)
708+
{
709+
// Compiler version matches expected version
710+
var ilcToolsPathCommand = new GetValuesCommand(Log, projectPath, targetFramework, "IlcToolsPath")
711+
{
712+
DependsOnTargets = "WriteIlcRspFileForCompilation"
713+
};
714+
ilcToolsPathCommand.Execute().Should().Pass();
715+
var ilcToolsPath = ilcToolsPathCommand.GetValues()[0];
716+
var ilcVersion = Path.GetFileName(Path.GetDirectoryName(Path.GetDirectoryName(ilcToolsPath)));
717+
ilcVersion.Should().Be(ExplicitPackageVersion);
718+
719+
// Compilation references (corelib) match expected version
720+
var ilcReferenceCommand = new GetValuesCommand(Log, projectPath, targetFramework, "IlcReference", GetValuesCommand.ValueType.Item)
721+
{
722+
DependsOnTargets = "WriteIlcRspFileForCompilation"
723+
};
724+
ilcReferenceCommand.Execute().Should().Pass();
725+
var ilcReference = ilcReferenceCommand.GetValues();
726+
var corelibReference = ilcReference.Where(r => Path.GetFileName(r).Equals("System.Private.CoreLib.dll")).Single();
727+
var ilcReferenceVersion = Path.GetFileName(Path.GetDirectoryName(Path.GetDirectoryName(corelibReference)));
728+
ilcReferenceVersion.Should().Be(ExplicitPackageVersion);
729+
}
730+
703731
private TestProject CreateHelloWorldTestProject(string targetFramework, string projectName, bool isExecutable)
704732
{
705733
var testProject = new TestProject()

0 commit comments

Comments
 (0)