我需要一些关于 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>
我正在尝试获取<x:Boolean x:Key="SCA">False</x:Boolean>
返回的 XML 的一部分。任何关于我如何实现这一点的想法都会受到赞赏。
解决方案
感谢 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);
}