TFS Build 2.0 C#,如何向构建/传递Msbuild args添加变量 [英] TFS Build 2.0 C#, howto add variables to the build/Pass Msbuild args

查看:49
本文介绍了TFS Build 2.0 C#,如何向构建/传递Msbuild args添加变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将参数传递给MSBuild 2.0.经过研究,看来我需要使用变量来执行此操作,但是我无法弄清楚如何将其合并到下面的队列请求中.我已经尝试过参数,但这似乎行不通.这是我要告诉MSBuild @"/p:OctoPackPackageVersion =" + releaseNumber的内容.这与使用IBuildRequest.ProcessParameters的XAML构建一起使用.

I am trying to pass arguments to MSBuild 2.0. After research it appears that I need to do this using variables, but I cannot figure out how to incorporate this into my queue request below. I have tried parameters but that does not seem to work. Here is what I am trying to tell MSBuild @" /p:OctoPackPackageVersion=" + releaseNumber. This worked with the XAML build using IBuildRequest.ProcessParameters.

var buildClient = new BuildHttpClient(new Uri(collectionURL), new 
VssCredentials(true));
var res = await buildClient.QueueBuildAsync(new Build
            {
                Definition = new DefinitionReference
                {
                    Id = targetBuild.Id
                },
                Project = targetBuild.Project,
                SourceVersion = ChangeSetNumber,
                Parameters = buildArg

            });
            return res.Id.ToString();

推荐答案

vNext构建系统与旧版XAML构建系统不同,在将构建排队时,您不能直接在构建定义中传递变量来构建任务.您使用的代码在将构建放入队列之前更新了构建定义,这意味着如果变量发生更改,则构建定义可能会不断更改.

vNext build system is different with legacy XAML build system, you cannot pass variable to build tasks in the build definition directly when queue the build. The code you used updated the build definition before queue the build which means that the build definition may keep changing if the variable changed.

此问题的解决方法是在构建定义中添加一个变量,例如"var1",然后将此变量用作MSBuild Task的参数:这样,您就可以在排队构建时将值传递给"var1"变量,而无需更新构建定义.

The workaround for this would be add a variable in your build definition for example "var1" and then use this variable as the arguments for MSBuild Task: With this, you will be able to pass the value to "var1" variable when queue the build without updating the build definition.

Build build = new Build();
build.Parameters = "{\"var1\":\"/p:OctoPackPackageVersion=version2\"}";

// OR using Newtonsoft.Json.JsonConvert
var dict = new Dictionary<string, string>{{"var1", "/p:OctoPackPackageVersion=version2"}};
build.Parameters = JsonConvert.SerializeObject(dict)

这篇关于TFS Build 2.0 C#,如何向构建/传递Msbuild args添加变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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