Team city vs-2017 Build version

2019-07-24 14:57发布

问题:

How can I set the build version on dotnet core projects in VS2017?

Is it through a build step over powershell to include the the version tag on .csproj file or is there a better way?

回答1:

I've created a PowerShell Build Step with the following script and worked fine:

$newBuildNumber = "%build.number%"

$files = Get-ChildItem -Path "*.csproj" -Recurse

foreach( $file in $files ) {
    Write-Host "Processing: " $file.Name
    $info = [xml] (Get-Content $file)

    if($info.Project.PropertyGroup.Version){
    $info.Project.PropertyGroup.Version = $newBuildNumber
    }
    else {
       $newChild = $info.CreateElement("Version")
       $newChild.set_InnerXml($newBuildNumber)

       $info.Project.PropertyGroup.AppendChild($newChild)
    }

    $info.Save($file)
}