nsubstitute / NSubstitute.Analyzers

Roslyn analysers for NSubstitute.
MIT License
30 stars 7 forks source link

NSubstitute.Analyzers.CSharp produces warnings about Microsoft.CodeAnalysis.CSharp in project, no analyzer output #77

Open erizzo opened 5 years ago

erizzo commented 5 years ago

Question I have an ordinary Test project in my solution, targeting .Net Framework 4.6.2. When I added a Nuget reference to NSubstitute.Analyzers.CSharp, I got several warnings like this:

An instance of analyzer NSubstitute.Analyzers.CSharp.DiagnosticAnalyzers.NonVirtualSetupWhenAnalyzer cannot be created from C:\Users\erizzo.nuget\packages\nsubstitute.analyzers.csharp\1.0.6\analyzers\dotnet\cs\NSubstitute.Analyzers.CSharp.dll : Could not load file or assembly 'Microsoft.CodeAnalysis.CSharp, Version=2.8.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The system cannot find the file specified..

I then tried adding Nuget reference to Microsoft.CodeAnalysis.CSharp (I tried both 2.8.0 and the latest stable version, 2.10.0), but it made no difference.

Obviously, the NSubstitute analyzers are not producing any warnings, either.

Any ideas what I can do?

VisualStudio version is 15.6.7 (VS 2017)

tpodolak commented 5 years ago

Hi @erizzo, thanks for reporting. I will try to take a look, however, I don't have access to this particular version on Visual Studio. I will take a look if this issue occurs on the one I own (15.7.6) and will get back to you

@dtchepak can you move this issue to NSubstitute.Analyzers repository? GitHub should be able to do this by now (but it seems I cant do it on my own)

erizzo commented 5 years ago

Thanks. I apologize for not noticing there was a separate repo for the analyzers.

tpodolak commented 5 years ago

@erizzo I did some digging and also asked on Roslyn gitter channel, and I am afraid I don't have good news. NSubstitute.Analyzers from the very first stable version depends on

<PackageReference Include="Microsoft.CodeAnalysis.CSharp.Workspaces" Version="2.8.2" PrivateAssets="all" />

This is the package which provides the Roslyn goodies thanks to which we are able to analyze c# code, report diagnostic etc. When the analyzer is added to project, this dependency is provided by VisualStudio itself - not by a NuGet reference/dependency. VisualStudio is shipped together with specific Roslyn version, the mapping between them is listed here. So as you can see from the link above you need Visual Studio 2017 version 15.7 or higher in order to make them work. At this point I can only advice to update VS to at least 15.7, would that be a problem for you @erizzo? From my side, I will add documentation which will clearly indicate min VS version is required for given NSubstitute.Analyzer package. I will also play around and see if it is possible to downgrade the Workspace packages to lower version but I am afraid it might not be possible

dtchepak commented 5 years ago

@erizzo Thanks for taking the time to raise the issue! Logging it in the other repo isn't a problem -- we'd much prefer to have a record of the issue than have people be put off trying to decide which repo it should go in! :)

@zvirja Thanks for moving this.

@tpodolak Seems like you've already found the issue. I did find the same message mentioned in this issue, but not sure how comparable that is.