Tuesday, July 8, 2014

Why my Roslyn extension is not getting loaded?

Below is my experience when I started working with a Roslyn project which I got from my colleague. First thing

Is the Roslyn compiler enabled for the Visual Studio test instance?

Yes there is something called enabling Roslyn. As we know Roslyn is the new compiler. The Visual Studio can now support 2 compilers. Traditional and Roslyn. So how the Visual Studio knows, it needs to use Roslyn? 
The answer is the below command line argument which needs to be passed to Visual Studio process devenv.exe when its started.

/rootsuffix Roslyn

If we are building VSIX extension project, we can mention this command line argument in the project properties->debug tab. This will make sure the test Visual Studio instance will be using the Roslyn compiler.

If the visual studio test instance itself not starting when we run the extension project, make sure the below path is there in the Project properties->Debug -> Start external program text box.

<Drive>:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\IDE\devenv.exe

Is the VSIX extension actually loaded or there is any bug in my code?

First of all check whether the Visual studio test instance can start with Roslyn enabled. If yes, load a project in the test instance of Visual Studio. If so go back to parent Visual Studio where we write our extension code and look at Modules window.

Debug->Windows-Modules

If our assembly is listed there in indicate that the extension is loaded. Now we can go to next debugging step.

Why the VSIXManifest is copied to wrong Roslyn extensions folder

If we are not able to find our extension assembly in the modules window, it indicate that the Visual Studio is not able to locate our extension assembly. To understand this better we should understand how the Roslyn extension is working under the hood. When we press the run button on the Roslyn extension project from VS,

  • It is compiling the project and copying the dlls including the extension.VSIXManifest file to the below mentioned location
    • <Drive>:\Users\<name>\AppData\Local\Microsoft\VisualStudio\12.0Roslyn\Extensions
  • The above underlined folder name "12.0Roslyn" is controlled by a project property given below
    • <VSSDKTargetPlatformRegRootSuffix>Roslyn</VSSDKTargetPlatformRegRootSuffix>
If the property hold a wrong value, it may copy the compiled vsix extension to wrong folder and the Roslyn extension will not take effect when we load Visual Studio test instance.

Why my VSIX extension files are not getting copied to Roslyn extension folder

Sometimes we will be having proper value in the <VSSDKTargetPlatformRegRootSuffix> tag. But still the files may not be copied. That will be due to improper values in the below project properties.

<IncludeAssemblyInVSIXContainer> true </IncludeAssemblyInVSIXContainer>  
<IncludeDebugSymbolsInVSIXContainer> false </IncludeDebugSymbolsInVSIXContainer>
<IncludeDebugSymbolsInLocalVSIXDeployment>  false</IncludeDebugSymbolsInLocalVSIXDeployment>
<CopyBuildOutputToOutputDirectory>    true</CopyBuildOutputToOutputDirectory>
<CopyOutputSymbolsToOutputDirectory>    true </CopyOutputSymbolsToOutputDirectory>

Best solution is to remove all these properties so that it will take the default behavior and default will copy required dlls to extensions folder.

Can I change these VSIX project properties using the properties tab?

The answer is NO as the project properties tab don't have the UI to support these properties. There is already a bug raised to Microsoft.

Is there a real issue in my code?

If all these things are set properly and still our Roslyn VSIX extension is not working, there is something wrong in the code. Inspect the code for below scenarios.
  • Class level attributes.
  • The interfaces implemented 
  • Whether the SymbolKindsOfInterest property returns proper list?

More links


Happy debugging...

1 comment:

Blogger said...

If you want your ex-girlfriend or ex-boyfriend to come crawling back to you on their knees (even if they're dating somebody else now) you must watch this video
right away...

(VIDEO) Text Your Ex Back?