title: Deploying a C# source generator project that includes references to other private projects
body: <p>I want to release a source generator package, and I want to include a private project dependency on the source generator project.</p>
  <p>For example, assume that my projects are <code>A.SourceGenerator</code> and <code>A.CodeAnalysis.Core</code>. I want <code>A.SourceGenerator</code> to depend on <code>A.CodeAnalysis.Core</code>, but use <code>ProjectReference</code> instead of <code>PackageReference</code>.</p>
  <p>This means that I want the following line or something similar in my <code>A.SourceGenerator.csproj</code> file:</p>
  <pre class="lang-xml prettyprint-override"><code>&lt;None Include=&quot;$(OutputPath)\A.CodeAnalysis.Core.dll&quot; Pack=&quot;true&quot; PackagePath=&quot;analyzers/dotnet/cs&quot; Visible=&quot;false&quot; /&gt;
  </code></pre>
  <p>The issue is that this, or some similar variations, won't work and will produce a source generation error, under the CS8785 compiler warning, with the following error message:</p>
  <p>Generator <code>BenchmarkSourceGenerator</code> failed to generate source. It will not contribute to the output and compilation errors may occur as a result.</p>
  <p>Exception was of type <code>FileNotFoundException</code> with message:</p>
  <p>Could not load file or assembly <code>A.CodeAnalysis.Core, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null</code> or one of its dependencies. The system cannot find the file specified.</p>
  <p>The above error is shown because the project's contents need to be locally copied on the directory that the source generator lies on. There is a trick for that when using <code>PackageReference</code>, as shown <a href="https://github.com/dotnet/roslyn/blob/main/docs/features/source-generators.cookbook.md#use-functionality-from-nuget-packages" rel="nofollow noreferrer">here</a>, but it clearly does not apply for the case of <code>ProjectReference</code>.</p>
  <p>I would prefer to avoid creating a brand new NuGet package that the source generator depends on, just to include the dependencies. The other solution is to not abstract that away and only have one source generator project including all source generators.</p>