我正在设置TFS ISubscriber插件,我希望能够根据已安装的处理模板名称(DONE),TypeID和版本来决定是否触发。
读取名称的代码相对简单:
var ics = context.GetService<ICommonStructureService>();
string ProjectName = string.Empty;
string ProjectState = String.Empty;
int templateId = 0;
CommonStructureProjectProperty[] ProjectProperties = null;
ics.GetProjectProperties(context, projectUri.ToString(), out ProjectName, out ProjectState, out ProjectProperties);
// The Projectproperties contains a property called "Process Template", holding the name.
但是我找不到一种方法来读取其他属性...我使用Reflector查看了TFS程序集,但它始终返回Unknown:
private ArtifactSpec GetProcessTemplateVersionSpec(string projectUri)
{
var commonService = this.context.GetService<CommonStructureService>();
Guid guid = commonService.GetProject(this.context, projectUri).ToProjectReference().Id;
return new ArtifactSpec(ArtifactKinds.ProcessTemplate, guid.ToByteArray(), 0);
}
public ProcessTemplateVersion GetCurrentProjectProcessVersion(Uri projectUri)
{
return this.GetProjectProcessVersion(projectUri.AbsoluteUri, ProcessTemplateVersionPropertyNames.CurrentVersion);
}
public ProcessTemplateVersion GetCreationProjectProcessVersion(Uri projectUri)
{
return this.GetProjectProcessVersion(projectUri.AbsoluteUri, ProcessTemplateVersionPropertyNames.CreationVersion);
}
private ProcessTemplateVersion GetProjectProcessVersion(string projectUri, string versionPropertyName)
{
ArtifactSpec processTemplateVersionSpec = GetProcessTemplateVersionSpec(projectUri);
ProcessTemplateVersion unknown = ProcessTemplateVersion.Unknown;
using (TeamFoundationDataReader reader = context.GetService<TeamFoundationPropertyService>().GetProperties(context, processTemplateVersionSpec, new string[] { versionPropertyName }))
{
foreach (ArtifactPropertyValue value2 in reader)
{
foreach (PropertyValue value3 in value2.PropertyValues)
{
return TeamFoundationSerializationUtility.Deserialize<ProcessTemplateVersion>(value3.Value as string);
}
return unknown;
}
return unknown;
}
}
更糟糕的是,我也希望能够从客户端对象模型中做到这一点,但这看起来更难。
答案 0 :(得分:1)
与微软产品团队I&#39协商后,M伤心地报告,这一特性目前仅由Visual Studio Online和该数值甚至没有存储在内部部署实例支持
。Rene van Osnabrugge正在努力复制这些价值and place them in the "standard" project properties。
将以下内容放在每个流程模板的Classification.xml中:
<properties>
<property name="MSPROJ" value="Classification\FieldMapping.xml" isFile="true" />
<property name="Process Template" value="Microsoft Visual Studio Scrum 2.2" />
<property name="Create Version" value="Custom Text is allowed here" />
<property name="Current Version" value="Custom Text is allowed here" />
</properties>
然后使用此代码阅读:
string uri = @"http://myServer:8080/tfs/defaultcollection";
string teamProjectName = "myTeamProject";
// Get the team project
var tpc = new TfsTeamProjectCollection(new Uri(uri));
tpc.Authenticate();
var ics = tpc.GetService<ICommonStructureService>();
var teamProject = ics.GetProjectFromName(teamProjectName);
// Read the properties
string projectName = string.Empty;
string projectState = string.Empty;
int templateId = 0;
ProjectProperty[] projectProperties = null;
ics.GetProjectProperties(teamProject.Uri, out projectName, out projectState, out templateId, out projectProperties);
// Return the properties
string processtemplate = projectProperties.Where(p => (p.Name == "Process Template")).Select(p => p.Value).FirstOrDefault();
string currentVersion = projectProperties.Where(p => (p.Name == "Current version")).Select(p => p.Value).FirstOrDefault();
string createVersion = projectProperties.Where(p => (p.Name == "Create version")).Select(p => p.Value).FirstOrDefault();
//Update the properties
projectProperties.Where(p => (p.Name == "Current version")).First().Value = "MS Scrum 2.2 - Custom 2.3";
ics.UpdateProjectProperties(teamProject.Uri, projectState, projectProperties);