【问题标题】:'AssemblyInfoFileMask' is not declared. It may be inaccessible due to its protection level未声明“AssemblyInfoFileMask”。由于其保护级别,它可能无法访问
【发布时间】:2013-04-15 16:50:19
【问题描述】:

我正在创建一个自定义构建 tfs 活动以在 azure 持续集成中使用。

我使用了这个博客的代码: 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 它在同一个类上,并没有在蓝色图标中显示错误。

我也会把代码贴在这里:

[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";
        }
    }
}

【问题讨论】:

标签: c# azure msbuild workflow-foundation-4


【解决方案1】:

蓝色感叹号表示您正在尝试将名为AssemblyInfoFileMaskArgument 的值传递给名为AssemblyInfoFileMask 的活动上的Property

您需要自己声明一个参数或变量以传递给您的活动。

如果您希望能够在构建定义中设置AssemblyInfoFileMask,则需要将其声明为参数。

查看此更新版本的图像,您将看到声明它的位置:

声明参数后,您需要找到 MetaData 集合参数并将其添加到那里。详情请见this post

如果您不需要在构建定义中设置它(它将对所有构建保持不变),那么只需添加一个 Variable 并将其值设置为您需要的模式。

【讨论】:

猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多