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.

Pack when referencing Microsoft.CodeAnalysis.CSharp generates exclude="Build,Analyzers"

See original GitHub issue

Repro steps:

  1. New project:
<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <TargetFramework>netstandard1.3</TargetFramework>
  </PropertyGroup>

  <PropertyGroup>
    <Version>0.1.0-dev</Version>
    <Authors>Author</Authors>
    <Description>Descriptor</Description>
    <NeutralLanguage>en</NeutralLanguage>
    <GeneratePackageOnBuild>true</GeneratePackageOnBuild>
    <PackageLicenseExpression>MIT</PackageLicenseExpression>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="2.3.1" />
  </ItemGroup>
</Project>
  1. Build in VS
  2. Check created package.
<?xml version="1.0" encoding="utf-8"?>
<package xmlns="http://schemas.microsoft.com/packaging/2012/06/nuspec.xsd">
  <metadata>
    <id>PackRepro</id>
    <version>0.1.0-dev</version>
    <authors>Author</authors>
    <owners>Author</owners>
    <requireLicenseAcceptance>false</requireLicenseAcceptance>
    <license type="expression">MIT</license>
    <description>Descriptor</description>
    <dependencies>
      <group targetFramework=".NETStandard1.3">
        <dependency id="Microsoft.CodeAnalysis.CSharp" version="2.3.1" exclude="Build,Analyzers" />
        <dependency id="NETStandard.Library" version="1.6.1" exclude="Build,Analyzers" />
      </group>
    </dependencies>
  </metadata>
</package>

I tried <PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="2.3.1" PrivateAssets="none"/> but it did not have any effect.

Is there a way to pack this so that analyzers are not excluded? Is there documentation about this?

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:1
  • Comments:28 (8 by maintainers)

github_iconTop GitHub Comments

1reaction
nkolev92commented, Jul 30, 2019

The exact repro didn’t matter in my case:

Here’s the generated nuspec.

<?xml version="1.0" encoding="utf-8"?>
<package xmlns="http://schemas.microsoft.com/packaging/2013/05/nuspec.xsd">
  <metadata>
    <id>3489-repro</id>
    <version>0.1.0-dev</version>
    <authors>Author</authors>
    <owners>Author</owners>
    <requireLicenseAcceptance>false</requireLicenseAcceptance>
    <license type="expression">MIT</license>
    <licenseUrl>https://licenses.nuget.org/MIT</licenseUrl>
    <description>Descriptor</description>
    <dependencies>
      <group targetFramework=".NETStandard1.3">
        <dependency id="Microsoft.CodeAnalysis.CSharp" version="2.3.1" include="All" />
        <dependency id="NETStandard.Library" version="1.6.1" exclude="Build,Analyzers" />
      </group>
    </dependencies>
  </metadata>
</package>

I’ll do some digging to see if I can figure out the scenario in which it ends up not working.

It’d be helpful if you can provide us the assets file right before you pack.

0reactions
nkolev92commented, Aug 2, 2019

Pack burns in the restored versions of packages, not the requested ones. So it’s by design right now.

Pack also doesn’t run build if it’s out of date. I see restore as the same thing.

Note that even if pack were to do an up to date restore check, it’d then need to run an up to date build check.

I’m not saying it’ll never ever change or something like that, I just don’t see any immediate changes happening 😃

Read more comments on GitHub >

github_iconTop Results From Across the Web

SourceGenerator analyzer package works in Visual Studio ...
So far I've: Cleared the nuget cache; deleted the .vs folder; restarted VS 2019. And no luck. Any help is appreciated. c# ......
Read more >
PackageReference in project files - NuGet
Package references, using <PackageReference> MSBuild items, specify NuGet package dependencies directly within project files, as opposed to ...
Read more >
Code analysis in .NET
NET compiler platform (Roslyn) analyzers inspect your C# or Visual Basic code for code quality and style issues. Starting in .NET 5, these ......
Read more >
CSharpCompilation.WithReferences Method
Creates a new compilation with the specified references.
Read more >
CSharpCompilation Class (Microsoft.CodeAnalysis.CSharp)
A compilation can produce a new compilation from existing compilation with the application of small deltas. In many cases, it is more efficient...
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