TFS Build提供预建自动增量汇编信息1并发布zip文件 [英] TFS Build providing prebuild auto increment assembly information by 1 and post publish zip the files

查看:69
本文介绍了TFS Build提供预建自动增量汇编信息1并发布zip文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用TFS实现Build automation(版本12.0.31101.0)。它构建正确并发布到上面提到的放置位置:


对于PreBuild我试图将汇编信息增加1,使用了以下批处理脚本,这不是递增:

 $ path =" E:\Dev\ABC \ Project Project \AssemblyInfo.vb" 
$ pattern ='\< Assembly:AssemblyVersion \(。* \)\>'
(Get-Content $ path)| ForEach-Object {
if($ _ -match $ pattern){
#我们找到匹配的行
#编辑版本号并放回去。
$ fileVersion = [version] $ matches [1]
Write-Output"Major is $ Matches [0] Minor is $ Matches [1] Build is $ Matches [2] Revision is [version] $匹配[3]"
$ newVersion =" {0}。{1}。{2}。{3}" -f $ fileVersion.Major,$ fileVersion.Minor,$ fileVersion.Build,($ fileVersion.Revision + 1)
'< Assembly:AssemblyVersion(" {0}")>' - f $ newVersion
} else {
#输出行为
$ _
}
} | Set-Content $ path


对于"后期构建脚本路径",我想压缩内容并将其放入另一个文件夹,我使用以下脚本。



 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上它会抛出以下错误:



异常调用"CreateFromDirectory"用"2"表示"2"。参数:"找不到路径的一部分'C:\ $ TF_BUILD_DROPLOCATION \ MySolution \ __PublishedWebsites\ABC At line:1 char:53 +& {Add-Type -A'System.IO.Compression.FileSystem';
[IO.Compression.ZipFile] :: Cr ... + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo :NotSpecified:(:) [],MethodInvocationException + FullyQualifiedErrorId:DirectoryNotFoundException



我应该为prebuild脚本和post build脚本做些什么改变才能使它工作?




解决方案

您好Akshay.MS,



感谢您在此处发帖。



根据错误消息,似乎  powershell无法 识别


TF_BUILD_DROPLOCATION。你可以尝试手动指定droplocation的位置而不是变量,如果你想访问变量,它应该



env:TF_BUILD_DROPLOCATION。


你需要确保powershell可以找到并识别位置。



最好的问候


Limitxiao Gao


I am trying to implement Build automation using TFS (Version 12.0.31101.0). It build properly and publishes to the mentioned drop location:

For PreBuild I am trying to increment assembly information by 1, have used the following batch script and this is not incrementing:

$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

For 'post build script path' i want to zip the contents and put it into another folder, I am using the following script for this.


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'); }"

On Executon it throws the following error:

Exception calling "CreateFromDirectory" with "2" argument(s): "Could not find a part of the path 'C:\$TF_BUILD_DROPLOCATION\MySolution\_PublishedWebsites\ABC At line:1 char:53 + & { Add-Type -A 'System.IO.Compression.FileSystem'; [IO.Compression.ZipFile]::Cr ... + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~ + CategoryInfo : NotSpecified: (:) [], MethodInvocationException + FullyQualifiedErrorId : DirectoryNotFoundException

What changes should i make for both prebuild script and post build script to get this working?


解决方案

Hi Akshay.MS,

Thank you for posting here.

According to the error message, it seems that powershell could not recognize


TF_BUILD_DROPLOCATION. You could try to specify the location of the droplocation manually instead of the variables, and if you want to access the variable, it should

be:


env:TF_BUILD_DROPLOCATION.

You need to make sure the powershell could find and recognize the location.

Best Regards

Limitxiao Gao


这篇关于TFS Build提供预建自动增量汇编信息1并发布zip文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆