質問

私たちは、チームが新しい機能を追加しているのと同時に、Brown Fieldコードの大きな束をクリーンアップしようとしています。私たちは、変更されたコンパイラ/コード分析やその他の警告から変更され、新しいコードがクリーニングされますが、現在のソリューションのクリーンアップから始めるには多くの場合があります。

TFS 2010を使用しています。

だから以下は提案されました:

  • ビルド内の警告のリストをそのチェックインで変更されたコード行と比較するビルドアクティビティを書き込みます。
  • 警告が行番号を提供し、その行番号が変更された場合は、ビルドを失敗させます。

    私はこれがすべての新しい警告を見つけることはないと、コードの他の部分に紹介されたものはフラグが立てられないでしょうが、それは少なくとも何かです。

    提案された別の選択肢:

    • このビルドのリストに対して、前回の既知の良いビルドの警告のリストを比較します。新しい警告がある場合(ファイル名レベルでトラック)、ビルドを失敗させます。

      上記の機能を提供するかもしれない任意の既知の行動はありますか?

      コードカバレッジレポートに機能することができる類似のアクション?

役に立ちましたか?

解決

次の活動は、現在のビルドが最後のビルドとfalseが上がっている場合には、Laseを上回っている場合は警告が少ない場合は、trueだけを返します。 new 警告および/またはコード内の彼らの場所を持つプレゼントは明らかに優れていますが、これは面白い始まりになるかもしれません:

using System;
using System.Activities;
using Microsoft.TeamFoundation.Build.Client;
using Microsoft.TeamFoundation.Build.Workflow.Activities;

namespace CheckWarnings
{
    [BuildActivity(HostEnvironmentOption.Agent)]
    public sealed class CheckWarnings : CodeActivity<bool>
    {
        [RequiredArgument]
        public InArgument<IBuildDetail> CurrentBuild { get; set; }  //buildDetail
        public InArgument<string> Configuration { get; set; }       //platformConfiguration.Configuration
        public InArgument<string> Platform { get; set; }            //platformConfiguration.Platform


        protected override bool Execute(CodeActivityContext context)
        {
            IBuildDetail currentBuildDetail = context.GetValue(CurrentBuild);
            string currentConfiguration = context.GetValue(Configuration);
            string currentPlatform = context.GetValue(Platform);

            Uri lastKnownGoodBuildUri = currentBuildDetail.BuildDefinition.LastGoodBuildUri;
            IBuildDetail lastKnownGoodBuild = currentBuildDetail.BuildServer.GetBuild(lastKnownGoodBuildUri);

            int numOfCurrentWarnings = GetNumberOfWarnings(currentBuildDetail, currentConfiguration, currentPlatform);
            context.TrackBuildMessage("Current compile presents " + numOfCurrentWarnings + " warnings.", BuildMessageImportance.Normal);

            int numOfLastGoodBuildWarnings = GetNumberOfWarnings(lastKnownGoodBuild, currentConfiguration,
                                                                 currentPlatform);
            context.TrackBuildMessage("Equivalent last good build compile presents " + numOfLastGoodBuildWarnings + " warnings.", BuildMessageImportance.Normal);

            if (numOfLastGoodBuildWarnings < numOfCurrentWarnings)
            {
                return true;
            }
            return false;
        }

        private static int GetNumberOfWarnings(IBuildDetail buildDetail, string configuration, string platform)
        {
            var buildInformationNodes =
                buildDetail.Information.GetNodesByType("ConfigurationSummary");

            foreach (var buildInformationNode in buildInformationNodes)
            {
                string localPlatform, numOfWarnings;
                string localConfiguration = localPlatform = numOfWarnings = "";
                foreach (var field in buildInformationNode.Fields)
                {

                    if (field.Key == "Flavor")
                    {
                        localConfiguration = field.Value;
                    }
                    if (field.Key == "Platform")
                    {
                        localPlatform = field.Value;
                    }
                    if (field.Key == "TotalCompilationWarnings")
                    {
                        numOfWarnings = field.Value;
                    }
                }
                if(localConfiguration == configuration && localPlatform == platform)
                {
                    return Convert.ToInt32((numOfWarnings));
                }
            }
            return 0;
        }
    }
}
.

このアクティビティは例外処理を提供していないため、ビルド定義が複数のソリューションを作成する場合はさらに洗練されるべきであることに注意してください。buildDetailアクティビティの直後に配置する必要があります。

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top