Updating source mappings

2019-08-31 05:42发布

I am using the TFS2018 api to copy the source mappings from my XAML build definitions to the new build definition. I have the following code

var def = defs.FirstOrDefault(d => d.Name == xamlDef.Name);
if (def != null)
{
    var json = JsonConvert.SerializeObject(mappings);
    var tfvs = json.Replace("$(SourceDir)", "");       
    def.Repository.Properties["tfvcMapping"] = tfvs;
    using (var buildClient = new BuildHttpClient(uri, cred))
    {
        var t = buildClient.UpdateDefinitionAsync(def, teamProject);
        var result = t.Result;
    }
}

The tfvs variable contains the following string

{"mappings":[{"serverPath":"$/Utils/TestQueue","mappingType":"map","localPath":"\Utils\TestQueue"},{"serverPath":"$/MyTeamProject/ProjectA","mappingType":"map","localPath":"\MyTeamProject\ProjectA"}]}

After I update the source mapping are not there. If I look at the build definition it only contains the following string

{[tfvcMapping, {"mappings":[{"serverPath":"$/MyTeamProject","mappingType":"map","localPath":"\\"}]}]}

Is the tfvcMapping string incorrect? Is it maybe not possible to update the source mappings using the tfs api?

标签: tfs
1条回答
一纸荒年 Trace。
2楼-- · 2019-08-31 06:03

Of course you can update source mappings using the tfs api, the api is Update a build definition.

The following is an example of JSON file for source mapping, you can check it:

"tfvcMapping": "{\"mappings\":[{\"serverPath\":\"$/TestCase/TestCase1\",\"mappingType\":\"map\",\"localPath\":\"\\\\TestCase1\"},{\"serverPath\":\"$/TestCase/TestCaseProject\",\"mappingType\":\"map\",\"localPath\":\"\\\\TestCaseProject\"}]}"
查看更多
登录 后发表回答