Skip to content

NuGets referenced from analyzer/source-generator should automatically include DLL's #7640

@Eli-Black-Work

Description

@Eli-Black-Work

Let's say that my analyzer or source generator depends on the GraphQL NuGet:

<ItemGroup>
    <PackageReference Include="GraphQL" Version="4.7.1" GeneratePathProperty="true" PrivateAssets="all" />
</ItemGroup>

This will fail, because MSBuild won't automatically include GraphQL's DLL's, so I need to do this:

<!-- See https://github.com/dotnet/roslyn-sdk/blob/0313c80ed950ac4f4eef11bb2e1c6d1009b328c4/samples/CSharp/SourceGenerators/SourceGeneratorSamples/SourceGeneratorSamples.csproj#L13-L30
and https://github.com/dotnet/roslyn/discussions/47517#discussioncomment-64145 -->
<PropertyGroup>
    <GetTargetPathDependsOn>$(GetTargetPathDependsOn);GetDependencyTargetPaths</GetTargetPathDependsOn>
</PropertyGroup>

<Target Name="GetDependencyTargetPaths">
    <!-- Manually include the DLL of each NuGet package that this analyzer uses. -->
    <ItemGroup>
        <TargetPathWithTargetPlatformMoniker Include="$(PKGGraphQL)\lib\netstandard2.0\GraphQL.dll" IncludeRuntimeDependency="false" />
    </ItemGroup>
</Target>

I'd like to request that when an analyzer/source-generator references a NuGet, MSBuild automatically hooks up the NuGet's DLL's 🙂

This seems to have been a source of confusion for many! See all of the comments at dotnet/roslyn#47517 🙂

P.S.
Not sure if MSBuild is the correct place to post this?

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions