2015-12-23 38 views
1

如何在nuget pack的NuGet包如何設置通過命令行/上改變依賴版本

<?xml version="1.0"?> 
<package > 
    <metadata> 
    <id>MyPacked.Name</id> 
    <version>1.1.1</version> 
    <authors>Pawel Cioch</authors> 
    <owners>Pawel Cioch</owners> 
    <requireLicenseAcceptance>false</requireLicenseAcceptance> 
    <description>Some Cool package</description> 
    <releaseNotes>Initial Release</releaseNotes> 
    <copyright>Copyright 2015</copyright> 
    <tags>replace dependency version</tags> 
    <dependencies> 
     <dependency id="dep1" version="I want version here to be same as package version" /> 
     <dependency id="dep2" version="2.1.3" /> 
    </dependencies> 
    </metadata> 
</package> 

nuspec文件動態改變依賴版本請不要問「你爲什麼需要它」問題

也對不起,如果問題是模糊的,但因爲我通過嘗試解決它/失敗的一切似乎是現在很明顯所以「我不知道該怎麼問」

回答

2

<version>標籤可以通過使用-Version開關被簡單的改變

的NuGet包-Version 2.0.0

的的NuGet文件說一點關於更換令牌https://docs.nuget.org/create/nuspec-reference#replacement-tokens

我們可以做的是使用自定義令牌/標記

... 
    <version>$myVersion$</version> 
    ... 
    <dependencies> 
     <dependency id="dep1" version="$myVersion$" /> 

現在如何替換這個,現在不需要開關-Version,但是我們必須使用-Properties切換

nuget pack -Prop myVersion=3.0.0 

一些更高級的命令

nuget pack My.ProjName\My.ProjName.csproj -Build -Prop Configuration=Release;myVersion=3.0.0 -OutputDirectory SomeDirHere 

,並與PowerShell的(例如)發揮很好,你必須使用是否爲分號多個屬性

$userVersion = Read-Host 'Enter a valid version you want to use' 
nuget pack .\My.ProjName\My.ProjName.csproj -Build -Prop "Configuration=Release;myVersion=$userVersion" -OutputDirectory SomeDirHere 
包裹亞丙值在雙引號

注意:使用nuget預定義$version$標記將工作依賴項,但版本將從獲得AssemblyInfo.cs上面的想法是通過命令行每次都明確設置版本

我希望有人會發現它很有用,節省時間

+0

他們真的應該明確說明分號分隔的屬性列表應該用引號括起來,這真的把我扔了。謝謝。 –

相關問題