簡體   English   中英

為具有多個項目的解決方案創建 nuget 包

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

我們目前正在為多個項目構建解決方案。

我們有這樣的事情:

- Common
  - Logging
     - Logging.NLog
- Threading

所以 Logging.NLog 依賴於 Logging、Logging on Common...等。

當我們打包 Logging.NLog 時,我希望 nuget 發現 Loggin 和 Common 依賴項。

目前,我使用 Common 創建了一個包,然后在 Logging 中安裝了 Common 包

install-package Common

但是每當我對 Common 進行修改時,我都必須更新包,它們是由我們的持續集成系統(Hudson)創建的,因此在我們開發時非常煩人。

我只想有一個項目參考(添加參考 -> 項目...),無論如何 nuget 都會發現依賴關系。

有沒有辦法實現它?

有一個針對此確切場景的計划功能

這就是它的外觀:

> nuget.exe pack proj.csproj -IncludeReferencedProjects

這顯然已經 實施僅僅幾天前,但也有漏洞還是

目前,該功能允許:

  • 將多個項目的工件打包到一個 nuget 包中(通過遞歸遍歷項目引用),

要么

  • 如果引用的項目具有隨附的 .nuspec 文件,則創建對這些項目的關聯包的nuget 包引用。

功能請求可以追溯到 1.5,但它一直在下滑。 不過最近,它收集了足夠的質量(請求)以安排在Nuget 2.3 中發布。

發布計划將 2.3 版與“2013 年 4 月下旬”掛鈎,敬請期待。
(目前,最新的 Nuget 版本是 2.2.1)。

目前無法完全按照您的要求執行,但以下內容將幫助您簡化更新。

聽起來您需要將 nuspec 文件添加到您的解決方案中。 類似於以下三個文件。 請注意后兩個中的依賴項。 這些通過 [$version$] 引用相同的 dll 版本。 這意味着當您運行以下命令時,它會更新所有三個,因為依賴項上的方括號需要依賴包的特定版本。

PM> 更新包通用

在 Hudson 中,您需要使用 nuget pack 命令(請參閱 Nuget 命令參考)執行這些 nuspec 文件,並將生成的包包含在您的工件中,並將它們部署到您的本地 nuget 服務器。 我會把它留給你。

您需要做的另一件事是確保您的所有程序集獲得相同版本的相同版本。 同樣,Hudson 可以處理這個問題,或者您可以使用通用的 AssemblyInfo 文件。

普通.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>

日志.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>

日志記錄

<?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>

我認為 Charles 的意思是,如果引用的項目也用於構建 NuGet 包,他希望 NuGet 自動將項目引用解析為包依賴項,對嗎?

例子:

  1. 設置日志記錄以生成 NuGet 包
  2. Logging.Nlog 設置為生成 NuGet 包
  3. Logging.Nlog 有一個對 Logging 的項目引用。
  4. 生成的 Logging.Nlog 包應該依賴於生成的 Logging 包。

這也是我一直在尋找的東西,但遺憾的是我發現它目前不受支持。 上面有一個工作項,計划用於 NuGet 1.7,但甚至沒有關於如何處理它的設計。

這個線程有一個很好的建議: NuGet 和多種解決方案

基本上,將公共組件分解為它們自己的解決方案,並具有自己的發布生命周期。

我設法做到了這樣:

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

在 MyProject.csproj 中為每個項目添加PrivateAssets="All"

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM