-
Notifications
You must be signed in to change notification settings - Fork 4.9k
/
Copy pathMicrosoft.NETCore.Native.Publish.targets
112 lines (90 loc) · 6.81 KB
/
Microsoft.NETCore.Native.Publish.targets
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Target Name="_ComputeIlcCompileInputs"
BeforeTargets="ComputeIlcCompileInputs"
DependsOnTargets="$(IlcDynamicBuildPropertyDependencies)">
<ItemGroup>
<IlcReference Include="@(_ManagedResolvedAssembliesToPublish)" />
<IlcSatelliteAssembly Include="@(_SatelliteAssembliesToPublish)" />
<IlcSatelliteAssembly Include="@(IntermediateSatelliteAssembliesWithTargetPath)" />
</ItemGroup>
</Target>
<!--
This target hooks into the dotnet CLI publish pipeline. That pipeline has
a target called ComputeFilesToPublish which produces the ItemGroup
ResolvedFileToPublish based on the inputs of @(IntermediateAssembly)
and @(ResolvedAssembliesToPublish). We modify those two item groups
to control what gets published after NativeAOT optimizes the application.
-->
<Target Name="ComputeLinkedFilesToPublish"
BeforeTargets="ComputeResolvedFilesToPublishList"
DependsOnTargets="_ComputeAssembliesToCompileToNative;LinkNative">
<ItemGroup>
<_ResolvedCopyLocalPublishAssets Remove="@(_AssembliesToSkipPublish)" />
<_ResolvedCopyLocalPublishAssets Include="@(_LinkedResolvedAssemblies)" />
</ItemGroup>
<ItemGroup>
<_NativeIntermediateAssembly Include="@(IntermediateAssembly->'$(NativeOutputPath)%(Filename)$(NativeBinaryExt)')" />
<IntermediateAssembly Remove="@(IntermediateAssembly)" />
<IntermediateAssembly Include="@(_NativeIntermediateAssembly)" />
</ItemGroup>
</Target>
<!--
Filter the input publish file list selecting managed assemblies for compilation.
Also produces _AssembliesToSkipPublish which chops out things from the publish
pipeline we don't want to see in the output (native images, CoreCLR artifacts)
until we get a proper AOT NetCore app package.
-->
<UsingTask TaskName="ComputeManagedAssembliesToCompileToNative" AssemblyFile="$(IlcBuildTasksPath)" />
<Target Name="_ComputeAssembliesToCompileToNative" DependsOnTargets="$(IlcDynamicBuildPropertyDependencies)">
<Warning Condition="Exists($(UserRuntimeConfig))" Text="The published project has a runtimeconfig.template.json that is not supported by PublishAot. Move the configuration to the project file using RuntimeHostConfigurationOption." />
<!-- Fail with descriptive error message for common mistake. -->
<Error Condition="$([MSBuild]::VersionLessThan('$(NETCoreSdkVersion)', '6.0.0'))" Text=".NET SDK 6+ is required for native compilation." />
<Error Condition="$([MSBuild]::VersionLessThan('$(TargetFrameworkVersion)', '6.0'))" Text="For native compilation, the project needs to target .NET 6 or higher." />
<Error Condition="'$(RuntimeIdentifier)' == ''"
Text="RuntimeIdentifier is required for native compilation. Try running dotnet publish with the -r option value specified." />
<Error Condition="'$(GeneratePackageOnBuild)' == 'true'" Text="GeneratePackageOnBuild is not supported for native compilation." />
<Error Condition="'$(OutputType)' != 'Library' and '$(NativeLib)' != ''" Text="NativeLib requires OutputType=Library." />
<Error Condition="'$(PublishTrimmed)' == 'false'" Text="PublishTrimmed is implied by native compilation and cannot be disabled." />
<Error Condition="'$(PublishAot)' == 'true' and '$(PublishSingleFile)' == 'true'" Text="PublishAot and PublishSingleFile cannot be specified at the same time." />
<!-- Fail with descriptive error message for common unsupported cases. -->
<Error Condition="'$(DisableUnsupportedError)' != 'true' and '$(OS)' == 'Windows_NT' and '$(_targetOS)' != 'win'"
Text="Cross-OS native compilation is not supported." />
<Error Condition="'$(DisableUnsupportedError)' != 'true' and '$(OS)' != 'Windows_NT' and '$(_targetOS)' == 'win'"
Text="Cross-OS native compilation is not supported." />
<Error Condition="'$(DisableUnsupportedError)' != 'true' and '$(_targetArchitecture)' != 'x64' and '$(_targetArchitecture)' != 'arm64'"
Text="Native compilation does not support targeting $(RuntimeIdentifier) yet." />
<Error Condition="'$(DisableUnsupportedError)' != 'true' and !('$(_hostArchitecture)' == 'x64' or '$(_hostArchitecture)' == 'arm64')"
Text="Native compilation can run on x64 and arm64 hosts only." />
<Error Condition="'$(IlcHostPackagePath)' == '' and '$(RuntimePackagePath)' != '' and ('$(_hostArchitecture)' == 'x64' or '$(_hostArchitecture)' == 'arm64')"
Text="Add a PackageReference for '$(_hostPackageName)' to allow cross-compilation for $(_targetArchitecture)" />
<!-- NativeAOT runtime pack assemblies need to be defined to avoid the default CoreCLR implementations being set as compiler inputs -->
<Error Condition="'@(PrivateSdkAssemblies)' == '' and '$(PublishAotUsingRuntimePack)' != 'true'" Text="The PrivateSdkAssemblies ItemGroup is required for _ComputeAssembliesToCompileToNative" />
<Error Condition="'@(FrameworkAssemblies)' == '' and '$(PublishAotUsingRuntimePack)' != 'true'" Text="The FrameworkAssemblies ItemGroup is required for _ComputeAssembliesToCompileToNative" />
<ComputeManagedAssembliesToCompileToNative
Assemblies="@(_ResolvedCopyLocalPublishAssets)"
DotNetAppHostExecutableName="$(_DotNetAppHostExecutableName)"
DotNetHostFxrLibraryName="$(_DotNetHostFxrLibraryName)"
DotNetHostPolicyLibraryName="$(_DotNetHostPolicyLibraryName)"
SdkAssemblies="@(PrivateSdkAssemblies)"
FrameworkAssemblies="@(FrameworkAssemblies)">
<Output TaskParameter="ManagedAssemblies" ItemName="_ManagedResolvedAssembliesToPublish" />
<Output TaskParameter="SatelliteAssemblies" ItemName="_SatelliteAssembliesToPublish" />
<Output TaskParameter="AssembliesToSkipPublish" ItemName="_AssembliesToSkipPublish" />
</ComputeManagedAssembliesToCompileToNative>
</Target>
<Target Name="CopyNativeBinary" AfterTargets="Publish">
<!-- replace apphost with binary we generated during native compilation -->
<Delete Files="$(PublishDir)\$(TargetName)$(NativeBinaryExt)" />
<Copy SourceFiles="$(NativeOutputPath)$(TargetName)$(NativeBinaryExt)" DestinationFolder="$(PublishDir)" />
<!-- dotnet CLI produces managed debug symbols, which we will delete and copy native symbols instead -->
<Delete Files="$(PublishDir)\$(TargetName).pdb" />
<PropertyGroup>
<_symbolExt Condition="'$(OS)' == 'Windows_NT'">$(NativeSymbolExt)</_symbolExt>
<_symbolExt Condition="'$(OS)' != 'Windows_NT'">$(NativeBinaryExt)$(NativeSymbolExt)</_symbolExt>
</PropertyGroup>
<!-- replace native symbol file if it exists -->
<Delete Files="$(PublishDir)\$(TargetName)$(_symbolExt)" />
<Copy SourceFiles="$(NativeOutputPath)$(TargetName)$(_symbolExt)" DestinationFolder="$(PublishDir)"
Condition="Exists('$(NativeOutputPath)$(TargetName)$(_symbolExt)')" />
</Target>
</Project>