I would like to pack a Roslyn source generator and another project that contains the attributes the source generator acts upon together into one NuGet package. To do this, I've decided that using a third project collecting the other two would be the best option.
Here's what that third project file looks like:
<Project Sdk="Microsoft.NET.Sdk"><PropertyGroup><TargetFramework>netstandard2.0</TargetFramework><IncludeBuildOutput>false</IncludeBuildOutput><IsPackable>true</IsPackable><NoWarn>$(NoWarn);NU5128</NoWarn><PackageId>MyGenerators</PackageId></PropertyGroup><ItemGroup><ProjectReference Include="$(SrcPath)\MyProject.SourceGenerators\MyProject.SourceGenerators.csproj" PrivateAssets="all" /><ProjectReference Include="$(SrcPath)\MyProject.SourceGenerators.Core\MyProject.SourceGenerators.Core.csproj" PrivateAssets="all" /></ItemGroup><ItemGroup><None Include="$(OutputPath)\MyProject.SourceGenerators.dll" Pack="true" PackagePath="analyzers/dotnet/cs" Visible="false" /><None Include="$(OutputPath)\MyProject.SourceGenerators.Core.dll" Pack="true" PackagePath="lib/netstandard2.0" /></ItemGroup></Project>
Using dotnet pack
to create the package works as intended. However, when I locally consume MyGenerators
, NuGet throws NU1101
twice:
Unable to find package MyProject.SourceGenerators.Core. No packages exist with this id in source(s): local, nuget.orgUnable to find package MyProject.SourceGenerators. No packages exist with this id in source(s): local, nuget.org
The local
source points to the directory the above project's package is placed in. MyGenerators
itself does, of course, get found. It's the project references that NuGet treats as packages themselves.
I've tried out some combinations of removing PrivateAssets
, setting DevelopmentDependency
to true
, changing package paths and output types, but I can't get the final package to behave the way I need it to.
What could I be doing wrong here?