.netvisual-studio-2017nuget.net-4.7.2packagereference

NuGet package shows no dependencies?


I try to make a NuGet package from a .NET 4.7.2 class library (VS2017), but the resulting NuGet package surprisingly shows no dependencies (which is an error).

My setup is like this:

The nuget.exe pack command should automatically fill in the needed dependencies - this also used to be the case earlier (in another project). However, at that time I used packages.config instead of packageReferences with my class library. Does that change anything?

What is going on?

How can I force the system to again include the needed dependencies in my package?

Notes:


Solution

  • How can I force the system to again include the needed dependencies in my package?

    This is a known issue about nuget pack is ignoring dependencies when using PackageReference instead of packages.config.

    To resolve this issue, you can use the workaround from that link of referencing NuGet.Build.Tasks.Pack and using msbuild -t:pack to pack it. NuGet team are still actively working on improving this scenario.

    I have tested this workaround, and it works fine. However, the msbuild command requires a little more detail.

    However, if you want to use a .nuspec file to create the nuget package, you should use the following .nuspec file:

    <?xml version="1.0"?>
    <package >
      <metadata>
        <id>MyTestLibrary</id>
        <version>1.0.0</version>
        <authors>Tester</authors>
        <owners>Tester</owners>
        <requireLicenseAcceptance>false</requireLicenseAcceptance>
        <description>Package description</description>
        <releaseNotes>Summary of changes made in this release of the package.</releaseNotes>
        <copyright>Copyright 2018</copyright>
        <tags>Tag1 Tag2</tags>
        <dependencies>
          <group targetFramework=".NETFramework4.7.2">
            <dependency id="Microsoft.Owin" version="4.0.0" exclude="Build,Analyzers" />
          </group>
        </dependencies>
      </metadata>
    
        <files>
            <file src="bin\Debug\MyTestLibrary.dll" target="lib\net472\MyTestLibrary.dll" />
        </files>
    </package>
    

    Then we could use nuget.exe pack to create the nuget package. But, using this method, we have to manually fill in the needed dependencies in the .nuspec file.