gpt4 book ai didi

c# - TFS 2010 : Why is it not possible to deserialize a Dictionary with XamlWriter.Save 当我可以使用 XamlReader 进行反序列化时

转载 作者:太空狗 更新时间:2023-10-29 20:34:44 25 4
gpt4 key购买 nike

public static string GetXml(Dictionary<string, object> parameters)
{
return XamlWriter.Save(parameters);
}

上述语句返回一个NotSupportedException

奇怪的是我可以使用XamlReader 来序列化字典。

public static Dictionary<string, object> GetParameters(IBuildDetail buildDetail, string buildDefinition)
{
var tfsProject = buildDetail.BuildDefinition.TeamProject;
var buildServer = buildDetail.BuildServer;
var buildDef = buildServer.GetBuildDefinition(tfsProject, buildDefinition);
using (var stringReader = new StringReader(buildDef.ProcessParameters))
{
using (var xmlTextReader = new XmlTextReader(stringReader))
{
return (Dictionary<string, object>) XamlReader.Load(xmlTextReader);
}
}
}

XML:

<?xml version="1.0" ?>
<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 ProjectsToBuild="$/XXX/Product/Company.XXX.Common/Company.XXX.Common.Basic/Company.XXX.Common.Basic.csproj" x:Key="BuildSettings">

<mtbwa:BuildSettings.PlatformConfigurations>

<mtbwa:PlatformConfigurationList Capacity="4">

<mtbwa:PlatformConfiguration Configuration="DEMO" Platform="AnyCPU"/>

<mtbwa:PlatformConfiguration Configuration="Release" Platform="AnyCPU"/>

</mtbwa:PlatformConfigurationList>

</mtbwa:BuildSettings.PlatformConfigurations>

</mtbwa:BuildSettings>

<mtbwa:TestSpecList Capacity="0" x:Key="TestSpecs"/>

<x:String x:Key="BuildNumberFormat">
$(BuildDefinitionName) 6.0.0$(Rev:.r)
</x:String>

<mtbwa:CodeAnalysisOption x:Key="RunCodeAnalysis">
Never
</mtbwa:CodeAnalysisOption>

<mtbwa:AgentSettings MaxWaitTime="00:15:00" TagComparison="MatchExactly" Tags="" x:Key="AgentSettings"/>

<x:Boolean x:Key="AssociateChangesetsAndWorkItems">
False
</x:Boolean>

<x:Boolean x:Key="CreateWorkItem">
False
</x:Boolean>

<x:Boolean x:Key="PerformTestImpactAnalysis">
False
</x:Boolean>

<x:Boolean x:Key="CreateLabel">
False
</x:Boolean>

<x:Boolean x:Key="DisableTests">
True
</x:Boolean>

<x:Boolean x:Key="DoCheckinAssemblyInfoFiles">
True
</x:Boolean>

<x:String x:Key="AssemblyVersionPattern">
6.0.0.0
</x:String>

<x:String x:Key="AssemblyFileVersionPattern">
6.0.0.B
</x:String>

<x:Boolean x:Key="UseObfuscation">
True
</x:Boolean>

<x:String x:Key="ObfuscatorFilePath">
C:\Program Files (x86)\LogicNP Software\Crypto Obfuscator For .Net 2011 R3\co.exe
</x:String>

<x:String x:Key="ObfuscatorProjectFile">
$/XXX/Product/BuildProcess/Company.XXX.ZZZ.obproj
</x:String>

<x:String x:Key="ProjectPath">
$/XXX/Product/Company.XXX.Common
</x:String>

</Dictionary>

最佳答案

我用了JetBrains dotPeek了解 Microsoft 如何序列化和反序列化 Dictionary<string, object>适用于 TFS 2010 工作流。

他们使用反序列化: Microsoft.TeamFoundation.Build.Workflow.WorkflowHelpers.DeserializeProcessParameters(string parameterValues)

他们使用序列化: WorkflowHelpers.SerializeProcessParameters(IDictionary<string, object> parameterValues)

程序集:Microsoft.TeamFoundation.Build.Workflow.dll

我最初的问题是我试图添加 IBuildRequest.ProcessParameters排队构建之前的值。

private static void SetProcessParametersForSubBuild(IBuildRequest buildRequest, Dictionary<string, object> processParametersForSubBuild, IBuildDefinition buildDefinition)
{
var subBuildProcessParameters = WorkflowHelpers.DeserializeProcessParameters(buildDefinition.ProcessParameters);

if (processParametersForSubBuild.Any())
{
foreach (var processParameter in processParametersForSubBuild)
{
if (subBuildProcessParameters.ContainsKey(processParameter.Key))
{
subBuildProcessParameters[processParameter.Key] = processParameter.Value;
}
else
{
subBuildProcessParameters.Add(processParameter.Key, processParameter.Value);
}
}
buildRequest.ProcessParameters = WorkflowHelpers.SerializeProcessParameters(subBuildProcessParameters);
}
}

队列构建:

var queuedBuild = buildServer.QueueBuild(buildRequest);

关于c# - TFS 2010 : Why is it not possible to deserialize a Dictionary<string, object> with XamlWriter.Save 当我可以使用 XamlReader 进行反序列化时,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9581474/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com