如何从 TFS 构建中的任务获取属性?

发布于 2024-08-04 06:33:52 字数 969 浏览 6 评论 0原文

我在 TFS 构建中创建了一个自定义任务来检查项目的 GlobalAssemblyInfo.cs 文件,以便提取一个属性(确切地说是 AssemblyInformationalVersion),以便在命名我在构建中创建的 zip 文件时使用它的值。

<UsingTask TaskName="GetAssemblyInformationalVersion.GetAssemblyInformationalVersionTask"
         AssemblyFile="$(MSBuildExtensionsPath)\GetAssemblyInformationalVersion.dll" />

我的 DLL 的 .cs 文件具有以下两个属性:

[Required]
public String InfoFile { get; set; }
public String InfoVersion { get; set; }

这是我对任务的调用:

<GetAssemblyInformationalVersionTask InfoFile="$(Path to file)\GlobalAssemblyInfo.cs" />

我的目的是通过属性 InfoFile 传入程序集信息文件,以便我可以找到我想要的内容(我的 C# 代码就是这样做的)和将其设置为属性 InfoVersion 以便我通过将其作为任务运行来在 TFS 中引用。原则上,我将使用 InfoVersion 属性来命名我的 zip 文件。例如,

"Package.$(some form of reference to InfoVersion).zip"

但是,我一直无法找到实际完成此任务的方法。

我的问题是:如何在任务中调用我的属性的 get 部分?看起来这应该很容易,因为我在网上没有找到任何关于此类事情的文章,但任何帮助将不胜感激。

I made a custom task in my TFS build to examine my project's GlobalAssemblyInfo.cs file in order to extract an attribute (AssemblyInformationalVersion to be exact) in order to use its value in naming a zip file that I make with the build.

<UsingTask TaskName="GetAssemblyInformationalVersion.GetAssemblyInformationalVersionTask"
         AssemblyFile="$(MSBuildExtensionsPath)\GetAssemblyInformationalVersion.dll" />

The .cs file for my DLL has these two properties:

[Required]
public String InfoFile { get; set; }
public String InfoVersion { get; set; }

Here is my call to my task:

<GetAssemblyInformationalVersionTask InfoFile="$(Path to file)\GlobalAssemblyInfo.cs" />

My intention is to pass in the assembly info file through the property InfoFile so that I can find what I want (which my C# code does) and set it to the property InfoVersion for me to reference in TFS by running it as a task. In principle, I would use the property InfoVersion to use in naming my zip file. For example,

"Package.$(some form of reference to InfoVersion).zip"

However, I have not been able to find a way to actually accomplish this.

My question is: How can I invoke the get part of my property in my task? It seems like it should be easy, since I have not found anything written about this sort of thing online, but any help will be much appreciated.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

儭儭莪哋寶赑 2024-08-11 06:33:52

您的自定义任务 GetAssemblyInformationVersionTask 需要有一个 ITaskItem 类型的属性,该属性用 [Output] 属性修饰。

public class GetAssemblyInformationVersionTask
{
    [Output]
    public ITaskItem Version { get; set; }

    public override bool Execute()
    {
      // code to set Version 
      return true;
    }
}

然后您将能够像这样使用它:

<GetAssemblyInformationVersionTask InfoFile="$(Path to file)\GlobalAssemblyInfo.cs">
        <Output TaskParameter="Version" ItemName="AssemblyVersion" />
 </GetAssemblyInformationVersionTask>

AssemblyVersion 将是包含任务的 Version 属性值的项变量。

如果您还没有看过,MSDN 可靠构建的最佳实践,第 2 部分< /a> 涉及输出参数的主题。我会看看是否无法在网上找到更好的示例。

Thomas Ardal 在自定义任务中提供了另一个很好的 [输出] 示例 此处

HTH,

Z

Your custom task, GetAssemblyInformationVersionTask, will need to have a property on it of type ITaskItem that is decorated with the [Output] attribute.

public class GetAssemblyInformationVersionTask
{
    [Output]
    public ITaskItem Version { get; set; }

    public override bool Execute()
    {
      // code to set Version 
      return true;
    }
}

Then you will be able to use it like so:

<GetAssemblyInformationVersionTask InfoFile="$(Path to file)\GlobalAssemblyInfo.cs">
        <Output TaskParameter="Version" ItemName="AssemblyVersion" />
 </GetAssemblyInformationVersionTask>

AssemblyVersion will be the item variable that will contain the value of the Version property of your task.

If you've not seen it, MSDN Best Practices for Reliable Builds, Part 2 touches on the subject of output parameters. I'll see if I can't find better examples online.

Thomas Ardal has another good sample of [Output] in a custom task here.

HTH,

Z

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文