Skip to content

NativeAOT targets copies native binary to publish dir twice #118298

@jtschuster

Description

@jtschuster

NativeAOT targets define the CopyNativeBinary target which copies the linked binary to the publish directory after the Publish target. It also adds the native binary to the IntermediateAssembly itemgroup, which gets copied to the publish directory in _CopyResolvedFilesToPublishPreserveNewest.

<!--
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)" />
<_DebugSymbolsIntermediatePath Remove="@(_DebugSymbolsIntermediatePath)" />
</ItemGroup>
<ItemGroup>
<_NativeIntermediateAssembly Include="@(IntermediateAssembly->'$(NativeOutputPath)%(Filename)$(NativeBinaryExt)')" />
<IntermediateAssembly Remove="@(IntermediateAssembly)" />
<IntermediateAssembly Include="@(_NativeIntermediateAssembly)" />
</ItemGroup>
</Target>

If the goal of overwriting IntermediateAssembly was to prevent the managed .dll from being copied over, we could instead set CopyBuildOutputToPublishDirectory=false and let CopyNativeBinary copy the file to the publish directory. Or we could remove CopyNativeBinary (or make it an empty target - some projects do reference it, but almost exclusively to run after it, not before). But we should avoid a double-write.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    Status

    No status

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions