C
C#6mo ago
rykr

relationship between C# compiler and .net core sdk

does a preview version of .net core use a preview version of the compiler? What is the relationship there?
16 Replies
reflectronic
reflectronic6mo ago
yes, the .NET SDK comes with a matching version of the C# compiler, and preview SDKs contain preview compilers
rykr
rykrOP6mo ago
so if I have a project that wants to build for .net 6, .net 8, and preview .net 9. it's going to use a GA versoin of the build system for 6 and 8 and the preview for 9? just making sure it's no tusing the preview of a compiler with the GA sdk for 6 and 8 for my builds making them suspect
reflectronic
reflectronic6mo ago
no, by default the highest SDK version installed is used for everything you can compile .NET 6 and .NET 8 projects using the .NET 9 SDK and it will use the preview version of the compiler, yes
reflectronic
reflectronic6mo ago
to stop this, you can use https://learn.microsoft.com/en-us/dotnet/core/tools/global-json to force a subdirectory to use some previous version of the SDK
global.json overview - .NET CLI
Learn how to use the global.json file to set the .NET SDK version when running .NET CLI commands.
rykr
rykrOP6mo ago
ok. if I have a project that targets net60, net80, and net90 I would want it to use GA build system for net60 and net80 and net9.0 dotnet build in a folder with a projecgt with this line
<TargetFrameworks>netstandard2.0;netstandard2.1;net6.0;net8.0;</TargetFrameworks>
<TargetFrameworks>netstandard2.0;netstandard2.1;net6.0;net8.0;</TargetFrameworks>
assuming we add the .net 9 preview in there as a target too we want binaries for each target but all exect the ..net 9 preview need to not use any preview stuff sorry if I'm not explaining it right
reflectronic
reflectronic6mo ago
there is no way to do that i mean. i guess, you can build it twice and change the target frameworks and SDK in between and stich it together manually. but that is quite unpleasant
rykr
rykrOP6mo ago
hmm ok. that's unfortunate
reflectronic
reflectronic6mo ago
you can override the compiler version using https://www.nuget.org/packages/Microsoft.Net.Compilers.Toolset you can add a reference, and dotnet build will switch to that compiler. the package versions there correspond to visual studio versions, mostly, so 4.9.2 would correspond to the compiler in VS 17.9, and that is not preview
rykr
rykrOP6mo ago
ok, I'll read up on it
reflectronic
reflectronic6mo ago
of course, the SDK does other things which could in principle be a concern
rykr
rykrOP6mo ago
yeah, would only want to use the preview sdk only for a preview build of our product
reflectronic
reflectronic6mo ago
i do not think there is really a huge concern in this scenario
rykr
rykrOP6mo ago
you may be right but if certainty is required
Unknown User
Unknown User6mo ago
Message Not Public
Sign In & Join Server To View
rykr
rykrOP6mo ago
Ok interesting
Unknown User
Unknown User6mo ago
Message Not Public
Sign In & Join Server To View
Want results from more Discord servers?
Add your server