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
yes, the .NET SDK comes with a matching version of the C# compiler, and preview SDKs contain preview compilers
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
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
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.
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
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
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
hmm ok. that's unfortunate
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 previewok, I'll read up on it
of course, the SDK does other things which could in principle be a concern
yeah, would only want to use the preview sdk only for a preview build of our product
i do not think there is really a huge concern in this scenario
you may be right but if certainty is required
Unknown User•6mo ago
Message Not Public
Sign In & Join Server To View
Ok interesting
Unknown User•6mo ago
Message Not Public
Sign In & Join Server To View