【问题标题】:NuGet package differences depending on build methodNuGet 包差异取决于构建方法
【发布时间】:2020-06-17 21:37:12
【问题描述】:

我有一个 .NET Core 项目,我想将其打包为 NuGet 包,以便在其他 Visual Studio 项目/解决方案中使用。在 .NET Core 项目中,有一个不错的功能,您可以在项目属性中选择以在构建时生成 NuGet 包,我尝试过。结果是一个包,我们称之为My.Company.Package,它有一个生成的nuspec文件,如下所示:

<?xml version="1.0" encoding="utf-8"?>
<package xmlns="http://schemas.microsoft.com/packaging/2012/06/nuspec.xsd">
  <metadata>
    <id>My.Company.Package</id>
    <version>10.1.2</version>
    <authors>My.Company.Package</authors>
    <owners>My.Company.Package</owners>
    <requireLicenseAcceptance>false</requireLicenseAcceptance>
    <description>Package Description</description>
    <dependencies>
      <group targetFramework=".NETCoreApp3.1">
        <dependency id="Microsoft.Win32.Registry" version="4.7.0" exclude="Build,Analyzers" />
      </group>
    </dependencies>
  </metadata>
  <files>
    <file src="C:\dev\MyProduct\bin\Debug\netcoreapp3.1\My.Company.dll" target="lib\netcoreapp3.1\My.Company.dll" />
  </files>
</package>

在另一个解决方案中安装构建的包时,NuGet 包管理器会显示以下内容:

Installing:

Microsoft.NETCore.Platforms.3.1.0
Microsoft.Win32.Registry.4.7.0
My.Company.Package.10.1.2
System.Security.AccessControl.4.7.0
System.Security.Principal.Windows.4.7.0

安装后,包似乎工作正常,我可以访问应该包含在包中的命名空间和类。

由于我不会进入这里的原因,我必须自己打包包裹,没有这个选项。我在 Visual Studio 中设置了一个运行 nuget pack mycompany.nuspec 的构建后事件,mycompany.nuspec 看起来像这样(我试图模仿生成的):

<?xml version="1.0" encoding="utf-8"?>
<package xmlns="http://schemas.microsoft.com/packaging/2012/06/nuspec.xsd">
  <metadata>
    <id>My.Company.Other.Package</id>
    <version>10.1.214</version>
    <authors>My Company</authors>
    <description>
    The real description.
    </description>
    <copyright>© My company</copyright>
    <tags>My company</tags>
    <dependencies>
      <group targetFramework=".NETCoreApp3.1">
        <dependency id="Microsoft.Win32.Registry" version="4.7.0" exclude="Build,Analyzers" />
      </group>
    </dependencies>
  </metadata>
  <files>
    <file src="C:\dev\MyProduct\bin\Debug\netcoreapp3.1\My.Company.dll" target="lib\netcoreapp3.1\My.Company.dll" />
  </files>
</package>

包构建成功。但是,当我选择在外部项目中安装它时,NuGet 包管理器会通知我它只会安装这个特定的包:

Installing:

My.Company.Package.10.1.2

安装后,我无法访问预期的类或命名空间,它似乎没有包含所需的所有内容。

第一个选项如何安装这么多从未在 nuspec 文件中列为依赖项的包,我该如何模仿它?

【问题讨论】:

  • 我建议您可以标记您的答案,以便它可以帮助其他社区成员处理类似的问题。谢谢:)

标签: xml visual-studio nuget nuspec


【解决方案1】:

我不知道它到底做了什么,但是在清理和重建我打包的解决方案并重新启动 Visual Studio 之后,它工作了。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-03-06
    • 2015-10-20
    • 2021-07-02
    • 1970-01-01
    • 1970-01-01
    • 2021-07-04
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多