Now that Visual Studio 2015 RC is fresh off the build machines and available for everyone, I’ve updated my Wintellect.Analyzers project (http://johnr.us/1bEO4h8) with full RC support. Go forth and add them to your project so you can get the benefit of advanced compiler analysis and code fixes. To add the analyzers, hit up your Package Manager Console with the following command:

  1. Install-Package Wintellect.Analyzers Prerelease

I guess you could go through the fancy new NuGet window in Visual Studio, but you want to be hard core and use PowerShell in VS!

If you’re interested in writing your own analyzers, as I have discussed previously, you’re immediately going to run into errors and warnings with projects based off the default Roslyn template when you try to install your analyzer masterpiece. Here’s what you’ll see:

Attempting to gather dependencies information for package ‘Analyzer1.1.0.0’ with respect to project targeting ‘.NETPortable, Version=v4.5, Profile=Profile7’
Attempting to resolve dependencies for package ‘Analyzer1.1.0.0’ with DependencyBehavior ‘Lowest’
Resolving actions to install package ‘Analyzer1.1.0.0’
Resolved actions to install package ‘Analyzer1.1.0.0’
Adding package ‘Analyzer1 1.0.0.0’ to folder ‘c:junkcodeAnalyzer1packages’
Added package ‘Analyzer1 1.0.0.0’ to folder ‘c:junkcodeAnalyzer1packages’
Added package ‘Analyzer1 1.0.0.0’ to ‘packages.config’
Executing script file ‘c:junkcodeAnalyzer1packagesAnalyzer1.1.0.0.0toolsinstall.ps1’
Get-ChildItem : Cannot find path ‘C:junkcodeAnalyzer1packagesAnalyzer1.1.0.0.0toolsanalyzersC#’ because it does not exist.
At C:junkcodeAnalyzer1packagesAnalyzer1.1.0.0.0toolsinstall.ps1:18 char:31
+ … alyzerFilePath in Get-ChildItem $languageAnalyzersPath -Filter *.dll)
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (C:junkcodeAn…lsanalyzersC#:String) [Get-ChildItem], ItemNotFoundException
+ FullyQualifiedErrorId : PathNotFound,Microsoft.PowerShell.Commands.GetChildItemCommand

Successfully installed ‘Analyzer1 1.0.0.0’ to Analyzer1.

When a developer is installing your analyzer NuGet package and you get all those errors, that’s not giving them a great sense of confidence. The good news is that it’s relatively easy to fix. Right now the Roslyn templates are not open sourced. I hope they will be before RTM so we can fix this issue. The good news is that it’s not too hard to fix it right now.

Analyzers can be language neutral, or specific to C# or VB. The template assumes you are writing a language neutral analyzer AND language specific analyzers, which is fine, but I’m willing to bet that you are writing a language specific analyzer.

When you open your analyzers .NUSPEC file, you’ll see the following in the files section:

<files>
    <file src=*.dll target=toolsanalyzers exclude=**Microsoft.CodeAnalysis.*;**System.Collections.Immutable.*;**System.Reflection.Metadata.* />
    <file src=tools*.ps1 target=tools />
</files>

The first file line is saying that your analyzer will be installed into <packages><your analyzer>toolsanalyzers and that’s where language neutral analyzers reside. If you are writing a C# specific analyzer, you want to change the file element to be the following:

<files>
    <file src=*.dll target=toolsanalyzersC# exclude=**Microsoft.CodeAnalysis.*;**System.Collections.Immutable.*;**System.Reflection.Metadata.* />
    <file src=tools*.ps1 target=tools />
</files>

For a VB specific analyzer, change the C# to VB and you are off to the races. That’s a pretty simple fix! Another alternative would be to change Install.ps1 and Uninstall.ps1 to do a Test-Path to see if there’s any language neutral or language specific analyzers.