Skip to content

Commit 4a3adf6

Browse files
committed
Use ILCompilerTargetsPath instead of AfterMicrosoftNETSdkTargets for ILC import
Replace the AfterMicrosoftNETSdkTargets hook with the SDK's ILCompilerTargetsPath extension point to import ILC targets in the correct order (before ILLink), fixing the DynamicCodeSupport property evaluation error. Gate IlcSetupPropertiesDependsOn on _IlcReferencedAsPackage to skip NuGet package resolution when using live ILC targets.
1 parent 9639ed2 commit 4a3adf6

3 files changed

Lines changed: 11 additions & 25 deletions

File tree

eng/testing/tests.singlefile.targets

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,11 @@
3030
<TrimmerSingleWarn>false</TrimmerSingleWarn>
3131
<StackTraceLineNumberSupport>true</StackTraceLineNumberSupport>
3232

33-
<!-- NativeAOT always enables trimming. Set this early so liveILLink.targets
34-
computes _RequiresLiveILLink=true and loads ILLink targets that define
35-
_PrepareTrimConfiguration. Previously set by the directly-imported
36-
Microsoft.NETCore.Native.targets, now deferred via AfterMicrosoftNETSdkTargets. -->
37-
<PublishTrimmed>true</PublishTrimmed>
33+
<!-- Use the SDK's ILCompilerTargetsPath hook to import ILC targets in the correct order
34+
(before ILLink), matching how the shipping SDK imports them. -->
35+
<PublishAot>true</PublishAot>
36+
<_IlcReferencedAsPackage>false</_IlcReferencedAsPackage>
37+
<ILCompilerTargetsPath>$(CoreCLRBuildIntegrationDir)Microsoft.DotNet.ILCompiler.SingleEntry.targets</ILCompilerTargetsPath>
3838

3939
<!-- Forced by ILLink targets -->
4040
<SelfContained>true</SelfContained>
@@ -48,14 +48,6 @@
4848
<DefineConstants>$(DefineConstants);TEST_READY_TO_RUN_COMPILED</DefineConstants>
4949
</PropertyGroup>
5050

51-
<!-- Import ILC targets after the SDK targets so that the NativeCompile target redefinition
52-
in Microsoft.NETCore.Native.Publish.targets comes AFTER the SDK's empty placeholder
53-
in Microsoft.NET.Publish.targets (MSBuild last-definition-wins). This mirrors how
54-
ILLink targets are imported via $(ILLinkTargetsPath) at the end of Microsoft.NET.Sdk.targets. -->
55-
<PropertyGroup Condition="'$(TestNativeAot)' == 'true'">
56-
<AfterMicrosoftNETSdkTargets>$(AfterMicrosoftNETSdkTargets);$(CoreCLRBuildIntegrationDir)Microsoft.DotNet.ILCompiler.SingleEntry.targets</AfterMicrosoftNETSdkTargets>
57-
</PropertyGroup>
58-
5951
<ItemGroup Condition="'$(TestNativeAot)' == 'true'">
6052
<RdXmlFile Include="$(MSBuildThisFileDirectory)default.rd.xml" />
6153
<TrimmerRootAssembly Include="TestUtilities" Condition="'$(SkipTestUtilitiesReference)' != 'true'" />

src/coreclr/nativeaot/BuildIntegration/Microsoft.DotNet.ILCompiler.SingleEntry.targets

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
<PropertyGroup>
4343
<!-- If the NativeAOT toolchain is being consumed via package, runtime-specific properties must be set before compilation can proceed -->
4444
<ImportRuntimeIlcPackageTargetDependsOn>RunResolvePackageDependencies</ImportRuntimeIlcPackageTargetDependsOn>
45-
<IlcSetupPropertiesDependsOn>ImportRuntimeIlcPackageTarget</IlcSetupPropertiesDependsOn>
45+
<IlcSetupPropertiesDependsOn Condition="'$(_IlcReferencedAsPackage)' != 'false'">ImportRuntimeIlcPackageTarget</IlcSetupPropertiesDependsOn>
4646
<IlcDynamicBuildPropertyDependencies>SetupProperties</IlcDynamicBuildPropertyDependencies>
4747
</PropertyGroup>
4848

src/tests/Directory.Build.targets

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -544,11 +544,11 @@
544544

545545
<IlcTreatWarningsAsErrors>false</IlcTreatWarningsAsErrors>
546546

547-
<!-- NativeAOT always enables trimming. Set this early so liveILLink.targets (imported below)
548-
computes _RequiresLiveILLink=true and loads the ILLink targets that define
549-
_PrepareTrimConfiguration. Previously this was set by Microsoft.NETCore.Native.targets
550-
during direct import, but now that import is deferred via AfterMicrosoftNETSdkTargets. -->
551-
<PublishTrimmed>true</PublishTrimmed>
547+
<!-- Use the SDK's ILCompilerTargetsPath hook to import ILC targets in the correct order
548+
(before ILLink), matching how the shipping SDK imports them. -->
549+
<PublishAot>true</PublishAot>
550+
<_IlcReferencedAsPackage>false</_IlcReferencedAsPackage>
551+
<ILCompilerTargetsPath>$(CoreCLRBuildIntegrationDir)Microsoft.DotNet.ILCompiler.SingleEntry.targets</ILCompilerTargetsPath>
552552

553553
<IlcToolsPath>$(CoreCLRCrossILCompilerDir)</IlcToolsPath>
554554
<IlcBuildTasksPath>$(CoreCLRILCompilerDir)netstandard/ILCompiler.Build.Tasks.dll</IlcBuildTasksPath>
@@ -581,12 +581,6 @@
581581

582582
<Import Project="$(RepositoryEngineeringDir)nativeSanitizers.targets" Condition="'$(TestBuildMode)' == 'nativeaot'" />
583583

584-
<!-- Import ILC targets after the SDK targets so that the NativeCompile target redefinition
585-
in Microsoft.NETCore.Native.Publish.targets comes AFTER the SDK's empty placeholder
586-
in Microsoft.NET.Publish.targets (MSBuild last-definition-wins). -->
587-
<PropertyGroup Condition="'$(TestBuildMode)' == 'nativeaot'">
588-
<AfterMicrosoftNETSdkTargets>$(AfterMicrosoftNETSdkTargets);$(CoreCLRBuildIntegrationDir)Microsoft.DotNet.ILCompiler.SingleEntry.targets</AfterMicrosoftNETSdkTargets>
589-
</PropertyGroup>
590584
<Import Project="$(RepoRoot)eng/liveILLink.targets" />
591585

592586
<ItemGroup Condition="'$(TestBuildMode)' == 'nativeaot'">

0 commit comments

Comments
 (0)