ā Primary constructors in VS 2019.
Probably going to be annoyed for not using 2022, yes I know. But moving on, I'm currently using .NET Standard 2.0 with the C# language version set to 'preview' in the .csproj. Is there any more steps I have to take so that I don't get 7 errors when trying to use primary constructors?
16 Replies
by default, standard 2.0 projects are set to an older c# language version
Ye, I'm aware, noticed the same issue with .NET Framework.
you need to use something like https://github.com/Sergio0694/PolySharp/, or bump up your framework target to net7
Framework 4.x targets will have the same limitations as Standard 2
š¤
wait, primary ctors are a preview feature?
Yes.
you definitely need to be targeting the latest net8 preview in that case
Noticed when I was trying to work with console apps in VS Code.
Sadly that doesn't work out in my case, I need to have my library be targeted for .NET Standard 2.0
Its intended use is on Mono, specifically for Unity 2020.3.
You need to use an sdk that has a new enough compiler which has the feature you want
I think I'd recommend you avoid preview lang features until that's officially added
Fair enough.
won't be too long now, release is in November
Just found the primary constructors pretty useful and wanted to simplify my code.
the only solution is to upgrade to Visual Studio 2022
that is the only version of Visual Studio that has a compiler which knows about primary constructors
or anything released in C# 10 or 11
there is no hack you can do which will turn it on, the tool you are using is more than two years out of date by now
š. I assume my VS 2019 solutions will transfer over fine?
They're not dependent on the IDE
Just switched over to VS 2022. Thank you all for helping me figure this out.
Always hesitated going through the effort of switching, but I'm starting to like the UI theme on VS 2022 a lot more, so it seems to be worth the switch.
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.