1

在 TFS 2015 中构建我的项目设置文件\msi 我使用

devenv 命令行任务:

solutionPath /build BuildConfiguration /project projectPath

我的问题是如何从该行更改 msi 版本(如果可能),例如 ... $(BuildVersion)

检查 MSDN devenv 命令行(什么都没有。)

谢谢

4

1 回答 1

1

假设您想在构建期间更改文件中的ProductVersion值。.vdproj您是正确的,没有命令可以直接更改它。

您需要使用 powershell 或以编程方式更改版本。在这种情况下,您可以参考以下代码片段:

static void Main(string[] args) 
{
    string setupFileName = @"<Replace the path to vdproj file>"; 
    StreamReader reader = File.OpenText(setupFileName); 
    string file = string.Empty; 

    try 
    { 
        Regex expression = new Regex(@"(?:\""ProductCode\"" = 
        \""8.){([\d\w-]+)}"); 
        Regex expression1 = new Regex(@"(?:\""UpgradeCode\"" = 
        \""8.){([\d\w-]+)}"); 
        file = reader.ReadToEnd(); 

        file = expression.Replace(file, "\"ProductCode\" = \"8:{" + 
        Guid.NewGuid().ToString().ToUpper() + "}"); 
        file = expression1.Replace(file, "\"UpgradeCode\" = \"8:{" 
        + Guid.NewGuid().ToString().ToUpper() + "}"); 
    } 
    finally 
    { 
        // Close the file otherwise the compile may not work 
        reader.Close(); 
    } 

    TextWriter tw = new StreamWriter(setupFileName); 
    try 
    { 
        tw.Write(file); 
    } 
    finally 
    { 
        // close the stream 
        tw.Close(); 
    } 
 }

或者,在这种情况下,您可以参考从 AssemblyInfo.cs 中替换 AssemblyVersion 的 powershell 脚本来更改文件中的ProductVersion.vdproj

于 2017-02-06T07:39:19.910 回答