简体   繁体   English

TFS工作流MSBuild活动项目位置

[英]TFS Workflow MSBuild Activity Project Location

I like how BuildProcessTemplates and the Custom Assemblies folder automatically syncs build scripts onto the build controller/agent. 我喜欢BuildProcessTemplates和“自定义装配体”文件夹如何自动将构建脚本同步到构建控制器/代理上。 I've written custom activities in C# and understand how to add an import so I can use the types in those assemblies. 我已经用C#编写了自定义活动,并了解了如何添加导入,以便可以在那些程序集中使用这些类型。

I also see how it's possible to use an MSBuild file via the MSBuild activity. 我还将看到如何通过MSBuild活动使用MSBuild文件。 I also note that if I check an msbuild file (say foo.proj ) into the CustomAssemblies folder in source control that the msbuild shows up in the temp directory structure on the server along side my custom assemblies. 我还注意到,如果将msbuild文件(例如foo.proj)检入源代码管理中的CustomAssemblies文件夹中,则该msbuild将显示在服务器上的temp目录结构中,以及我的自定义程序集旁边。

So here's my question? 所以这是我的问题? How do I reference the location of foo.proj in the MSBuild activity's Project property? 如何在MSBuild活动的Project属性中引用foo.proj的位置? I've been searching for variables and such but can't seem to put it together. 我一直在寻找变量之类的东西,但似乎无法将它们放在一起。

I've found a way to do it using a custom code activity. 我找到了一种使用自定义代码活动的方法。 Basically I wire this up into the workflow as a variable initialization pattern and then later use it in my other activities. 基本上,我将其作为变量初始化模式连接到工作流中,然后在其他活动中使用它。 But I'd rather do it without the need for a custom assembly if possible. 但是如果可能的话,我宁愿不需要自定义程序集。

using System.IO;
using System.Activities;
using System.Reflection;
using Microsoft.TeamFoundation.Build.Client;

namespace BuildTasks.Activities
{

    [BuildActivity(HostEnvironmentOption.All)]
    public sealed class FindCustomAssembliesDirectory : CodeActivity
    {
        public OutArgument<string> CustomAssembliesDirectory { get; set; }

        protected override void Execute(CodeActivityContext context)
        {
            context.SetValue(CustomAssembliesDirectory, new FileInfo(Assembly.GetExecutingAssembly().Location).Directory.FullName);
        }
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM