novotnyllc / MSBuildSdkExtras

Extra properties for MSBuild SDK projects
MIT License
348 stars 42 forks source link

MSB4057: GetCopyToPublishDirectoryItems missing for per-RID project #259

Open alexrp opened 3 years ago

alexrp commented 3 years ago

I have a project looking like this:

<Project Sdk="MSBuild.Sdk.Extras">
    <PropertyGroup>
        <ExtrasBuildEachRuntimeIdentifier>true</ExtrasBuildEachRuntimeIdentifier>
        <IsPackable>true</IsPackable>
        <NoWarn>$(NoWarn);NU5131</NoWarn>
        <RuntimeIdentifiers>@(SupportedRuntimes)</RuntimeIdentifiers>
        <TargetFrameworks>net6.0</TargetFrameworks>
    </PropertyGroup> 

    <ItemGroup>
        <ReferenceAssemblyProjectReference Include="../ref/runtime.ref.csproj" />
    </ItemGroup>
</Project>

It builds/packs fine on its own.

I reference it from another project like this:

        <ProjectReference Include="../runtime/src/runtime.src.csproj"
                          SkipGetTargetFrameworkProperties="true"
                          ReferenceOutputAssembly="false" />

However, running dotnet pack from this project results in:

runtime.src.csproj : error MSB4057: The target "GetCopyToPublishDirectoryItems" does not exist in the project.

A workaround I'm using for now is adding this at the bottom of the first project:

    <Target Name="GetCopyToPublishDirectoryItems" />