Paket v6 cannot be used for .NET source generation
Nobody has claimed this yet.
- Dominant language
- F#
- Stars
- 2.1k
- Forks
- 528
- Avg merge
- 1d 12m
- Merged PRs (30d)
- 54
Description
Description
I have a solution that uses source generation and it requires some additional work to make it work with Paket v5. I have my standard projects compile for net5.0, but source generators must be netstandard2.0, so I used the following paket.dependencies:
source https://api.nuget.org/v3/index.json
framework: net5.0
# All NuGet packages for the regular projects go here
group CodeGenerator
# The source generator should be .NET Standard 2.0
source https://api.nuget.org/v3/index.json
framework: netstandard2.0
nuget Microsoft.CodeAnalysis.Analyzers copy_local:true
nuget Microsoft.CodeAnalysis.CSharp copy_local:true
Note that both packages for the CodeGenerator havev copy_local:true added, because these packages should have PrivateAssets="all" enabled in the (generated) project-file as described here.
To ensure that the proper packages are used, the paket.references file of my source generator looks like this:
group CodeGenerator
Microsoft.CodeAnalysis.Analyzers
Microsoft.CodeAnalysis.CSharp
I upgraded to .NET 6.0 and needed to upgrade Paket to v6 too, but it now fails to properly invoke the source generator. It fails with the following error:
Generator '...' failed to generate source. It will not contribute to the output and compilation errors may occur as a result. Exception was of type 'FileNotFoundException' with message 'Could not load file or assembly 'System.Collections.Immutable, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified.'
When using the traditional approach with including the packages directly in the project-file it works fine again.
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reproducing the failure with the shown paket.dependencies and paket.references, then compare Paket v6's generated project-file references with the working direct project-file approach. Trace how the CodeGenerator group handles Microsoft.CodeAnalysis packages and verify that the source generator can load System.Collections.Immutable; done means the .NET 6 source generator builds and runs successfully under Paket v6.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- csharp
- Domain
- build-system, tooling
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100