TFS 不加载自定义程序集

标签 tfs process build assemblies

我在尝试让我的构建 Controller /代理从我的构建过程模板中使用的引用中获取自定义程序集时遇到问题。

我已经在多个博客中广泛阅读了这个问题,但不幸的是我一直无法解决这个问题:

TFS Build Error Log ]

我可以确认以下内容:

  1. 没有更新的 TFS 2012 Visual Studio 2013,更新 1(创建 事件并升级构建过程模板)

  2. 一个构建 Controller 与多个代理

  3. TFS 程序集在源代码管理中 checkin

Custom Assembly Checked In]

在重新启动服务的构建 Controller 中设置了正确的路径: [Build Controller Settings

按照这些博客中使用的指南,自定义事件在模板中正确解析:

http://www.ewaldhofman.nl/post/2010/04/29/Customize-Team-Build-2010-e28093-Part-4-Create-your-own-activity.aspx

http://blogs.msdn.com/b/jimlamb/archive/2010/02/12/how-to-create-a-custom-workflow-activity-for-tfs-build-2010.aspx

Build Process Template - Custom Activity Resolving Correctly (assembly updater)

我可以在构建过程模板的 XAML 中查看引用,它看起来很好,没有验证错误,我的代码事件似乎已正确实现。

代码如下:

using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Activities;
using System.Text.RegularExpressions;
using Microsoft.TeamFoundation.Build.Client;
using Microsoft.TeamFoundation.VersionControl.Client;

namespace FireWatch.TFS
{
    [BuildActivity(HostEnvironmentOption.Agent)]
    public sealed class AssemblyUpdater : CodeActivity
    {
        #region Static Methods
        #endregion   

        #region Property Variables
        #endregion

        #region Constants and Read-Onlys
        private const string ASSEMBLY_VERSION_REG_EX = @"\(""\d+\.\d+\.\d+\.\d+""\)";
        private const string ATTRIBUTE_REG_EX = "AssemblyVersion";
        #endregion

        #region Accessors

        [RequiredArgument]
        public InArgument<int> Major { get; set; }
        [RequiredArgument]
        public InArgument<int> Minor { get; set; }
        [RequiredArgument]
        public InArgument<int> Build { get; set; }
        [RequiredArgument]
        public InArgument<Workspace> Workspace { get; set; }

        #endregion

        #region Encapsulation

        private void UpdateAssemblyInfo(IEnumerable<string> assemblyInfos, int major, int minor, int build)
        {
            foreach (string myAssemblyInfo in assemblyInfos)
            {
                string myFileText = File.Exists(myAssemblyInfo) ? File.ReadAllText(myAssemblyInfo) : string.Empty;

                if (myFileText != string.Empty)
                {
                    Regex myRegex = new Regex(ATTRIBUTE_REG_EX + ASSEMBLY_VERSION_REG_EX);
                    Match myMatch = myRegex.Match(myFileText);

                    if (myMatch.Success)
                    {
                        string myVersionNumber = myMatch.Value.Substring(ATTRIBUTE_REG_EX.Length + 2,
                                                 myMatch.Value.Length - ATTRIBUTE_REG_EX.Length - 4);

                        Version myCurrentVersion = new Version(myVersionNumber);
                        Version myNewVersion = new Version(major, minor, build, (myCurrentVersion.Revision + 1));

                        string myUpdatedAssemblyText = myRegex.Replace(myFileText, ATTRIBUTE_REG_EX + "(\"" + myNewVersion + "\")");

                        File.WriteAllText(myAssemblyInfo, myUpdatedAssemblyText);
                    }
                }
            }
        }

        private void CheckOut(Workspace workspace, IList<string> assemblyInfos)
        {
            if (workspace != null && assemblyInfos != null && assemblyInfos.Any())
            {
                workspace.PendEdit(assemblyInfos.ToArray());
            }
        }

        private IEnumerable<string> GetRelevantAssemblyInfos(Workspace workspace)
        {
            IList<string> myReturn = new List<string>();

            PendingChange[] myPendingChanges = workspace.GetPendingChanges();

            foreach (PendingChange myPendingChange in myPendingChanges)
            {
                string myPath = AssemblyInfoPresent(myPendingChange);

                if (!string.IsNullOrEmpty(myPath))
                {
                    myReturn.Add(myPath);
                }
            }

            return myReturn;
        }

        private string AssemblyInfoPresent(PendingChange pendingChange)
        {
            string myReturn = string.Empty;

            if (pendingChange != null)
            {
                string myParentDirectory = pendingChange.LocalItem;
                string myParentLevelAssemblyInfo = myParentDirectory + @"\AssemblyInfo.cs";

                string myPropertiesDirectory = pendingChange.LocalItem + @"\Properties";
                string myPropertiesLevelAssemblyInfo = myParentDirectory + @"\Properties\AssemblyInfo.cs";

                if (Directory.Exists(myPropertiesDirectory) && File.Exists(myPropertiesLevelAssemblyInfo))
                {
                    myReturn = myPropertiesLevelAssemblyInfo;
                }
                else if (Directory.Exists(myParentDirectory) && File.Exists(myParentLevelAssemblyInfo))
                {
                    myReturn = myParentLevelAssemblyInfo;
                }
            }

            return myReturn;
        }

        #endregion

        #region CodeActivity Members

        protected override void Execute(CodeActivityContext context)
        {
            int myMajor = context.GetValue(this.Major);
            int myMinor = context.GetValue(this.Minor);
            int myBuild = context.GetValue(this.Build);
            Workspace myWorkspace = context.GetValue(this.Workspace);

            IList<string> myAssemblyInfos = GetRelevantAssemblyInfos(myWorkspace).Distinct().ToList();

            if (myAssemblyInfos.Any())
            {
                CheckOut(myWorkspace, myAssemblyInfos);
                UpdateAssemblyInfo(myAssemblyInfos, myMajor, myMinor, myBuild);
            }
        }

        #endregion
    }
}

最佳答案

你重启机器了吗?尝试清除构建机器上的缓存

C:\Users\BUILDACCOUNT\AppData\Local\Temp\BuildController\2.0\Assemblies

C:\Users\BUILDACCOUNT\AppData\Local\Temp\BuildAgent\BUILDAGENTNO\Assemblies

任何一种方式都应该强制构建 Controller 下载最新的程序集

关于TFS 不加载自定义程序集,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25619671/

相关文章:

build - 如何从 Jenkins 的另一份工作中提升特定的内部版本号?

c++ - 在 Visual Studio 中,如果组件已过时,如何强制构建?

java - 使用 Maven 构建 2 个具有不同源的 jar

git - 如何从 VisualStudio.com 的 Git 分支自动部署到 Azure?

没有分支的 TFS

c# - Chrome 驱动程序 : disconnected: unable to connect to renderer

java - Java 中的进程——它们同时工作吗?

c# - 进程 WaitForExit() 永远不会结束(cmd 打开文件)

linux - 检索进程曾经在 linux 中打开的所有文件描述符(文件)的列表

c# - 如何使用 Team Foundation Server 对象模型获取可编写脚本的构建定义?