简体   繁体   English

为具有多个项目的解决方案创建 nuget 包

[英]Create nuget package for a solution with multiple projects

We are currently building a solution with several projects.我们目前正在为多个项目构建解决方案。

We have something like this:我们有这样的事情:

- Common
  - Logging
     - Logging.NLog
- Threading

So Logging.NLog is dependant on Logging, Logging on Common...etc.所以 Logging.NLog 依赖于 Logging、Logging on Common...等。

When we pack Logging.NLog I would like nuget to discover the Loggin and Common dependecies.当我们打包 Logging.NLog 时,我希望 nuget 发现 Loggin 和 Common 依赖项。

At the moment, I created a package with Common, then in Logging I installed the package Common with目前,我使用 Common 创建了一个包,然后在 Logging 中安装了 Common 包

install-package Common

But whenever I do a modification to Common, I have to update the package and they are created by our continous integration systeme (Hudson), so it is pretty annoying when we are developing.但是每当我对 Common 进行修改时,我都必须更新包,它们是由我们的持续集成系统(Hudson)创建的,因此在我们开发时非常烦人。

I would like to simply have a Project Reference (Add References -> Project...) and the nuget discover the depencies anyway.我只想有一个项目参考(添加参考 -> 项目...),无论如何 nuget 都会发现依赖关系。

Is there a way to achieve it?有没有办法实现它?

There is a planned feature targeting this exact scenario.有一个针对此确切场景的计划功能

This is how it will apparently look like:这就是它的外观:

> nuget.exe pack proj.csproj -IncludeReferencedProjects

It has apparently been implemented mere days ago, but there are bugs still being ironed out .这显然已经 实施仅仅几天前,但也有漏洞还是

The feature, as it currently stands, allows:目前,该功能允许:

  • packaging several projects' artifacts into a single nuget package (by walking project references recursively),将多个项目的工件打包到一个 nuget 包中(通过递归遍历项目引用),

OR要么

  • creating nuget package references to those projects's associated packages, if the referenced projects have accompanying .nuspec files.如果引用的项目具有随附的 .nuspec 文件,则创建对这些项目的关联包的nuget 包引用。

The feature request dates back all the way to 1.5, but it kept slipping.功能请求可以追溯到 1.5,但它一直在下滑。 Recently though, it gathered enough mass (requests) to be scheduled for release in Nuget 2.3 .不过最近,它收集了足够的质量(请求)以安排在Nuget 2.3 中发布。

The release plan pegs version 2.3 for "End of April, 2013" so stay tuned.发布计划将 2.3 版与“2013 年 4 月下旬”挂钩,敬请期待。
(Presently, the latest Nuget version is 2.2.1). (目前,最新的 Nuget 版本是 2.2.1)。

There is currently no way to do exactly what you ask, but the following will help you streamline your updates.目前无法完全按照您的要求执行,但以下内容将帮助您简化更新。

It sounds like you need to add nuspec files to your solution.听起来您需要将 nuspec 文件添加到您的解决方案中。 Something like the following three files.类似于以下三个文件。 Note the dependencies in the second two.请注意后两个中的依赖项。 These refer to the same dll version as common through [$version$].这些通过 [$version$] 引用相同的 dll 版本。 This means that when you run the following command, it updates all three because the square brackets on the dependencies require a specific version of the dependent packages.这意味着当您运行以下命令时,它会更新所有三个,因为依赖项上的方括号需要依赖包的特定版本。

PM> update-package common PM> 更新包通用

In Hudson, you will need to execute these nuspec files using nuget pack command ( see Nuget command reference ) and include the resulting packages in your artifacts, AND deploy them to your local nuget server.在 Hudson 中,您需要使用 nuget pack 命令(请参阅 Nuget 命令参考)执行这些 nuspec 文件,并将生成的包包含在您的工件中,并将它们部署到您的本地 nuget 服务器。 I will leave that over to you.我会把它留给你。

The other thing you would need to do is ensure that all of your assemblies get the same version for the same build.您需要做的另一件事是确保您的所有程序集获得相同版本的相同版本。 Again, Hudson can take care of this or you could use a common AssemblyInfo file.同样,Hudson 可以处理这个问题,或者您可以使用通用的 AssemblyInfo 文件。

Common.nuspec普通.nuspec

<?xml version="1.0"?>
<package xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd">
<metadata>
    <version>$version$</version>
    <authors>Charles Ouellet</authors>
    <owners />
    <iconUrl>http://domain/Content/images/LOGO_32x32.png</iconUrl>
    <id>Common</id>
    <title>Common</title>
    <requireLicenseAcceptance>false</requireLicenseAcceptance>
    <description>full description here</description>
</metadata>
<files>
    <file src="..\Common\bin\Release\Common.dll" target="lib\net40" />
    <file src="..\Common\bin\Release\Common.pdb" target="lib\net40" />
</files>
</package>

Logging.nuspec日志.nuspec

<?xml version="1.0"?>
<package xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd">
<metadata>
    <version>$version$</version>
    <authors>Charles Ouellet</authors>
    <owners />
    <iconUrl>http://domain/Content/images/LOGO_32x32.png</iconUrl>
    <id>Logging</id>
    <title>Logging</title>
    <requireLicenseAcceptance>false</requireLicenseAcceptance>
    <description>full description here</description>
    <dependencies>
        <dependency id="Common" version="[$version$]" />
    </dependencies>        
</metadata>
<files>
    <file src="..\Logging\bin\Release\Logging.dll" target="lib\net40" />
    <file src="..\Logging\bin\Release\Logging.pdb" target="lib\net40" />
</files>
</package>

Logging.NLog日志记录

<?xml version="1.0"?>
<package xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd">
<metadata>
    <version>$version$</version>
    <authors>Charles Ouellet</authors>
    <owners />
    <iconUrl>http://domain/Content/images/LOGO_32x32.png</iconUrl>
    <id>Logging.NLog</id>
    <title>Logging.NLog</title>
    <requireLicenseAcceptance>false</requireLicenseAcceptance>
    <description>full description here</description>
    <dependencies>
        <dependency id="Logging" version="[$version$]" />
    </dependencies>        
</metadata>
<files>
    <file src="..\Logging.NLog\bin\Release\Logging.NLog.dll" target="lib\net40" />
    <file src="..\Logging.NLog\bin\Release\Logging.NLog.pdb" target="lib\net40" />
</files>
</package>

I think Charles means he wants NuGet to automatically resolve project references into package dependencies if said referenced projects also are used to construct NuGet packages, right?我认为 Charles 的意思是,如果引用的项目也用于构建 NuGet 包,他希望 NuGet 自动将项目引用解析为包依赖项,对吗?

Example:例子:

  1. Logging is set up to generate a NuGet package设置日志记录以生成 NuGet 包
  2. Logging.Nlog is set up to generate a NuGet package Logging.Nlog 设置为生成 NuGet 包
  3. Logging.Nlog has a project reference to Logging. Logging.Nlog 有一个对 Logging 的项目引用。
  4. The generated Logging.Nlog package should get a dependency on the generated Logging package.生成的 Logging.Nlog 包应该依赖于生成的 Logging 包。

This is something I had been looking for myself as well, but sadly I found that it is currently not supported.这也是我一直在寻找的东西,但遗憾的是我发现它目前不受支持。 There is a work item on it, scheduled for NuGet 1.7, but there isn't even a design on how to handle this yet.上面有一个工作项,计划用于 NuGet 1.7,但甚至没有关于如何处理它的设计。

This thread has a good suggestion: NuGet and multiple solutions这个线程有一个很好的建议: NuGet 和多种解决方案

Basically, break out the common components to their own Solution, with their own release lifecycle.基本上,将公共组件分解为它们自己的解决方案,并具有自己的发布生命周期。

I managed this achieve it like this:我设法做到了这样:

<ProjectReference Include="MyProject2.csproj" PrivateAssets="All" />

Add PrivateAssets="All" in MyProject.csproj for each project.在 MyProject.csproj 中为每个项目添加PrivateAssets="All"

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

相关问题 为多个 SDK 项目创建 nuget 包 - Create nuget package for multiple SDK projects 在一个解决方案中从多个项目创建一个 NuGet package - Creating one NuGet package from multiple projects in one solution 从 Visual Studio 解决方案和项目(不是 cmake)中的非托管 (C++/C) 代码创建 Nuget 包 - Create Nuget package from unmanaged (C++/C) code in Visual Studio Solution and projects (not cmake) 是否可以在解决方案中为单个项目创建Nuget包? - Is it Possible to Create Nuget Package for Single Project in a Solution? 在同一解决方案中的两个不同项目上使用相同的 Nuget package - Same Nuget package on two different projects in same solution .Net Standard 2.0 生成 NuGet package 包括同一解决方案中的项目和 NuGet 包 - .Net Standard 2.0 Generate NuGet package including projects in the same solution and NuGet packages 如何从类库项目和预编译视图创建NuGet包? - How to create NuGet package from class library projects and precompiled views? 跨多个解决方案和项目卸载/安装 Nuget Package - uninstall / Install Nuget Package across multiple solutions and projects 如何以编程方式创建多个项目的解决方案? - How to create solution with multiple projects programmatically? 创建 nuget package 而解决方案使用干净的架构 - Create nuget package while solution uses clean architecture
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM