简体   繁体   English

在nuget包中包含引用的项目

[英]Include referenced project in nuget package

I have a solution with 3 projects (using netstandard1.4). 我有3个项目的解决方案(使用netstandard1.4)。 Project A contains shared code. 项目A包含共享代码。 Project B is a server side library and project C is a client side library. 项目B是服务器端库,项目C是客户端库。 Project B and C include project A as project reference. 项目B和C包括项目A作为项目参考。

Now I want to publish project B and project C as a nuget package. 现在我想将项目B和项目C发布为nuget包。

The Problem is the nuget packages for project B and C do not contain the code / dll from project A. It looks like project B and C want project A also as a nuget package. 问题是项目B和C的nuget包不包含项目A的代码/ dll。看起来项目B和C希望项目A也作为nuget包。

How can I pack the project B and C as standalone nuget packages? 如何将项目B和C打包为独立的nuget包? I don't want to publish project A as a nuget package. 我不想将项目A发布为nuget包。

How can I pack the project B and C as standalone nuget packages? 如何将项目B和C打包为独立的nuget包? I don't want to publish project A as a nuget package. 我不想将项目A发布为nuget包。

Since you are using .NET Standard 1.4 , you could not use the direct way " dotnet pack " to include the project references. 由于您使用的是.NET Standard 1.4 ,因此无法使用“ dotnet pack ”直接方式来包含项目引用。 Because dotnet pack will pack only the project and not its P2P references, you can get the detail info from the document dotnet-pack and the issue on GitHub : 因为dotnet pack只打包项目而不打包P2P引用,所以你可以从文件dotnet-pack获取详细信息,以及GitHub上的问题

NuGet dependencies of the packed project are added to the .nuspec file, so they're properly resolved when the package is installed. 打包项目的NuGet依赖项将添加到.nuspec文件中,因此在安装软件包时可以正确解析它们。 Project-to-project references aren't packaged inside the project. 项目到项目的引用不会打包在项目中。 Currently, you must have a package per project if you have project-to-project dependencies. 目前,如果您具有项目到项目的依赖关系,则每个项目必须有一个包。

If you want to pack project B and C contain the code / dll from project A, you can use NuGet.exe to create the package B and C by adding project reference assemblies to the .nuspec file: 如果要打包项目B和C包含项目A中的代码/ dll,可以使用NuGet.exe通过将项目引用程序集添加到.nuspec文件来创建程序包B和C:

<?xml version="1.0"?>
<package >
  <metadata>
    <id>TestProjectB</id>
    <version>1.0.0</version>
    <authors>Tester</authors>
    <owners>Tester</owners>
    <requireLicenseAcceptance>false</requireLicenseAcceptance>
    <description>Package description</description>
    <releaseNotes>Test sample for netstandard package.</releaseNotes>
    <copyright>Copyright 2017</copyright>
    <tags>Tag1 Tag2</tags>
  </metadata>
<files>
    <file src="bin\Debug\netstandard1.4\TestProjectB.dll" target="lib\netstandard1.4\TestProjectB.dll" />
    <file src="bin\Debug\netstandard1.4\TestProjectA.dll" target="lib\netstandard1.4\TestProjectA.dll" />
</files>
</package>

In this case, you can pack the project B and C as standalone nuget packages, do not need publish project A as a nuget package. 在这种情况下,您可以将项目B和C打包为独立的nuget包,不需要将项目A作为nuget包发布。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM