[英]NuGet direct project references as versioned dependencies
我的示例解決方案> Visual Studio中有2個項目庫。 我在另一個中直接引用其中一個。 當我現在發布我的nuget包時,在依賴概述上我得到我直接引用的nuget >= 1.0.0.0
,當我通過nuget執行它時引用意味着沒有直接引用,因為相同的解決方案我得到正確的版本號> =依賴概述。 我不會將默認依賴行為更改為lowest
。 我試過的是用依賴項/ references / files元素更新我的nuspec文件,它們都不適用於我。 我想在直接引用的nuget中看到相同版本的給定nuget作為依賴。
我會嘗試對你的問題做一個非平凡的解釋,因為它沒有得到很好的解釋,但是最后一句話和你對直接引用的強調讓我覺得我知道你在追求什么。 如果我誤解了你的問題,請耐心和道歉。
NuGet定義-IncludeReferencedProjects
選項以指示nuget.exe
如何處理引用的項目,作為依賴項或作為包的一部分:
.nuspec
文件,則該引用的項目將作為顯式NuGet依賴項添加。 我的猜測是你追求前者。
讓我們將問題簡化為最基本的形式:假設您有一個解決方案,其中LibraryA
直接將LibraryB
作為項目引用引用。 構建解決方案時, LibraryA
的程序集輸出將復制到LibraryB
~/
│ Solution.sln
├───LibraryA
│ │ ClassA.cs
│ │ LibraryA.csproj
│ │ LibraryA.nuspec
│ ├───bin
│ │ ├───Debug
│ │ │ LibraryA.dll
│ │ │ LibraryA.pdb
│ │ └───Release
│ └───Properties
│ AssemblyInfo.cs
└───LibraryB
│ ClassB.cs
│ LibraryB.csproj
│ LibraryB.nuspec
├───bin
│ ├───Debug
│ │ LibraryA.dll
│ │ LibraryA.pdb
│ │ LibraryB.dll
│ │ LibraryB.pdb
│ └───Release
└───Properties
AssemblyInfo.cs
確保您的項目包含具有相同名稱的.nuspec文件。 這對項目LibraryA
特別重要,因為它是被引用的項目。 我會做這兩個好的做法。 現在讓我們使用以下基本模板:
<?xml version="1.0"?>
<package >
<metadata>
<id>$id$</id>
<version>$version$</version>
<authors>The author... (**mandatory element**)</authors>
<description>Your description... (**mandatory element**)</description>
</metadata>
</package>
在.nuspec
以上,更換令牌$id$
和$version$
會得到他們的值inferred
,當您運行nuget.exe
對一個.csproj
已建文件。
為了便於說明,我將在AssemblyInfo.cs
文件中使用[assembly: AssemblyVersion("1.0.*")]
,並在每個項目上執行幾個單獨的構建,以確保我的程序集獲得一些不同的有趣版本。
現在,我將從解決方案目錄( ~
)在命令行中運行nuget.exe
PS> nuget pack .\LibraryB\LibraryB.csproj -IncludeReferencedProjects -Verbosity detailed
Attempting to build package from 'LibraryB.csproj'.
Packing files from '~\LibraryB\bin\Debug'.
Using 'LibraryB.nuspec' for metadata.
Add file '~\LibraryB\bin\Debug\LibraryB.dll' to package as 'lib\net451\LibraryB.dll'
Id: LibraryB
Version: 1.0.5993.6096
Authors: The author... (**mandatory element**)
Description: Your description... (**mandatory element**)
Dependencies: LibraryA (= 1.0.5993.7310)
Added file 'lib\net451\LibraryB.dll'.
Successfully created package '~\LibraryB.1.0.5993.6096.nupkg'.
PS>
LibraryB.1.0.5993.6096.nupkg
,其具有對LibraryA.1.0.5993.7310.nupkg
的顯式NuGet依賴性。 當您檢查LibraryB.1.0.5993.6096.nupkg
的內容時,您將看到.nuspec
生成的nuget.exe
將所有$version$
替換標記替換為所使用的實際版本。
最后一兩件事,上面的命令將創建只為NuGet包LibraryB
,但很明顯,你可以創建一個LibraryA
只是再次運行目標LibraryA.csproj
我希望這就是你所追求的,或者至少可以為你能做的事情提供一些啟示。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.