NuGet package shows no dependencies?

偶尔善良 提交于 2019-12-04 14:33:34
Leo Liu-MSFT

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 following workaround, and NuGet team are still actively working on improving this scenario:

To package your C# Class Library which manages your dependencies via PackageReference in the csproj itself,

please add a reference to NuGet.Build.Tasks.Pack ( https://www.nuget.org/packages/NuGet.Build.Tasks.Pack/) and run msbuild /t:pack from the command line.

I have test this workaround, it works fine. To make sure this workaround works fine, we need to pay attention to the following points:

  • Need to add the nuget package NuGet.Build.Tasks.Pack to the project.
  • Need to add properties /p:PackageOutputPath="D:\TesterFolder" -p:Authors=tester
  • Use the command msbuild.exe /t:pack, like: msbuild.exe /t:pack "MyTestLibrary.csproj" /p:PackageOutputPath="D:\TestFolder" -p:Authors=tester

Besides, if you want to use .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.

Hope this helps.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!