简体   繁体   中英

How to get workspace from VisualStudioWorkspace?

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.

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM