NuGet包的差异取决于生成方法

问题描述 投票:0回答:1

我有一个.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

安装后,该程序包似乎运行良好,我可以访问应该包含在该程序包中的名称空间和类。

出于某些原因,我将不打算进入这里,没有这个选项,我必须自己打包包裹。我已经在运行nuget pack mycompany.nuspec的Visual Studio中设置了一个生成后事件,并且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个回答
0
投票

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

© www.soinside.com 2019 - 2024. All rights reserved.