[英]How do you create a nuget package in a TFS post build script?
我正在嘗試使用TFS后期構建腳本中的nuget打包和發布庫。 TFS構建似乎沒有使用標准的項目輸出路徑,因此使事情變得復雜。 我要做的就是構建項目(它確實可以完成),然后使用nuget打包和發布。
這是我的劇本。 它在我的本地計算機上運行得很好。
param([string]$project, [string]$version)
if (-not $project)
{
Write-Error ("The project parameter is required.")
exit 1
}
if (-not $version)
{
$version = $Env:TF_BUILD_BUILDNUMBER
}
if (-not $version)
{
Write-Error ("Either the version parameter or the TF_BUILD_BUILDNUMBER environment variable is required.")
exit 1
}
$projectFile = "$project\$project.csproj"
$packageFile = "$project.$version.nupkg"
$nugetPath = ".nuget\NuGet.exe"
if ($Env:TF_BUILD_SOURCESDIRECTORY)
{
# relative paths won't work on the build server
$projectFile = "$Env:TF_BUILD_SOURCESDIRECTORY\$projectFile"
$packageFile = "$Env:TF_BUILD_SOURCESDIRECTORY\$packageFile"
$nugetPath = "$Env:TF_BUILD_SOURCESDIRECTORY\$nugetPath"
}
else
{
$nugetPath = ".\$nugetPath"
}
Write-Host ("packing $projectFile...")
& $nugetPath pack "$projectFile" -Version $version -Symbols -IncludeReferencedProjects
這是我遇到的錯誤。
& : The term '.\.nuget\NuGet.exe' is not recognized as the name of a cmdlet, function, script file, or operable
program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
At C:\a\src\project\.build\PublishPackage.ps1:85 char:3
+ & $nugetPath pack "$projectFile" -Version $version -Symbols -IncludeReferencedPr ...
+ ~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (.\.nuget\NuGet.exe:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
我簡化了腳本,所以行號不匹配,但是您可以看到它是導致錯誤的最后一行。 我正在將Visual Studio Online與托管的構建控制器一起使用。
您為什么不使用標准機制?
<!-- Property that enables building a package from a project --> <BuildPackage Condition=" '$(BuildPackage)' == '' ">true</BuildPackage>
編輯您要從中生成nuget包的解決方案中的每個項目
右鍵單擊項目->“卸載項目”
再次右鍵單擊該項目,然后單擊“編輯[NameofYourProject]”
通過將以下內容添加到第一個PropertyGroup來將BuildPackage設置為true
<BuildPackage>true</BuildPackage>
保存文件並重新加載項目
將更改提交到新構建隊列中,然后應該在構建結果中看到您的軟件包。
這將基本上使用項目文件(對於C#.csproj)創建您的程序包
如果您需要對包創建的更多控制,則可以在項目中包含一個.nuspec文件,您可以在其中指定更多元數據屬性,例如:依賴項,標簽,標題,所有者等。
甚至您可以使用類似的參數
<version>$version$</version>
使nuget軟件包版本與實際程序集版本同步。
如果您需要在nuget build命令上為構建服務器指定OutDir,請修改NuGet.targets文件BuildCommand
定義,如下所示。
<BuildCommand>$(NuGetCommand) pack "$(ProjectPath)" -Properties "Configuration=$(Configuration);Platform=$(Platform);OutDir=$(OutDir)" $(NonInteractiveSwitch) -OutputDirectory "$(PackageOutputDir)" -symbols</BuildCommand>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.