Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TFS Not Loading Custom Assemblies

I am having problems trying to get my Build Controller/Agents to pick up on a custom assembly from the reference used in my Build Process Template.

I have read about this problem extensively across several blogs and unfortunately I have been unable to resolve this issue:

TFS Build Error Log]

I can confirm the following:

  1. TFS 2012 with no updates Visual Studio 2013, Update 1 (to create the activity and upgrade the build process template)

  2. One Build Controller with mutiple agents

  3. The TFS Assembly checked in and within source control

Custom Assembly Checked In]

The correct path is set within the build controller with the service restarted: [Build Controller Settings

The custom activity is resolving correctly within the template when following the guide lines used in these blogs:

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)

I can view the the reference within the XAML of the Build Process Template and it looks fine with no validation errors and my code activity appears to be implemented correctly.

Code below:

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
    }
}
like image 668
Slavvy Avatar asked Mar 25 '26 20:03

Slavvy


1 Answers

Have you restarted the machine? try clearing the cache on the build machine at

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

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

either way should force the build controller to download the latest assemblies

like image 173
Just TFS Avatar answered Mar 28 '26 14:03

Just TFS