MSBuild 从自定义任务参数中获取 %(RecursiveDir) 指令
我正在通过继承基任务类来开发自定义 MSBuild 任务。我的任务调用在 Microsoft.Build.Tasks.dll 中声明的复制任务,并在进程中设置 DestinationFolder 属性。我的自定义任务有一个名为 DestinationFolder 的属性,声明为
public ITaskItem DestinationFolder { get; set; }
当从构建/项目文件调用此任务时,我可能会传入一个参数,例如
<MyTask DestinationFolder="C:\Development\Test\%(RecursiveDir)"
我遇到的问题是,当此任务执行时,DestinationFolder 属性似乎不知道 < code>%(RecursiveDir) 位,而似乎只是设置为 C:\Development\Test\Bin
。
此问题似乎表明此问题没有解决方法。确实是这样吗?我想知道是否可以将该属性声明为一个简单的字符串,然后动态创建一个 TaskItem 对象,并且 DestinationFolder 字符串是否包含特殊的 %(RecursiveDir)
指令,然后相应地设置 TaskItem 对象。
I'm developing a custom MSBuild task by inheriting from the base Task class. My task calls the Copy task declared in Microsoft.Build.Tasks.dll
setting the DestinationFolder property in the process. My custom task has a property called DestinationFolder declared as
public ITaskItem DestinationFolder { get; set; }
When calling this task from a build/project file I might pass in a parameter such as
<MyTask DestinationFolder="C:\Development\Test\%(RecursiveDir)"
the problem I have is that when this task executes, the DestinationFolder property seems to have no knowledge of the %(RecursiveDir)
bit, instead just seems to be set to C:\Development\Test\Bin
.
This question seems to suggest that there is no work-around for this problem. Is this definitely the case? I was wondering if it's possible to declare the property as a simple string then create a TaskItem object on the fly and if the DestinationFolder string contains the special %(RecursiveDir)
instruction to then set up the TaskItem object accordingly.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
链接的问题处理任务的输出参数,其中这个问题处理输入。这里的问题是您已将 DestinationFolder 声明为 ITaskItem,但您传递的是字符串。
您没有给出足够的示例让我准确地弄清楚您想要做什么,但假设您有一个名为“C:\Development\Test\Bin\SomeFile.txt”的文件,您可以定义一个项目在您的项目中,例如:
现在您的任务将可以访问该项目的所有元数据,并且 RecursiveDir 将包含“Bin\”。
The linked question deals with output parameters from a task, where this one deals with inputs. The problem here is that you've declared DestinationFolder as an ITaskItem, but you're passing in a string.
You haven't given enough of an example for me to figure out exactly what you're trying to do, but assuming you have a file called "C:\Development\Test\Bin\SomeFile.txt", you could define an item in your project like:
Now your task will have access to all of the item's metadata, and RecursiveDir will contain "Bin\".