Attach VsPackage to Roslyn Instance

2019-07-01 15:24发布

问题:

I'm trying to create a VsPackage that makes use of the Roslyn Language Services. Under the properties of my VsPackage, I've changed the command line arguments to:

/rootsuffix Roslyn

When running the project, the instance of Visual Studio that starts up is correctly using Roslyn. (I see [Roslyn] next to the names of .cs files I have open). However, my VsPackage is not deployed to this instance of Visual Studio.

I have opened up the SyntaxVisualizerExtension VsPackage that ships with Roslyn and compiled/run that. It correctly deploys to Visual Studio using Roslyn. I've looked through the project properties and references and nothing has stood out to me as missing.

The steps I'm taking are :

  1. File > New Project > Visual Studio Package
  2. Create with Tool Window
  3. Open Project properties, change /rootsuffix Exp to /rootsuffix Roslyn
  4. Add references to Roslyn .dlls
  5. Run project.

In theory, I could probably strip down the SyntaxVisualizerExtension Package, but I'd like to know the proper way to create a VsPackage for the Roslyn instance.

回答1:

There's no UI setting to control what the property is. Edit your project file in Notepad (or unload the project in VS and then right click and choose "edit"), and add this line:

<VSSDKTargetPlatformRegRootSuffix>Roslyn</VSSDKTargetPlatformRegRootSuffix>

into the appropriate PropertyGroup. Look in the projects created via any of the Roslyn templates for an example.