我可以从MsBuild Task类中访问MsBuildWorkspace吗? [英] Can I access the MsBuildWorkspace from within a MsBuild Task class?

查看:72
本文介绍了我可以从MsBuild Task类中访问MsBuildWorkspace吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

据我了解,罗斯林介绍了工作区的概念. MsBuildWorkspace是Workspaces的一种实现.

As far as I understand, Roslyn have introduced the concept of Workspaces. One implementation of Workspaces is the MsBuildWorkspace.

我的问题是,我可以从定制构建任务中访问代表正在构建的项目的Roslyn工作区吗?

My question is, can I from within a custom build task access a Roslyn Workspace representing the project being built?

我怀疑这是MsBuildWorkspace的目的.如果是这样,我可以在自定义任务(源自Microsoft.Build.Utilities.Task)中通过Execute方法访问此工作空间吗?

I suspect that this is the purpose of MsBuildWorkspace. If so, can I access this workspace from the Execute method in my custom task (derived from Microsoft.Build.Utilities.Task)?

如果您想知道为什么,我需要遍历正在构建的项目的其他方面. 对我而言,仅访问任务的特定输入文件以生成输出是不够的.

In case you are wondering why, I need to traverse other aspects of the project being built. It is not enough for me to have access to the specific input file of the task to generate the output.

推荐答案

我怀疑这是MsBuildWorkspace的目的

I suspect that this is the purpose of MsBuildWorkspace


MsBuildWorkspace的重点是将MSBuild项目或解决方案解析到Roslyn工作区中.

No.
The point of MsBuildWorkspace is to parse an MSBuild project or solution into a Roslyn workspace.

MSBuild本身(实际上是运行MSBuild任务的对象)根本不使用Roslyn(它仅调用使用Roslyn实现的C#编译任务),因此没有现有的MsBuildWorkspace您可以获取.

MSBuild itself (which is what actually runs your MSBuild task) does not use Roslyn at all (it just invokes the C# compilation task, which is implemented using Roslyn), so there is no existing MsBuildWorkspace that you could fetch.

您可以从项目文件中创建自己的MsBuildWorkspace.

You could create your own MsBuildWorkspace from the project file.

这篇关于我可以从MsBuild Task类中访问MsBuildWorkspace吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆