Skip to content

EnableNETAnalyzers feature not working #12784

@carlossanlop

Description

@carlossanlop

This file has bugs in these lines:

In these two locations, there is an extra space in $(EnableNETAnalyzers ) before the closing parenthesis, causing MSBuild to not find that property:

<EnableNETAnalyzers Condition="'$(EnableNETAnalyzers )' == '' And

<EnableNETAnalyzers Condition="'$(EnableNETAnalyzers )' == ''">false</EnableNETAnalyzers>

So even if I set EnableNETAnalyzers to true in my csproj, it gets overriden to false because this line overrides it:

<EnableNETAnalyzers Condition="'$(EnableNETAnalyzers )' == ''">false</EnableNETAnalyzers>

Once that spaces get removed, the DLLs are not found because their paths are relative to the project, not to the SDK:

Include="..\analyzers\Microsoft.CodeAnalysis.VisualBasic.NetAnalyzers.dll"

Include="..\analyzers\Microsoft.CodeAnalysis.CSharp.NetAnalyzers.dll"

Include="..\analyzers\Microsoft.CodeAnalysis.NetAnalyzers.dll"

Error:

CSC : error CS0006: Metadata file '..\analyzers\Microsoft.CodeAnalysis.CSharp.NetAnalyzers.dll' could not be found [D:\testing\ConsoleCore\ConsoleCore.csproj]
CSC : error CS0006: Metadata file '..\analyzers\Microsoft.CodeAnalysis.NetAnalyzers.dll' could not be found [D:\testing\ConsoleCore\ConsoleCore.csproj]

So the fix is to prefix the 3 DLL paths with $(MSBuildThisFileDirectory) like this:

Include="$(MSBuildThisFileDirectory)..\analyzers\Microsoft.CodeAnalysis.VisualBasic.NetAnalyzers.dll"

Once fixed, it can find instances of the new Roslyn analyzers.

This bug is present in master and in Preview8.

cc @jmarolf @mavasani

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions