Search code examples
c#nuget

Unable to add LICENSE/README to NuGet package: error NU5030


I have the following .targets file that I import in multiple .csproj projects:

<Project>
    <PropertyGroup>
        ...         
        <PackageLicenseFile>LICENSE</PackageLicenseFile>
        <PackageReadmeFile>README.md</PackageReadmeFile>
        ...         
    </PropertyGroup>
</Project>

Both LICENSE and README.md files are next to that .targets file which is at root of repository.

But I get the following error:

error NU5030: The license file 'C:\...\blah\LICENSE' does not exist in the package. [C:\...\blah\whatever\whatever.csproj]

Reference documentation:

Question:

How can I get these two files packed onto the NuGet package?


Solution

  • Finally found the cause thanks to a clue in the docs though that wasn't enough to get it working.

    Not only there must be ItemGroup as well but these shall have $(MSBuildThisFileDirectory):

    <Project>
    
        <PropertyGroup>
            <PackageLicenseFile>LICENSE</PackageLicenseFile>
            <PackageReadmeFile>README.md</PackageReadmeFile>
        </PropertyGroup>
    
        <ItemGroup>
            <None Include="$(MSBuildThisFileDirectory)LICENSE" Pack="true" PackagePath="" />
            <None Include="$(MSBuildThisFileDirectory)README.md" Pack="true" PackagePath="" />
        </ItemGroup>
    
    </Project>