Can I access the MsBuildWorkspace from within a MsBuild Task class?

送分小仙女□ 提交于 2019-12-02 06:35:51

问题


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

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

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.


回答1:


I suspect that this is the purpose of MsBuildWorkspace

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

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.

You could create your own MsBuildWorkspace from the project file.



来源:https://stackoverflow.com/questions/27948207/can-i-access-the-msbuildworkspace-from-within-a-msbuild-task-class

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!