How to get workspace from VisualStudioWorkspace?

我怕爱的太早我们不能终老 提交于 2019-12-24 06:35:09

问题


I'm trying to get Workspace from visual studio to use it with roslyn.

I found some topics about that, like this one : How to get reference to 'Roslyn' Workspace object from IVsSolution?

I wrote exactly the same code :

var componentModel = (IComponentModel)Microsoft.VisualStudio.Shell.Package.GetGlobalService(typeof(SComponentModel));
var workspace = componentModel.GetService<Microsoft.VisualStudio.LanguageServices.VisualStudioWorkspace>();

But I get this error...

"No exports were found that match the constraint: ContractName Microsoft.CodeAnalysis.Workspace RequiredTypeIdentity Microsoft.CodeAnalysis.Workspace"

I don't really understand what's the problem.


回答1:


Sounds like the Roslyn language services aren't running in the experimental version of Visual Studio. You have to download the end user preview from here: http://msdn.microsoft.com/en-us/vstudio/roslyn.aspx

That includes a program called "Install Roslyn Preview into Roslyn Experimental Hive" that you must run.

The VSPackage you're running must have the command line arguments "/rootSuffix Roslyn". You can set this by right clicking the project in Solution Explorer, clicking properties and navigating to "Debug".

Lastly, you must include an extra property in the .csproj XML file:

<VSSDKTargetPlatformRegRootSuffix>Roslyn</VSSDKTargetPlatformRegRootSuffix>

There's an explanation in a previous question of mine: Attach VsPackage to Roslyn Instance




回答2:


Problem solved.

My problem came from conflict between assembly.

In my project, there was Roslyn assembly version 0.7.0 but during test, at Runtime, it was Roslyn version 0.6.0.

So in Visual Studio /rootSuffix Roslyn With <VSSDKTargetPlatformRegRootSuffix>Roslyn</VSSDKTargetPlatformRegRootSuffix> in each project using Roslyn. All is ok.



来源:https://stackoverflow.com/questions/24200125/how-to-get-workspace-from-visualstudioworkspace

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