当我运行以下内容时,新版本会排队,但没有我的新映射。
TfsTeamProjectCollection server = TfsTeamProjectCollectionFactory.GetTeamProjectCollection(new Uri(collectionUri));
IBuildServer buildServer = server.GetService<IBuildServer>();
WorkItemStore workItemStore = server.GetService<WorkItemStore>();
Project teamProject = workItemStore.Projects[projectArea];
IBuildDefinition buildDef = buildServer.GetBuildDefinition(teamProject.Name, buildDefininition);
IBuildRequest requestedBuild = buildDef.CreateBuildRequest();
var mapping = requestedBuild.BuildDefinition.Workspace.Mappings[0];
mapping.LocalItem = mapping.LocalItem.Replace("OLD", "NEW");
mapping.ServerItem = mapping.ServerItem.Replace("OLD", "NEW");
requestedBuild.BuildDefinition.Workspace.RemoveMapping(requestedBuild.BuildDefinition.Workspace.Mappings[0]);
requestedBuild.BuildDefinition.Workspace.AddMapping(mappingT.ServerItem,mappingT.LocalItem,mappingT.MappingType);
buildServer.QueueBuild(requestedBuild);
我无法理解为什么构建服务器没有使用我的新映射。在此之前设置断点QueueBuild调用显示映射是我的新值。是不是可以动态地这样做?我见过的所有示例都首先保存了构建定义,或者没有更改映射。
答案 0 :(得分:1)
您只更改了一个内存中对象:QueueBuild会在队列中放入一个指向已保存定义的指针。
如果您不希望永久更改,通过在QueueBuild之前保存,您必须求助于自定义Xaml构建模板(例如,通过添加DownloadFile)。 请记住,通常,运行Build的用户帐户可以完全访问Version Control。