language-ext icon indicating copy to clipboard operation
language-ext copied to clipboard

Plans to replace CodeGeneration.Roslyn dependency with Source Generators (introduced in .NET 5) in LanguageExt.CodeGen?

Open Malgefor opened this issue 3 years ago • 8 comments

Hi!

I am using the LanguageExt.CodeGen package to generate Discriminated Unions. However, the dependency https://github.com/AArnott/CodeGeneration.Roslyn is marked as deprecated in the repo.

Are there plans to use the Source Generators (https://devblogs.microsoft.com/dotnet/introducing-c-source-generators/) for the CodeGen package?

Cheers

Malgefor avatar May 27 '21 08:05 Malgefor

To elaborate a bit more on why the dependency on the deprecated package isn't great: if you want to run the codegen tool in your build you need to .NET Core 2.1 SDK installed on the machine / Docker image to be able to build. So when building a .NET 5 project, you still need 2.1.

If you don't have the 2.1 SDK you will get errors along the lines of:

.nuget/packages/codegeneration.roslyn.buildtime/0.6.1/build/CodeGeneration.Roslyn.BuildTime.targets(61,5): warning MSB3073: The command "dotnet codegen --version" exited with code 150.

.nuget/packages/codegeneration.roslyn.buildtime/0.6.1/build/CodeGeneration.Roslyn.BuildTime.targets(61,5): warning MSB4181: The "Exec" task returned false but did not log an error.

.nuget/packages/codegeneration.roslyn.buildtime/0.6.1/build/CodeGeneration.Roslyn.BuildTime.targets(73,5): error CGR1001: CodeGeneration.Roslyn.Tool (dotnet-codegen) is not available, code generation won't run. Please check https://github.com/AArnott/CodeGeneration.Roslyn for usage instructions.

To fix this you have to install the .NET Core 2.1 SDK, which goes out of support August 2021. (https://dotnet.microsoft.com/platform/support/policy/dotnet-core)

Example config of installing the 2.1 SDK in a Docker file: FROM mcr.microsoft.com/dotnet/sdk:5.0-focal AS build COPY --from=mcr.microsoft.com/dotnet/sdk:2.1-focal /usr/share/dotnet /usr/share/dotnet

Malgefor avatar Jun 01 '21 11:06 Malgefor

you should not need 2.1 sdk. try to define roll forward policy https://github.com/AArnott/CodeGeneration.Roslyn/issues/180#issuecomment-562895670

harrhp avatar Jun 02 '21 13:06 harrhp

Ah you are right! Thanks for pointing that out : ) Missed that when I was trying to get the codegen tool to work.

Malgefor avatar Jun 02 '21 13:06 Malgefor

Regarding the original question, yes, I will be updating the CodeGen to use Source Generators. I'm super overloaded with other projects at the moment, so I'm having to keep my interaction with LangExt at a minimum for a while, so it probably won't be for a month or so.

louthy avatar Jun 07 '21 08:06 louthy

you should not need 2.1 sdk. try to define roll forward policy

In my case, it was required to install the runtime 2.1. Installing the SDK was not enough.

gabomgp4 avatar Jun 08 '21 23:06 gabomgp4

Hi, I'm totally new to LanguageExt and tried to setup the codegen functionality as mentioned in the wiki. But I do have the same problem as other in that I can't get it to work with my .NET6 SDK. I saw there was no activity here for 6 months. Is this still on the roadmap, @louthy ?

bmargula avatar Dec 22 '21 11:12 bmargula

@bmargula: Installing .NET 2.1 (SDK or runtime, don't know) on your developer machine (and your build server) should be enough to make codegen working as documented. This is not a runtime dependency for your binaries. Your project can target e.g. net60. It's working fine with latest LanguageExt, too.

StefanBertels avatar Dec 23 '21 23:12 StefanBertels

you should not need 2.1 sdk. try to define roll forward policy AArnott/CodeGeneration.Roslyn#180 (comment)

Have you tried this? After I set the rollforwardpolicy as an environment variable it worked without having to install the 2.1 sdk/runtime

Malgefor avatar Dec 24 '21 11:12 Malgefor