2011-09-02 248 views
15

我們目前正在構建包含多個項目的解決方案。爲具有多個項目的解決方案創建nuget包

我們有這樣的事情:

- Common 
    - Logging 
    - Logging.NLog 
- Threading 

所以Logging.NLog取決於日誌,日誌中常見...等。

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

此刻,我創建了常見的一個包,然後在登錄我安裝包常見的有

install-package Common 

但每當我做了修改,以常見的,我一定要更新包,並在創建通過我們的持續集成系統(Hudson),所以當我們開發時它非常煩人。

我想簡單地有一個項目參考(添加引用 - >項目...)和nuget無論如何發現依賴關係。

有沒有辦法實現它?

+0

您的意思是說,當您爲Logging構建一個NuGet包時,您希望它爲Common包含一個依賴項,因爲Common包含在通過NuGet記錄中? –

+0

[在一個解決方案中從多個項目創建一個NuGet包]可能的副本(https://stackoverflow.com/questions/15882770/creating-one-nuget-package-from-multiple-projects-in-one-solution) –

回答

11

有計劃feature瞄準了這一確切的情況。

這是怎麼回事顯然將是這樣的:

> nuget.exe pack proj.csproj -IncludeReferencedProjects 

它顯然已經implemented僅僅前,但也有bugsstillbeingironedout

的功能,因爲它目前爲,允許:

  • (步行項目引用遞歸),包裝幾個項目的文物到一個單一的NuGet包

OR

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

功能請求可以一直追溯到1.5,但它一直在滑動。最近,它收集了足夠的質量(請求)以便在Nuget 2.3中發佈。

發佈計劃釘住了2013年4月底的2.3版本,敬請期待。
(目前,最新的Nuget版本是2.2.1)。

+2

這似乎在我的版本(2.5.40416.9020)中工作得很好,不需要在.nuspec文件(本例中爲proj.nuspec)中的任何元素。 –

1

我認爲Charles意味着他希望NuGet自動將項目引用解析爲包依賴關係,如果所引用的項目也用於構建NuGet包,對吧?

實施例:

  1. 日誌記錄被設置爲產生一個NuGet包
  2. Logging.Nlog被設置爲產生一個NuGet包
  3. Logging.Nlog具有項目引用日誌記錄。
  4. 生成的Logging.Nlog程序包應該依賴生成的Logging程序包。

這是我一直在尋找自己的東西,但遺憾的是我發現它目前不支持。其上有一個work item,計劃用於NuGet 1.7,但是甚至沒有關於如何處理這個問題的設計。

+0

是的,你是對的!謝謝你提供的信息 –

1

這個討論有一個很好的建議:NuGet and multiple solutions

基本上,打出來的通用組件自己的解決方案,用自己的生命週期發佈。

1

目前沒有辦法完全按照您的要求進行操作,但以下內容將幫助您簡化更新。

這聽起來像你需要添加nuspec文件到你的解決方案。類似以下三個文件。注意後面兩個的依賴關係。這些引用與[$ version $]中常見的dll版本相同。這意味着當您運行以下命令時,它會更新所有這三個,因爲依賴項上的方括號需要特定版本的相關軟件包。常見

在哈德森

PM>更新包,您將需要執行使用的NuGet包命令(see Nuget command reference)這些nuspec文件,包括所得封裝在你的文物,並將其部署到本地的NuGet服務器。我會把它留給你。

您需要做的另一件事是確保您的所有程序集都獲得相同版本的相同版本。再次,哈德森可以照顧這一點,或者你可以使用一個通用的AssemblyInfo文件。

Common.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

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

YES!這也許是我需要的。我現在會嘗試,但是這樣我可以有一個VS解決方案,說3個項目,每個項目都可以引用解決方案中的其他項目,但是當我打包它們時,它們都是與其他包相關的單獨包。好吧,要去試試。thx – Raif

相關問題