我希望我的Visual Studio Team Services Build使用我的可執行文件的Assembly版本。有沒有簡單的方法來實現這一點?更改Visual Studio Team Services/Visual Studio Online的drop文件夾構建到組件版本
我知道可以將參數傳遞到構建過程中,但是如何在一個步驟中定義參數並稍後使用它?
我希望我的Visual Studio Team Services Build使用我的可執行文件的Assembly版本。有沒有簡單的方法來實現這一點?更改Visual Studio Team Services/Visual Studio Online的drop文件夾構建到組件版本
我知道可以將參數傳遞到構建過程中,但是如何在一個步驟中定義參數並稍後使用它?
不知道我是否正確理解你的問題。您可以通過調用task.servariable Logging Command通過從構建任務回VSTS變量:
##vso[task.setvariable variable=testvar;]testvalue
所以,你可以寫一個PowerShell腳本來獲取程序集版本,並通過這回VSTS。
首先,將你的內部版本號格式設置爲你想要的。我使用:$(BuildDefinitionName)_1.0.0 $(Rev:.r)。 然後,在構建解決方案之前,請在PowerShell Script構建步驟中調用此步驟:
Param(
[string]$pathToSearch = $env:BUILD_SOURCESDIRECTORY,
[string]$buildNumber = $env:BUILD_BUILDNUMBER,
[string]$searchFilter = "AssemblyInfo.*",
[regex]$pattern = "\d+\.\d+\.\d+\.\d+",
[regex]$pattern2 = "AssemblyProduct(\()("".*?"")",
[regex]$pattern3 = "AssemblyCopyright(\()("".*?"")",
[Parameter(Mandatory=$true)]
[string]$assemblyProduct,
[Parameter(Mandatory=$true)]
[string]$Copyright
)
# Pattern: "AssemblyProduct(\()("".*?"")"
# Replace: "AssemblyProduct(""$assemblyProduct"""
try
{
if ($buildNumber -match $pattern -ne $true) {
Write-Host "Could not extract a version from [$buildNumber] using pattern [$pattern]"
exit 1
} else {
$extractedBuildNumber = $Matches[0]
Write-Host "Using version $extractedBuildNumber"
gci -Path $pathToSearch -Filter $searchFilter -Recurse | %{
Write-Host " -> Changing $($_.FullName)"
# remove the read-only bit on the file
sp $_.FullName IsReadOnly $false
# Get the copyright string from a local file
#$Copyright = Get-Content TeamBuildScripts\PSScripts\Copyright.txt
# run the regex replace
(gc $_.FullName) | % { $_ -replace $pattern, $extractedBuildNumber } | sc $_.FullName
(gc $_.FullName) | % { $_ -replace $pattern2, "AssemblyProduct(""$assemblyProduct""" } | sc $_.FullName
(gc $_.FullName) | % { $_ -replace $pattern3, "AssemblyCopyright(""$Copyright""" } | sc $_.FullName
}
Write-Host "Done!"
}
}
catch {
Write-Host $_
exit 1
}