1

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.

Community
  • 1
  • 1
PasTeK
  • 105
  • 4

2 Answers2

0

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

Community
  • 1
  • 1
JoshVarty
  • 9,066
  • 4
  • 52
  • 80
  • I did everything in the link, but i get new error. Cannot cast the underlying exported value of type 'Microsoft.VisualStudio.LanguageServices.RoslynVisualStudioWorkspace (ContractName="Microsoft.VisualStudio.LanguageServices.VisualStudioWorkspace")' to type 'Microsoft.VisualStudio.LanguageServices.VisualStudioWorkspace'. I don't really understand.. – PasTeK Jun 15 '14 at 16:03
  • That's a bizarre error and seems more related to MEF than Roslyn. They mention a similar problem here: http://stackoverflow.com/a/14320296/300908 – JoshVarty Jun 16 '14 at 08:12
  • I had Roslyn in all my solution's project. But I get always the same error "No exports were found that match the constraint: ContractName Microsoft.CodeAnalysis.Workspace RequiredTypeIdentity Microsoft.CodeAnalysis.Workspace" I work in VisualStudio and test my Editor VSPackage on VisualStudio with /rootSuffix Roslyn. Is it the good way? I don't really understand, I follow all your post, but got always an error. – PasTeK Jun 16 '14 at 09:44
  • I get the other error if I work on VisualStudio with /rootSuffix Roslyn and test my Editor VSPackage on VisualStudio with /rootSuffix Roslyn. – PasTeK Jun 16 '14 at 09:45
0

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.

PasTeK
  • 105
  • 4