将安装文件复制到 TFS 中以版本号命名的文件夹中

Copy the Setup file to a folder named with version number in TFS

我们正在使用 TFS 构建,当我在 TFS 构建中构建项目时,它还会创建一个安装文件。

比如我的应用版本是V1.2.3(来自assembly.cs)安装文件的位置是C:\myproject\setup\setup.exe

好吧,我想将此安装程序 exe 复制到以下文件夹中

C:\products\producta\V1.2.3

所以我只需要获取版本号来创建一个名为 "V1.2.3" 的文件夹。对于复制和创建,我可以制作一个批处理文件,但我不知道如何获取版本号。 TFS 有一些变量,例如 Build.SourceVersion 但是这些变量没有给我产品的版本号。

我该怎么做?

您必须编写一个脚本来执行此操作。

1) 从 assemblyInfo.cs

中读取内部版本号的 Powershell 脚本
$myAssemblyVersion = major.minor.patch -> Read from assembyInfo.cs
$versionWithBuildId = '{0}.{1}' -f $myAssemblyVersion, $Env:BUILD_BUILDID

2) 从当前版本更新 TFS 内部版本号

Write-Verbose -verbose "##vso[build.updatebuildnumber]$versionWithBuildId"

之后您可以使用 "Copy Files" 或 "Publish Artifact" 步骤。

和"Copy Files"

Target Folder = "C:\products\producta$(Build.BuildNumber)"

和"Publish Artifact"

Artifact Name = "$(Build.BuildNumber)"

Path = "C:\products\producta"