问题
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