Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Question] How to support older versions of .net-SDK when authoring a source-generator? #1056

Closed
earloc opened this issue Feb 8, 2023 · 1 comment
Labels
Area-Source Generators SDK support for source generators question

Comments

@earloc
Copy link

earloc commented Feb 8, 2023

Hey folks.

I´m authoring a neat little source-generator over at https://github.com/earloc/TypealizR, where I´m doing some minor code-analysis over C# using Microsoft.CodeAnalysis.CSharp.

Recently, I wittnessed one of my github-actions to fail the build on an agent with .net6 . The build broke once I updated Microsoft.CodeAnalysis.CSharp to 4.4.0, so I donwgraded to 4.3.0 in order to get things working again.

Then I tried to just bundle the assembly as suggested here, but doing so then breaks whenever I build on an agent with .net7, giving the following error during compilation:

Unhandled Exception: System.InvalidCastException: 
[A]Microsoft.CodeAnalysis.CSharp.Syntax.CompilationUnitSyntax cannot be cast to 
[B]Microsoft.CodeAnalysis.CSharp.Syntax.CompilationUnitSyntax. 
Type A originates from 'Microsoft.CodeAnalysis.CSharp, Version=4.4.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' in the context 'Default' at location 'C:\Program Files\Microsoft Visual Studio\2022\Enterprise\MSBuild\Current\Bin\Roslyn\Microsoft.CodeAnalysis.CSharp.dll'. 
Type B originates from 'Microsoft.CodeAnalysis.CSharp, Version=4.4.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' in the context 'LoadFrom' at location 'C:\Users\[USERNAME]\.nuget\packages\typealizr\0.8.3\analyzers\dotnet\cs\Microsoft.CodeAnalysis.CSharp.dll'.

To reproduce, just reference the (unlisted) version 0.8.3 of my TypealizR-package in a fresh console-project on a machine with .net7-sdk

Is there something I can do to still support older sdks, other than just downgrading Microsoft.CodeAnalysis.CSharp?
I guess to support even older sdk´s (or good old full-fx), I would even need to downgrade to an even lesser version, right?

#107 looks kind of an enabler for my scenario, but wasn´t exactly sure.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-Source Generators SDK support for source generators question
Projects
None yet
Development

No branches or pull requests

2 participants