团队城市 vs-2017 Build 版本

问题描述:

如何在 VS2017 中设置 dotnet 核心项目的构建版本?

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

是通过 powershell 的构建步骤在 .csproj 文件中包含 version 标签还是有更好的方法?

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

我已经使用以下脚本创建了一个 PowerShell 构建步骤并且运行良好:

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)
}