Skip to content

Commit a2ff7c0

Browse files
LakshanFjkotassbomer
committed
Discourage using explicit package references to ILCompiler to publish (dotnet#74591)
* Show a warning when an explicit package reference to ILCompiler is added * Apply suggestions from code review Co-authored-by: Jan Kotas <jkotas@microsoft.com> * Fix issue 27239 * Apply suggestions from code review Co-authored-by: Sven Boemer <sbomer@gmail.com> * exclude the warning for direct targets file invoke cases Co-authored-by: Jan Kotas <jkotas@microsoft.com> Co-authored-by: Sven Boemer <sbomer@gmail.com>
1 parent fe99c44 commit a2ff7c0

File tree

3 files changed

+25
-11
lines changed

3 files changed

+25
-11
lines changed

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

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,15 +36,18 @@
3636
<IlcDynamicBuildPropertyDependencies>SetupProperties</IlcDynamicBuildPropertyDependencies>
3737
</PropertyGroup>
3838

39-
<ItemGroup>
40-
<!-- If called via package instead of the SDK, update the runtime package version to match the build package -->
41-
<_PackageReferenceExceptILCompiler Include="@(PackageReference)" Exclude="Microsoft.DotNet.ILCompiler" />
42-
<_ILCompilerPackageReference Include="@(PackageReference)" Exclude="@(_PackageReferenceExceptILCompiler)" />
43-
<KnownILCompilerPack Update="Microsoft.DotNet.ILCompiler" Condition="@(_ILCompilerPackageReference->'%(Identity)')=='Microsoft.DotNet.ILCompiler'">
44-
<ILCompilerPackVersion>@(_ILCompilerPackageReference->'%(Version)')</ILCompilerPackVersion>
39+
<!-- If called via package instead of the SDK, update the runtime package version to match the build package -->
40+
<ItemGroup Condition="'$(AotRuntimePackageLoadedViaSDK)' != 'true'">
41+
<KnownILCompilerPack Update="Microsoft.DotNet.ILCompiler">
42+
<ILCompilerPackVersion>$([System.IO.Path]::GetFileName($([System.IO.Path]::GetDirectoryName($([System.IO.Path]::GetDirectoryName($(ILCompilerTargetsPath)))))))</ILCompilerPackVersion>
4543
</KnownILCompilerPack>
4644
</ItemGroup>
4745

46+
<!-- Generate a warning if the non-SDK path is used -->
47+
<Target Name="GenerateILCompilerExplicitPackageReferenceWarning" Condition="'$(SuppressGenerateILCompilerExplicitPackageReferenceWarning)' == '' and '$(AotRuntimePackageLoadedViaSDK)' != 'true' and '$(ILCompilerTargetsPath)' != ''" BeforeTargets="ImportRuntimeIlcPackageTarget">
48+
<Warning Text="Set PublishAot property to true and delete explicit 'Microsoft.DotNet.ILCompiler' package reference in your project file. Explicit 'Microsoft.DotNet.ILCompiler' package reference can run into version errors." />
49+
</Target>
50+
4851
<!-- Locate the runtime package according to the current target runtime -->
4952
<Target Name="ImportRuntimeIlcPackageTarget" Condition="'$(BuildingFrameworkLibrary)' != 'true' and '$(PublishAot)' == 'true' and $(IlcCalledViaPackage) == 'true'" DependsOnTargets="$(ImportRuntimeIlcPackageTargetDependsOn)" BeforeTargets="Publish">
5053
<Error Condition="'@(ResolvedILCompilerPack)' == ''" Text="The ResolvedILCompilerPack ItemGroup is required for target ImportRuntimeIlcPackageTarget" />

src/coreclr/nativeaot/BuildIntegration/Microsoft.DotNet.ILCompiler.props

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@ Copyright (c) .NET Foundation. All rights reserved.
1111
-->
1212
<Project>
1313
<PropertyGroup>
14-
<!-- Set the publishAot property to true when imported from a package reference. -->
15-
<PublishAot Condition="'$(PublishAot)' == '' And '$(AotRuntimePackageLoadedViaSDK)' != 'true'">true</PublishAot>
1614
<!-- N.B. The ILCompilerTargetsPath is used as a sentinel to indicate a version of this file has already been imported. It will also be the path
1715
used to import the targets later in the SDK. -->
1816
<ILCompilerTargetsPath>$(MSBuildThisFileDirectory)Microsoft.DotNet.ILCompiler.SingleEntry.targets</ILCompilerTargetsPath>

src/coreclr/nativeaot/docs/compiling.md

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@
22

33
Please consult [documentation](https://docs.microsoft.com/dotnet/core/deploying/native-aot) for instructions how to compile and publish application.
44

5-
The rest of this document covers advanced topics only.
6-
5+
The rest of this document covers advanced topics only. Adding an explicit package reference to `Microsoft.DotNet.ILCompiler` will generate warning when publishing and it can run into version errors. When possible, use the PublishAot property to publish a native AOT application.
76

87
## Using daily builds
98

@@ -34,7 +33,21 @@ or by adding the following element to the project file:
3433

3534
## Cross-architecture compilation
3635

37-
Native AOT toolchain allows targeting ARM64 on an x64 host and vice versa for both Windows and Linux. Cross-OS compilation, such as targeting Linux on a Windows host, is not supported. To target win-arm64 on a Windows x64 host, in addition to the `Microsoft.DotNet.ILCompiler` package reference, also add the `runtime.win-x64.Microsoft.DotNet.ILCompiler` package reference to get the x64-hosted compiler:
36+
Native AOT toolchain allows targeting ARM64 on an x64 host and vice versa for both Windows and Linux and is now supported in the SDK. Cross-OS compilation, such as targeting Linux on a Windows host, is not supported. For SDK support, add the following to your project file,
37+
38+
```xml
39+
<PropertyGroup>
40+
<PublishAot>true</PublishAot>
41+
</PropertyGroup>
42+
```
43+
44+
Targeting win-arm64 on a Windows x64 host machine,
45+
46+
```bash
47+
> dotnet publish -r win-arm64 -c Release
48+
```
49+
50+
To target win-arm64 on a Windows x64 host on an advanced scenario where the SDK support is not sufficient (note that these scenarios will generate warnings for using explicit package references), in addition to the `Microsoft.DotNet.ILCompiler` package reference, also add the `runtime.win-x64.Microsoft.DotNet.ILCompiler` package reference to get the x64-hosted compiler:
3851
```xml
3952
<PackageReference Include="Microsoft.DotNet.ILCompiler; runtime.win-x64.Microsoft.DotNet.ILCompiler" Version="7.0.0-preview.2.22103.2" />
4053
```

0 commit comments

Comments
 (0)