question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Package analyzers always included, ignoring exclude settings

See original GitHub issue

NuGet provides the “ExcludeAssets” setting to allow excluding analyzers from packages. However, it appears the SDK still includes analyzers in the build even if excluded.

(cref https://docs.microsoft.com/en-us/nuget/consume-packages/package-references-in-project-files#controlling-dependency-assets)

Repro

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <TargetFramework>netcoreapp2.0</TargetFramework>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.0.0" />
    <PackageReference Include="xunit" Version="2.2.0" />
    <PackageReference Include="xunit.runner.visualstudio" Version="2.2.0" />

    <PackageReference Include="xunit.analyzers" Version="0.1.0" ExcludeAssets="analyzers" />

  </ItemGroup>

</Project>
using System;                              
using Xunit;                               
                                           
namespace test1                            
{                                          
    public class UnitTest1                 
    {                                      
        [Fact]                             
        public void Test1(string data) // this line intentionally trips an error in xunit.analyzers...just to prove the analyzer is running
        {                                  
        }                                  
    }                                      
}                                          
dotnet restore
dotnet build

Expected The analyzer in xunit.analzyers/0.1.0/analyzers/dotnet/cs/xunit.analyzers.dll should not have been passed to CSC, and build succeeds.

Result

Build FAILED.

UnitTest1.cs(9,21): error xUnit1001: Fact methods cannot have parameters [C:\tmp\test1\test1.csproj]
    0 Warning(s)
    1 Error(s)

Details Using dotnet.exe 2.0.0-preview2-006067

project.assets.json file contains:

{
  // ...
  "libraries": {
    "xunit.analyzers/0.1.0": {
      "sha512": "wPHthUmM0vdhL3lrTlyxJFfTgGh+2bkOn5CuxgZaPEMxLJArMCvUx8WmsVFeIATLVulVGvwNnZFkuwc0lsun7g==",
      "type": "package",
      "path": "xunit.analyzers/0.1.0",
      "files": [
        "analyzers/dotnet/cs/xunit.analyzers.dll",
        "tools/install.ps1",
        "tools/uninstall.ps1",
        "xunit.analyzers.0.1.0.nupkg.sha512",
        "xunit.analyzers.nuspec"
      ]
    }
  },
  // ...
  "project": {
    "frameworks": {
      "netcoreapp2.0": {
        "dependencies": {
          // ...
          "xunit.runner.visualstudio": {
            "target": "Package",
            "version": "2.2.0"
          },
          "xunit.analyzers": {
            "include": "Runtime, Compile, Build, Native, ContentFiles",
            "target": "Package",
            "version": "0.1.0"
          },
          // ...
        }
      }
    }
  }
}

Issue Analytics

  • State:open
  • Created 6 years ago
  • Reactions:17
  • Comments:7 (5 by maintainers)

github_iconTop GitHub Comments

2reactions
Cryowattcommented, Oct 5, 2017

This issue also occurs when a project includes a package that excludes analyzes from it’s .nuspec. The solution ends up including the nested dependency analyzers and I get IDE1002 errors during the build.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Exclude Unity packages from Roslyn Analyzers
I just added some Roslyn analyzers into my Unity project like described ... I cannot find a way to exclude Unity packages from...
Read more >
Add variable to ignore development, test dependencies in ...
The Gemnasium Maven plugin provides an option to exclude dependencies belonging to the test scope but gemnasium-maven doesn't expose that option ...
Read more >
How can you force StyleCop for ReSharper to ignore files?
This was what I was looking for, except in Resharper 6 the correct keystroke to disable inspection in a specific file is: Ctrl...
Read more >
Narrowing the focus with analysis scope - SonarQube Docs
You can have SonarQube ignore issues on certain components and against certain coding rules. Go to Project Settings > General Settings > Analysis...
Read more >
Can't exclude folders for VS Code OmniSharp's ...
I use VS Code with Unity and I'm trying to ignore the code analysis of third party code bases. I've read OmniSharp's github...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found