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?
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: