aspnet / RoslynCodeDomProvider

Roslyn CodeDOM provider
MIT License
84 stars 43 forks source link

Allow overriding version through MSBuild property #143

Closed khellang closed 1 year ago

khellang commented 2 years ago

Hello @StephenMolloy! 👋

How's the 3.11 version coming along?

Would it be possible to include an easy way to set the desired compiler version through an MSBuild property?

By conditionally setting the following properties, only if they haven't already been set, you could allow users that want to wander "off the beaten track" to override the compiler version in order to use newer compiler/language features:

https://github.com/aspnet/RoslynCodeDomProvider/blob/960f11f63bc33f99c6a6bfd903b1a1daccb2e1d9/tools/RoslynCodeProvider.settings.targets#L22-L25

StephenMolloy commented 1 year ago

I don't think we could commit to officially supporting this configuration. However, if you really want to "bring your own" roslyn compiler, you always have the option to use the RoslynToolPath property to point this provider at a specific roslyn toolset. This does require you to have downloaded the specific toolset already, rather than simply supplying a version number. But it is otherwise a similar concept.

khellang commented 1 year ago

Yeah, we ended up with this solution, which relies on NuGet's GeneratePathProperty feature to download the toolset with package restore and set the RoslynToolPath based on that. Works like a charm ✨