简体   繁体   English

从.net 3.5以编程方式访问和更新tfs 2010构建参数

[英]accessing and updating tfs 2010 build parameters programmatically from .net 3.5

I am probably missing something basic here as this just doesn't seem to be working the way I expect. 我可能在这里错过了一些基本的东西,因为这似乎并没有按照我期望的方式工作。 I am not really ac# guy by day. 我并不是一个真正的熟人。

I have a tfs 2010 plugin that is watching ticket change events and filtering for the WIT changes to tickets that I want. 我有一个tfs 2010插件,可以监视票证更改事件并过滤所需的票证WIT更改。 This is all based on http://geekswithblogs.net/jakob/archive/2010/10/27/devleoping-and-debugging-server-side-event-handlers-in-tfs-2010.aspx 这全部基于http://geekswithblogs.net/jakob/archive/2010/10/27/devleoping-and-debugging-server-side-event-handlers-in-tfs-2010.aspx

I pull out all the necessary variables in the plugin and I need to pass this to the build engine, which will be actually pushing the build. 我在插件中提取了所有必需的变量,然后将其传递给构建引擎,该引擎实际上将推动构建。 The thing that is giving me the most grief here is that the parameters are pushed as an xaml string or a "dictionary and serialized it into a string". 让我最难过的是,这些参数以xaml字符串或“字典并将其序列化为字符串”的形式推送。 Now, there is a library Microsoft.TeamFoundation.Build.Workflow that does some handling of this but it seems to be for .net 4 and the tfs server is running in .net 2 and cannot bind it. 现在,有一个库Microsoft.TeamFoundation.Build.Workflow对此做了一些处理,但它似乎适用于.net 4,而tfs服务器正在.net 2中运行并且无法绑定它。 That method is discussed in the widely linked http://blogs.msdn.com/b/jpricket/archive/2010/03/25/tfs2010-queuing-a-build-from-code-with-custom-process-parameter-values.aspx but he just uses a method DeserialzeProcessParameters that I don't have access to. 在广泛链接的http://blogs.msdn.com/b/jpricket/archive/2010/03/25/tfs2010-queuing-a-build-from-code-with-custom-process-parameter-中讨论了该方法values.aspx,但他只是使用了我无权访问的DeserialzeProcessParameters方法。

I am just trying to update a few values and I can do this in a couple lines of powershell so I thought I would be able to address it myself but I am running into trouble. 我只是尝试更新一些值,并且可以在几行powershell中执行此操作,因此我认为自己可以解决此问题,但我遇到了麻烦。

The default Buildrequest.parameters for the build request looks like the below (w/ the /r/n converted to new lines. It can be parsed as the innerXml of an XmlDocument). 生成请求的默认Buildrequest.parameters如下所示(将/ r / n转换为新行。可以将其解析为XmlDocument的innerXml)。

If I have an xml doc like below, how, in c#, can I address and update the values for, say, RestoreDatabase? 如果我有如下所示的xml文档,如何在C#中如何寻址和更新RestoreDatabase的值?

<Dictionary x:TypeArguments="x:String, x:Object" xmlns="clr-namespace:System.Collections.Generic;assembly=mscorlib" xmlns:mtbw="clr-namespace:Microsoft.TeamFoundation.Build.Workflow;assembly=Microsoft.TeamFoundation.Build.Workflow" 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="$/EJTest/TFSServerEventHandler/TFSServerEventHandler.sln">
                            <mtbwa:BuildSettings.PlatformConfigurations>
                                            <mtbwa:PlatformConfigurationList Capacity="0" />
                            </mtbwa:BuildSettings.PlatformConfigurations>
            </mtbwa:BuildSettings>
            <mtbwa:TestSpecList x:Key="TestSpecs" Capacity="0" />
            <mtbwa:CodeAnalysisOption x:Key="RunCodeAnalysis">Never</mtbwa:CodeAnalysisOption>
            <x:Boolean x:Key="AssociateChangesetsAndWorkItems">False</x:Boolean>
            <x:Boolean x:Key="CreateWorkItem">False</x:Boolean>
            <x:Boolean x:Key="DropBuild">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>
            <mtbw:BuildVerbosity x:Key="Verbosity">Detailed</mtbw:BuildVerbosity>
            <x:String x:Key="BuildNumber">4.4.2.29</x:String>
            <x:String x:Key="BackupDatabase">yes</x:String>
            <x:String x:Key="RestoreDatabase">Yes</x:String>
            <x:String x:Key="OverwriteBackup">Yes</x:String>
            <x:String x:Key="UpgradeSoftware">No</x:String>
            <x:String x:Key="DeploymentTicket">654</x:String>
</Dictionary>

The x:string values are the ones I want to update and change. x:string值是我要更新和更改的值。

For what it's worth, the PS version 值得的是,PS版本

[xml]$a = Get-Content .\test.xml
$b = $a.Dictionary.string | where {$_.key -eq "CustomerData"}
$b."#text" = 'No'

Thanks for your time. 谢谢你的时间。

ok, i banged my way through it. 好吧,我撞了过去。 not sure it is the most efficient way but it seems to work: 不确定这是最有效的方法,但它似乎可以工作:

        XmlDocument xDoc = new XmlDocument();
        xDoc.Load("test.xml");
        XmlNodeList elemList = xDoc.GetElementsByTagName("x:String");

        foreach (XmlNode xNode in elemList)
        {
            switch (xNode.Attributes[0].Value)
            {
                case "BuildNumber":
                    Console.WriteLine(xNode.Attributes[0].Value + " = " + xNode.InnerText);
                    xNode.InnerText = "4.3w2432.2";
                    break;

                case "BackupDatabase":
                    Console.WriteLine(xNode.Attributes[0].Value + " = " + xNode.InnerText);
                    xNode.InnerText = "4.3w2432.2";
                    break;

                case "RestoreDatabase":
                    Console.WriteLine(xNode.Attributes[0].Value + " = " + xNode.InnerText);
                    xNode.InnerText = "4.3w2432.2";
                    break;

                case "OverwriteBackup":
                    Console.WriteLine(xNode.Attributes[0].Value + " = " + xNode.InnerText);
                    xNode.InnerText = "4.3w2432.2";
                    break;

                case "UpgradeSoftware":
                    Console.WriteLine(xNode.Attributes[0].Value + " = " + xNode.InnerText);
                    xNode.InnerText = "4.3w2432.2";
                    break;

                case "DeploymentTicket":
                    Console.WriteLine(xNode.Attributes[0].Value + " = " + xNode.InnerText);
                    xNode.InnerText = "4.3w2432.2";
                    break;


            }

Since the Build environment dll is a .net 4.0 dll and your current dll you either need to use a adapter (http://code.msdn.microsoft.com/windowsdesktop/Using-a-NET-4-Based-DLL-bb141db3, this way you can start the build normaly using the object model) or kick of a build using tfsbuild.exe from code. 由于生成环境dll是.net 4.0 dll,而当前的dll是您需要使用适配器的(http://code.msdn.microsoft.com/windowsdesktop/Using-a-NET-4-Based-DLL-bb141db3 ,这样您就可以使用对象模型正常启动构建)或通过代码中的tfsbuild.exe启动构建。 This is because your values aren't serialized otherwise. 这是因为您的值不会被序列化。

Since you listed the same functionality in powershell, I thought you where already in powershell. 由于您在Powershell中列出了相同的功能,因此我想您已经在Powershell中。 If that was the case you could have just start the tfsbuild.exe command line to kick of a build. 如果是这种情况,您可能只需启动tfsbuild.exe命令行即可启动构建。 this is however not the case. 但是事实并非如此。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM