2013-04-15 55 views
3

我正在創建一個自定義構建tfs活動,以在Azure持續集成中使用。'AssemblyInfoFileMask'未被聲明。由於它的保護級別,它可能無法訪問

我從這個博客中使用的代碼: http://www.ewaldhofman.nl/post/2010/06/01/Customize-Team-Build-2010-e28093-Part-10-Include-Version-Number-in-the-Build-Number.aspx

正如你可以看到AssemblyInfoFileMask在公共下面的代碼。 也請檢查截圖,看看我的意思,BuildDetail它在同一類,並沒有告訴我藍色圖標的錯誤。

enter image description here

我將其粘貼在這裏的代碼,以及:

[BuildActivity(HostEnvironmentOption.Controller)] 
    public sealed class GetAssemblyVersion : CodeActivity<string> 
    { 
     [RequiredArgument] 
     public InArgument<string> AssemblyInfoFileMask { get; set; } 

     [RequiredArgument] 
     public InArgument<IBuildDetail> BuildDetail { get; set; } 

     protected override string Execute(CodeActivityContext context) 
     { 
      // Obtain the runtime value of the input arguments 
      string assemblyInfoFileMask = context.GetValue(this.AssemblyInfoFileMask); 
      IBuildDetail buildDetail = context.GetValue(this.BuildDetail); 

      var workspace = buildDetail.BuildDefinition.Workspace; 
      var vc = buildDetail.BuildServer.TeamProjectCollection.GetService<VersionControlServer>(); 

      string attribute = "AssemblyFileVersion"; 

      // Define the regular expression to find (which is for example 'AssemblyFileVersion("1.0.0.0")') 
      Regex regex = new Regex(attribute + @"\(""\d+\.\d+\.\d+\.\d+""\)"); 

      // For every workspace folder (mapping) 
      foreach (var folder in workspace.Mappings) 
      { 
       // Get all files (recursively) that apply to the file mask 
       ItemSet itemSet = vc.GetItems(folder.ServerItem + "//" + assemblyInfoFileMask, RecursionType.Full); 
       foreach (Item item in itemSet.Items) 
       { 
        context.TrackBuildMessage(string.Format("Download {0}", item.ServerItem)); 

        // Download the file 
        string localFile = Path.GetTempFileName(); 
        item.DownloadFile(localFile); 

        // Read the text from the AssemblyInfo file 
        string text = File.ReadAllText(localFile); 
        // Search for the first occurrence of the version attribute 
        Match match = regex.Match(text); 
        // When found 
        if (match.Success) 
        { 
         // Retrieve the version number 
         string versionNumber = match.Value.Substring(attribute.Length + 2, match.Value.Length - attribute.Length - 4); 
         Version version = new Version(versionNumber); 
         // Increase the build number -> this will be the new version number for the build 
         Version newVersion = new Version(version.Major, version.Minor, version.Build + 1, version.Revision); 

         context.TrackBuildMessage(string.Format("Version found {0}", newVersion)); 

         return newVersion.ToString(); 
        } 
       } 
      } 

      return "No version found"; 
     } 
    } 
} 
+0

誰說它在那裏?你沒有告訴我們什麼變量在[Activity的變量和參數中]範圍內。(http://i.stack.imgur.com/9IdrX.png)這個變量很可能不存在,被稱爲現在還有其他的東西,或者是另一種類型。 – Will

回答

3

藍色感嘆號意味着你正嘗試將Variable/Argument稱爲AssemblyInfoFileMask的值傳遞給Property您活動名爲AssemblyInfoFileMask

您需要自己聲明一個參數或變量以傳遞給您的活動。

如果您希望能夠在您的構建定義中設置AssemblyInfoFileMask,那麼您需要將其聲明爲參數。

,你聲明它見你的形象的更新版本,您將看到:

Arguments

一旦你聲明的說法,你需要找到MetaData採集參數,並將其添加有太多。有關更多詳細信息,請參閱this post

如果您不需要將其設置爲構建定義(對於所有構建它將保持不變),那麼只需添加一個Variable並將其值設置爲您需要的模式。

+0

看起來像那個教程沒有很好解釋然後:( –

+0

也許你可以檢查這個問題,以及:) http://stackoverflow.com/questions/16031434/the-path-fullstacksampleapplication-is-not-a-file-type -invalidoperationexcep –

相關問題