我正在尝试使用TFS(版本12.0.31101.0)实现Build自动化 这是我正在使用的设置,它正确构建并发布到上面提到的放置位置:
对于PreBuild我试图使用以下批处理脚本,但这不是递增:
$path = "E:\Dev\ABC\My Project\AssemblyInfo.vb"
$pattern = '\<Assembly: AssemblyVersion\(.*\)\>'
(Get-Content $path) | ForEach-Object{
if($_ -match $pattern){
# We have found the matching line
# Edit the version number and put back.
$fileVersion = [version]$matches[1]
Write-Output "Major is $Matches[0] Minor is $Matches[1] Build is $Matches[2] Revision is [version]$matches[3]"
$newVersion = "{0}.{1}.{2}.{3}" -f $fileVersion.Major, $fileVersion.Minor, $fileVersion.Build, ($fileVersion.Revision + 1)
'<Assembly: AssemblyVersion("{0}")>' -f $newVersion
} else {
# Output line as is
$_
}
} | Set-Content $path
对于&#39;构建脚本路径&#39;我想压缩内容并将其放入另一个文件夹,我使用以下脚本。
powershell.exe -nologo -noprofile -command "& { Add-Type -A 'System.IO.Compression.FileSystem'; [IO.Compression.ZipFile]::CreateFromDirectory('\$(TF_BUILD_DROPLOCATION)\MySolution\_PublishedWebsites\ABC', 'ABC_Deploy.zip'); }"
在Executon上,它会抛出以下错误:
异常调用&#34; CreateFromDirectory&#34;用&#34; 2&#34;参数:&#34;找不到 路径的一部分&#39; C:\ $ TF_BUILD_DROPLOCATION \ MySolution \ _PublishedWebsites \ ABC 在线:1字符:53 +&amp; {Add-Type -A&#39; System.IO.Compression.FileSystem&#39 ;; [IO.Compression.ZipFile] :: Cr ...... + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~ + CategoryInfo:NotSpecified:(:) [],MethodInvocationException + FullyQualifiedErrorId:DirectoryNotFoundException
我应该对prebuild脚本和后期构建脚本进行哪些更改才能使其正常工作?
答案 0 :(得分:2)
预建: 创建一个C#项目(我使用的是控制台项目),它更新了程序集信息..
答案 1 :(得分:0)
对于“Post Build Script”如果无法通过您正在使用的变量访问构建放置位置;尝试使用COPY命令并将删除的文件夹复制到TFS Build服务器上的已知位置,然后在ZIP Powershell命令中提供该路径。 (虽然现在是解决方法。:))
对于“Pre build Script”,我会检查并回复你。
答案 2 :(得分:0)
For 'post build script path', according to the Exception message it cannot identify the variable $TF_BUILD_DROPLOCATION
.
As it's environment variable, So,please try to access the variables using $env:
. The drop location would be
$env:TF_BUILD_DROPLOCATION
for example.
For PreBuild, if you want to version the assemblies, you can try to put all custom Versioning work into a custom Version.proj MsBuild script and call it in TFS build definition before the .sln. The script injects Version into source code (SharedAssemblyInfo.cs, Wix code, readme.txt), and then solution build builds that source code. Please reference this thread :Versioning .NET builds
You can also reference this article : https://www.stevefenton.co.uk/2012/11/automatically-updating-your-assemblyinfo-with-a-batch-file/