NuGet包显示没有依赖关系? [英] NuGet package shows no dependencies?

查看:487
本文介绍了NuGet包显示没有依赖关系?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试从.NET 4.7.2类库(VS2017)中制作一个NuGet包,但是生成的NuGet包令人惊讶地显示没有依赖项(这是一个错误)。

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).

我的设置是这样的:


  • 我的类库是.NET Framework 4.7.2

  • 我的班级库使用另一个 NuGet包(具有 依赖项)。

  • 我的类库在.csproj中使用 packageReferences

  • 我的类库包含正确的.nuspec文件

  • 我使用 nuget.exe包来创建软件包

  • My class library is .NET Framework 4.7.2
  • My class library uses another NuGet package (that has dependencies).
  • My class library uses packageReferences in .csproj
  • My class library contains a proper .nuspec file
  • I use nuget.exe pack for creating the package

> nuget.exe pack 命令应自动填写所需的依赖项-以前(在另一个项目中)也是如此。但是,那时我在类库中使用了 packages.config 而不是 packageReferences

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?

这是怎么回事?

如何强制系统再次在软件包中包含所需的依赖项?

注意:


  • 该软件包由TeamCity构建服务器上的MSBuild脚本构建(无VS2017)。该构建脚本同时调用 nuget.exe restore 和更高版本的 nuget.exe pack 作为构建逻辑的一部分。

  • The package is built by a MSBuild script on our TeamCity build server (without VS2017). It's the build script that calls both "nuget.exe restore" and later "nuget.exe pack" as part of its build logic.

MSBuild版本15.7

MSBuild is version 15.7

nuget.exe版本4.6.2

nuget.exe is version 4.6.2

推荐答案


如何强制系统再次在包中包含所需的依赖项?

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

这是关于在使用PackageReference而不是packages.config 时,nuget pack忽略了依赖关系。

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

要解决此问题,可以使用以下命令解决方法,NuGet团队仍在积极改善这种情况:

To resolve this issue, you can use the following workaround, and NuGet team are still actively working on improving this scenario:


打包您的C#类库,该库通过$ b $管理您的依赖项b csproj本身中的 PackageReference

请添加对
<$的引用c $ c> NuGet.Build.Tasks.Pack (
https://www.nuget.org/packages/NuGet.Build.Tasks.Pack/ ),然后运行
msbuild / t:pack 从命令行。

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:


  • 需要添加nuget包 NuGet.Build.Tasks.Pack 到项目。

  • 需要添加属性 / p :PackageOutputPath = D:\TesterFolder -p:Authors = tester

  • 使用命令 msbuild.exe / t:pack ,例如: msbuild.exe / t:pack MyTestLibrary.csproj / p:PackageOutputPath = D:\TestFolder -p: Authors = tester

  • 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

此外,如果要使用 .nuspec 文件来创建nuget包,您应该使用以下 .nuspec 文件:

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>

然后我们可以使用 nuget.exe包创建nuget包。但是,使用这种方法,我们必须在 .nuspec 文件中手动填写所需的依赖项。

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.

希望这会有所帮助。

这篇关于NuGet包显示没有依赖关系?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆