โ Incremental source generator not called with docker
Hello,
I have 2 projects (simplified):
- one sandbox .net6
- one SourceGenerator .netStandard2.0
In my SourceGenerator, I have a class called RestServicesSourceGenerator like this
And in my sandbox project, I have a reference of my SourceGenerator
When i start building my sandbox (from VS or from command line
dotnet build --no-incremental
), the IIncrementalGenerator.Initialize is executed and i can see my generated files.
When i start building from docker using this image mcr.microsoft.com/dotnet/sdk:6.0
nothing happens. ๐ญ
When i start building from azure pipepline using vmImage: 'ubuntu-latest'
it's work ๐
If someone have an idea ๐ฅน
Deps are :
#rosyln31 Replies
Your generator is referencing workspaces?
Also, MS.CA 4.5 corresponds to VS 17.5. That is not the version in .NET 6
My generator reference some abstract projects for helping to generate or carry some custom attribute.
Microsoft.CodeAnalysis.CSharp.Workspaces 4.5.0 can be used for .net6 app & netstandard2.0
So, that doesn't mean what you think it means
First and foremost: you need to not depend on workspaces
You can only depend on MS.CA and MS.CA.CSharp/VB
Workspaces APIs are not available to generators
Second, yes MS.CA 4.5 supports being run on .NET 6. However, you don't control what version of MS.CA is used
The compiler is the thing that loads you, not the other way around
So you need to not depend on a newer version of MS.CA that could load you
The best way to determine this is to look at the .NET 6 SDK and see what version the dlls are (iirc they're going to be either 4.0 or 4.1)
You could also have the project consuming the generator depend on Microsoft.Net.Compilers.Toolset 4.5.0, which will cause the project to be built with the 4.5 version of MS.CA. However, the generator still won't work in VS less than 17.5
Thanks, I downgraded Microsoft.CodeAnalysis.CSharp.Workspaces to 4.2.0 and Microsoft.CodeAnalysis.Analyzers to 3.3.3 and it seem to work
You cannot use Workspaces
You will, at some point, accidentally use an API that is not available to your generator and it will fail again
You must use MS.CA.CSharp
i need this package Microsoft.CodeAnalysis.CSharp.Workspaces to reference IIncrementalGeneratorNo, that comes from MS.CA MS.CA's packages are a series of layers. The generator base apis (such as IIncrementalGenerator) come from the base layer When you run a
dotnet build
, you have up to and including the MS.CA.CSharp and VB layers
The Workspaces layer includes all of these, but more things
Those more things do not exist and you will run into errors if you accidentally start depending on APIs in this layerSorry, misreading.
yeah i will try with this
<PackageReference Include="Microsoft.CodeAnalysis.Common" Version="4.2.0" PrivateAssets="all"/>
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="4.2.0" PrivateAssets="all"/>
You don't need the first, the second includes it as a transitive dependency. Otherwise, looks good
I was some error without the Common
Your tests are depending on the wrong version still
it ask for version 3.8.0 but on this version
IIncrementalGenerator
doesn't exist, i should use ISourceGenerator
What asks for 3.8.0?
Microsoft.CodeAnalysis.CSharp.Workspaces ask for Microsoft.CodeAnalysis.CSharp to be on version 3.8
Wat
Why are you referencing this package?
I have only Microsoft.CodeAnalysis.CSharp on my deps
Then what did you mean by this?
Well, first, you're depending on the CodeRefactoring unit testing framework. Why?
And CodeFix
Are you writing codefixers or refactorings?
Only SourceGenerator
Then only reference that unit testing framework
it's global file props, i need to refactor this parts ๐
Andrew Lock | .NET Escapades
Source generator updates: incremental generators: Exploring .NET 6 ...
In this post I look at the updates to the source generator API in .NET 6, why the changes were made, and how to update your source generators to use them.
this is why i used
Microsoft.CodeAnalysis.CSharp.Workspaces
Well, I can't help bad articles ๐
Hello,
I'm still blocked with the
Microsoft.CodeAnalysis.CSharp
. I don't use Microsoft.CodeAnalysis.CSharp.Workspaces
but CA.Csharp required Workspace on 3.8.0.
I shouldn't add Workspace on reference.. but when i add it and run it from VS it's good
If i build from docker with sdk7 it's also good but i can't run test because the dotnet 6 runtime isn't here
If i build from docker with sdk6 it's going bad (can't build)https://github.com/dotnet/roslyn/blob/main/docs/wiki/NuGet-packages.md
4.3.1 is good with .net 6
GitHub
roslyn/NuGet-packages.md at main ยท dotnet/roslyn
The Roslyn .NET compiler provides C# and Visual Basic languages with rich code analysis APIs. - roslyn/NuGet-packages.md at main ยท dotnet/roslyn
CA.Csharp does not require Workspaces. I'm not sure what is going on with the testing framework here though. @sharwell, why is the generator testing framework bringing in workspaces and ruining the package references here?
The source generator references Microsoft.CodeAnalysis.CSharp. The test project needs to explicitly reference Microsoft.CodeAnalysis.Workspaces.CSharp of the same version.
thanks you
i have created a Dockerfile with sdk 6 & sdk7 and now it's work ๐
Was this issue resolved? If so, run
/close
- otherwise I will mark this as stale and this post will be archived until there is new activity.