roslyn: Unable to create an Analyzer targeting Roslyn 2.0

Version Used: Microsoft Visual Studio Enterprise 2017 VisualStudio/15.0.0+26228.10

Steps to Reproduce:

  1. Create a new Analyzer project from the “Analyzer with Code Fix (NuGet + VSIX)” template
  2. Notice that the Analyzer builds against Roslyn 1.0.1
  3. Attempt to upgrade all NuGet package.

Expected Behavior:

  • The Analyzer is now built against Roslyn 2.0

Actual Behavior:

An error message:

Could not install package ‘Microsoft.CodeAnalysis.Common 2.0.0’. You are trying to install this package into a project that targets ‘.NETPortable,Version=v4.5,Profile=Profile7’, but the package does not contain any assembly references or content files that are compatible with that framework. For more information, contact the package author.

It seems like this is because Microsoft.CodeAnalysis.Common is now only built for .NET Standard 1.3. If I manually reference this assembly from my existing analyzer, I get a Code Analysis error:

MSBUILD : error : CA0001 : Could not find type ‘System.Runtime.CompilerServices.ConditionalWeakTable`2’ in assembly ‘Microsoft.CodeAnalysis, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35’.

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Reactions: 2
  • Comments: 24 (17 by maintainers)

Commits related to this issue

Most upvoted comments

It has been a few months, @jmarolf, is there a issue tracking the progress of updating the templates that come in the .NET Compiler Platform SDK that I can follow? I just downloaded the SDK and the template in Visual Studio 2017 Update 2 still generates a 1.0.1 Roslyn project using a PCL library.

I tried the suggestions, but with the netstandard project format I’m having trouble using an external dependency (JSON.NET). Since PackageReferences are not copied to the bin directory, I cannot include them in the nuget-package. If they are not included in the nuget analyzers folder, VS will complain of course.

Is there a way to force the referenced dll to be placed into the output directory so that they can be included?

does this imply that both the workaround and the solution are that Analyzers for 2.0/C#7/etc. must now be .NET Standard 1.3 libraries instead of PCL libraries?

@yaakov-h yes netdstandard has a much larger surface area than PCLs in terms of APIs. You cannot reference a netstandard library from a PCL (though the reverse is possible).