我需要一些SQL查询的帮助,它将返回一个构建定义列表,其中包含特定的自定义参数。
我遇到了这个问题,但是我有点难以弄清楚如何深入挖掘。
;WITH XMLNAMESPACES('clr-namespace:Microsoft.TeamFoundation.Build.Workflow.Activities;assembly=Microsoft.TeamFoundation.Build.Workflow' AS mtbwa,
DEFAULT 'clr-namespace:System.Collections.Generic;assembly=mscorlib'),
q AS (
SELECT CAST(bd.ProcessParameters AS XML) p
FROM dbo.tbl_BuildDefinition bd
)
SELECT
X.Doc.query('mtbwa:BuildSettings') AS 'Node',
X.Doc.value('(mtbwa:BuildSettings/@ProjectsToBuild)[1]', 'VARCHAR(100)') AS 'ProjectsToBuild'
FROM q
CROSS APPLY p.nodes('/Dictionary') AS X(Doc)
以下是此查询返回的XML示例:
<Dictionary x:TypeArguments="x:String, x:Object" xmlns="clr-namespace:System.Collections.Generic;assembly=mscorlib" xmlns:mtbwa="clr-namespace:Microsoft.TeamFoundation.Build.Workflow.Activities;assembly=Microsoft.TeamFoundation.Build.Workflow" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<mtbwa:BuildSettings x:Key="BuildSettings" ProjectsToBuild="$/ACME/Dev/v1.0.0/Source/ACME/ACME.sln">
<mtbwa:BuildSettings.PlatformConfigurations>
<mtbwa:PlatformConfigurationList Capacity="1">
<mtbwa:PlatformConfiguration Configuration="ACMS Website" Platform="Any CPU" />
</mtbwa:PlatformConfigurationList>
</mtbwa:BuildSettings.PlatformConfigurations>
</mtbwa:BuildSettings>
<mtbwa:TestSpecList x:Key="TestSpecs" Capacity="1">
<mtbwa:TestAssemblySpec MSTestCommandLineArgs="{x:Null}" TestSettingsFileName="{x:Null}" AssemblyFileSpec="**\*test*.dll" CategoryFilter="!CodedUITest" />
</mtbwa:TestSpecList>
<mtbwa:SourceAndSymbolServerSettings x:Key="SourceAndSymbolServerSettings" SymbolStorePath="\\ACME.com\dfs\USA\AppDev\TeamBuild\Symbols" />
<mtbwa:AgentSettings x:Key="AgentSettings" MaxWaitTime="04:00:00" Name="*" Tags="" />
<x:Boolean x:Key="SCA">False</x:Boolean>
<x:String x:Key="SSCProjectVersion">ACME v1.0.0</x:String>
</Dictionary>
我正在尝试访问返回的XML的<x:Boolean x:Key="SCA">False</x:Boolean>
部分。关于如何实现这一目标的任何想法总是受到赞赏。
解
信用证转到jessehouwing的建议。
TfsTeamProjectCollection server = new TfsTeamProjectCollection(new Uri("http://acmetfs:8080/tfs"));
server.EnsureAuthenticated();
IBuildServer build = (IBuildServer)server.GetService(typeof(IBuildServer));
IBuildDefinition buildDefinition = build.GetBuildDefinition("ACME", "ACME_v1.0.0");
object argumentValue;
if (WorkflowHelpers.DeserializeProcessParameters(buildDefinition.ProcessParameters).TryGetValue("SCA", out argumentValue))
{
Console.WriteLine(argumentValue);
}
答案 0 :(得分:2)
警告
不建议直接查询TFS操作数据存储区,这些字段的内容可能会在不同版本甚至修补程序之间发生变化,恕不另行通知。正式的方法是使用客户端对象模型。您不小心对数据进行的任何更改都会使您的服务器处于不受支持的状态。
TFS客户端对象模型提供了相对easy API to query build definitions。从那里,您可以使用标准的.NET XML类(Linq-2-XML或标准XPathNavigator)快速获取您所需的信息。您正在寻找的参数甚至可能是stored in the build metadata。
这将导致以下代码(由OP提供):
TfsTeamProjectCollection server = new TfsTeamProjectCollection(new Uri("http://acmetfs:8080/tfs"));
server.EnsureAuthenticated();
IBuildServer build = (IBuildServer)server.GetService(typeof(IBuildServer));
IBuildDefinition buildDefinition = build.GetBuildDefinition("ACME", "ACME_v1.0.0");
object argumentValue;
if (WorkflowHelpers.DeserializeProcessParameters(buildDefinition.ProcessParameters).TryGetValue("SCA", out argumentValue))
{
Console.WriteLine(argumentValue);
}