nugetcsproj.net-4.8packagereferencecsproj-user

How to get csproj to add the reference file for a dll for a nuget package?


I'm able to add a dll and make sure it's in lib and ref folders so I can avoid the MSB3246, NU5128, and NU5131 warnings in a .nuspec file.

    <?xml version="1.0" encoding="utf-8"?>
<package >
  <metadata>
    <id>NewDll</id>
    <version>1.0.0</version>
    <title>NewDll</title>
    <authors>Dll Dev Team</authors>
    <requireLicenseAcceptance>false</requireLicenseAcceptance>
    <license type="expression">MIT</license>
    <projectUrl>https://new.dll.com</projectUrl>
    <description>Allow NewDll dll to be used in .NET Framework 4.8 as a nuget package.</description>
    <releaseNotes>Remove missing reference assembly warning.</releaseNotes>
    <copyright>2021</copyright>
      <dependencies>
          <group targetFramework=".NETFramework4.8">
          </group>
      </dependencies>
    <references>
      <group targetFramework="net48">
        <reference file="newdll.dll" />
      </group>
    </references>
  </metadata>
  <files>
      <file src="C:\Users\me\source\repos\Project1\dlls\newdll.dll" target="lib\net48\newdll.dll" />
    <file src="C:\Users\me\source\repos\Project1\dlls\newdll.dll" target="ref\net48\newdll.dll" />
  </files>
</package>

But I don't know how to do that in a .csproj file. I've gotten only part of the way there.

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <TargetFramework>net48</TargetFramework>
    <Description>Put NewDll.dll to be used in .NET Framework 4.8 as a nuget package.</Description>
    <PackageReleaseNotes>Remove missing reference assembly warning.</PackageReleaseNotes>
    <Version>1.0.0</Version>
  </PropertyGroup>

  <!-- How do I add a reference? -->

  <ItemGroup>
    <Content Include="NewDll.dll">
      <Pack>true</Pack>
      <PackagePath>lib\$(TargetFramework)</PackagePath>
    </Content>
  </ItemGroup>
</Project>

How do I make sure that the dll also creates the ref folder in the nuget package in the .csproj?


Solution

  • You can add multiple paths to PackagePath, e.g.:

    <ItemGroup>
      <None Include="NewDll.dll">
        <Pack>true</Pack>
        <PackagePath>lib\$(TargetFramework);ref\$(TargetFramework)</PackagePath>
      </None>
    </ItemGroup>