[英]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:目前,该功能允许:
OR要么
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:例子:
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.