Skip to content

True-negative in GetUsedAssemblyReferences #66188

@stan-sz

Description

@stan-sz

Version Used: 4.4.0

Steps to Reproduce:

Given:

foo.csproj:

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

  <PropertyGroup>
    <OutputType>Library</OutputType>
    <TargetFramework>net6.0</TargetFramework>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="Newtonsoft.Json" Version="13.0.2" />
  </ItemGroup>

</Project>

and foo.cs

namespace Library
{
    public static class Foo
    {
        public static string Bar() => "Baz";
    }
}

Repro requires an analyzer that dumps the output of GetUsedAssemblyReferences. An example implementation is in https://github.com/dfederm/ReferenceTrimmer/pull/20/files, the failed test case (where the above repo is taken from) is dotnet test ReferenceTrimmer.sln --filter UnusedPackageReference

Expected Behavior:

The result of CSharpCompilation.GetUsedAssemblyReferences does not contain Newtonsoft.Json.dll reference

Actual Behavior:

The result of CSharpCompilation.GetUsedAssemblyReferences does contain <home>\.nuget\packages\newtonsoft.json\13.0.2\lib\net6.0\Newtonsoft.Json.dll

Metadata

Metadata

Assignees

Type

No type

Projects

Status

Active/Investigating

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions