C
C#โ€ข16mo ago
QzL

โ” 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
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.CSharp.Syntax;

[Generator]
public sealed class RestServicesSourceGenerator
: IIncrementalGenerator
{
public RestServicesSourceGenerator()
{
}

void IIncrementalGenerator.Initialize(IncrementalGeneratorInitializationContext context)
{
// processing code
}
}
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.CSharp.Syntax;

[Generator]
public sealed class RestServicesSourceGenerator
: IIncrementalGenerator
{
public RestServicesSourceGenerator()
{
}

void IIncrementalGenerator.Initialize(IncrementalGeneratorInitializationContext context)
{
// processing code
}
}
And in my sandbox project, I have a reference of my SourceGenerator
<ProjectReference Include="..\..\project.csproj" OutputItemType="Analyzer" ReferenceOutputAssembly="true" />
<ProjectReference Include="..\..\project.csproj" OutputItemType="Analyzer" ReferenceOutputAssembly="true" />
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 :
<PackageReference Update="Microsoft.CodeAnalysis.Analyzers" Version="3.3.4" />
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.Workspaces" Version="4.5.0" PrivateAssets="all" />
<PackageReference Update="Microsoft.CodeAnalysis.Analyzers" Version="3.3.4" />
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.Workspaces" Version="4.5.0" PrivateAssets="all" />
#rosyln
31 Replies
333fred
333fredโ€ข16mo ago
Your generator is referencing workspaces? Also, MS.CA 4.5 corresponds to VS 17.5. That is not the version in .NET 6
QzL
QzLโ€ข16mo ago
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
333fred
333fredโ€ข16mo ago
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
QzL
QzLโ€ข16mo ago
Thanks, I downgraded Microsoft.CodeAnalysis.CSharp.Workspaces to 4.2.0 and Microsoft.CodeAnalysis.Analyzers to 3.3.3 and it seem to work
333fred
333fredโ€ข16mo ago
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 IIncrementalGenerator
No, 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 layer
QzL
QzLโ€ข16mo ago
Sorry, 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"/>
333fred
333fredโ€ข16mo ago
You don't need the first, the second includes it as a transitive dependency. Otherwise, looks good
QzL
QzLโ€ข16mo ago
I was some error without the Common
QzL
QzLโ€ข16mo ago
333fred
333fredโ€ข16mo ago
Your tests are depending on the wrong version still
QzL
QzLโ€ข16mo ago
it ask for version 3.8.0 but on this version IIncrementalGeneratordoesn't exist, i should use ISourceGenerator
QzL
QzLโ€ข16mo ago
333fred
333fredโ€ข16mo ago
What asks for 3.8.0?
QzL
QzLโ€ข16mo ago
Microsoft.CodeAnalysis.CSharp.Workspaces ask for Microsoft.CodeAnalysis.CSharp to be on version 3.8
333fred
333fredโ€ข16mo ago
Wat Why are you referencing this package?
QzL
QzLโ€ข16mo ago
I have only Microsoft.CodeAnalysis.CSharp on my deps
333fred
333fredโ€ข16mo ago
Then what did you mean by this?
QzL
QzLโ€ข16mo ago
333fred
333fredโ€ข16mo ago
Well, first, you're depending on the CodeRefactoring unit testing framework. Why? And CodeFix Are you writing codefixers or refactorings?
QzL
QzLโ€ข16mo ago
Only SourceGenerator
333fred
333fredโ€ข16mo ago
Then only reference that unit testing framework
QzL
QzLโ€ข16mo ago
it's global file props, i need to refactor this parts ๐Ÿ™‚
QzL
QzLโ€ข16mo ago
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.
QzL
QzLโ€ข16mo ago
this is why i used Microsoft.CodeAnalysis.CSharp.Workspaces
333fred
333fredโ€ข16mo ago
Well, I can't help bad articles ๐Ÿ™‚
QzL
QzLโ€ข16mo ago
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)
QzL
QzLโ€ข16mo ago
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
333fred
333fredโ€ข16mo ago
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?
sharwell
sharwellโ€ข16mo ago
The source generator references Microsoft.CodeAnalysis.CSharp. The test project needs to explicitly reference Microsoft.CodeAnalysis.Workspaces.CSharp of the same version.
QzL
QzLโ€ข16mo ago
thanks you i have created a Dockerfile with sdk 6 & sdk7 and now it's work ๐Ÿ˜„
Accord
Accordโ€ข16mo ago
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.
Want results from more Discord servers?
Add your server
More Posts
โ” c# vs code help neededi made a perfect running script but when i get to high numbers vs code freezesโ” Set up Sustainsys.Saml2 configuration in Web.config programmaticallyI'm trying to set up Sustainsys' Saml2 integration in an ASP.NET MVC 4 application. However, I need โ” Adding managed module to Web.config programmatically in ASP.NETHi everyone! I have a kind-of niche situation in which I am required to programmatically add a managโœ… Struggling with c#I'm trying to do a Bank Form in WPF and I'm struggling with saving the data that the user inputs intโœ… Help optimizing finding keywords in textI currently have a huge document database, and want to go through each of them and find matching keyโœ… Visual Studio nesting resource filesHi, I'm using [File Nesting In Visual Studio](https://learn.microsoft.com/en-us/visualstudio/ide/fiโ” Update-Database causing errorHi, When I try to use the "Update-Database" command in visual studio an error occures: An error occHow to get Grid to use the height of the tallest image instead of the height of the first image XAMLBeen stuck on this one for a few days Any help would be greatly apricated. Its showing images usingโ” ASP.NET to .net CoreIm trying to convert my asp.net project to .net core. I have a class thats using Httpcontext in someโ” Nettopologysuite - What datasources are supported? How to query data?Can I use Nettopologysuite (https://github.com/NetTopologySuite/NetTopologySuite) to retrieve data f