Getting Setup With .NET 6 Preview

In the coming months I’ll be covering the new features of .NET 6, including things like MAUI (Cross platform GUI in .NET), PriorityQueue, and so much more. So I thought it would be worth talking a little bit on how to actually get set up to use .NET 6 if you are looking to touch this new tech early on.

In previous versions of .NET/.NET Core, the process to accessing preview versions was somewhat convoluted and involved installing a second “preview” version of Visual Studio to get up and running, but all that’s out the window now and things are easier than ever!

Setting Up .NET 6 SDK

To start, head over to the .NET 6 download page and download the latest SDK (not runtime!) for your operating system : https://dotnet.microsoft.com/download/dotnet/6.0

After installing, from a command prompt, you should be able to run “dotnet –info” and see something similar to the below :

.NET SDK (reflecting any global.json):
 Version:   6.0.100-preview.2.21155.3
 Commit:    1a9103db2d

It is important to note that this is essentially telling you that the default version of the .NET SDK is .NET 6 (Although, sometimes in Visual Studio, it will ignore preview versions as we will shortly see). This is important to note because any projects that don’t utilize a global.json will now be using .NET 6 (and a preview version at that). We have a short guide on how global.json can determine which SDK is used right here.

Setting Up Visual Studio For .NET 6

Now for the most part, developers of .NET will use Visual Studio. And the number one issue I find when people say “the latest version of .NET does not work in Visual Studio”, is because they haven’t downloaded the latest updates. I don’t care if a guide says “You only need version X.Y.Z” and you already have that. Obviously you need Visual Studio 2019, but no matter what anyone tells you about required versions, just be on the latest version.

You can check this by going to Help, then Check For Updates inside Visual Studio. The very latest version at the time of writing is 16.9.1, but again, download whatever version is available to you until it tells you you are up to date.

After installing the latest update, there is still one more feature flag to check. Go Tools -> Options, then select Preview Features as per the screenshot below. Make sure to tick the “Use previews of the .NET Core SDK”. Without this, Visual Studio will use the latest version of the .NET SDK installed, that is *not* a preview version. Obviously once .NET 6 is out of preview, you won’t need to do this, but if you are trying to play with the latest and greatest you will need this feature ticked.

After setting this, make sure to restart Visual Studio manually as it does not automatically do it for you. And you don’t want to be on the receiving end of your tech lead asking if you have “turned it off and on again” do you!

Migrating A Project To .NET 6

For the most part, Visual Studio will likely not create projects in .NET 6 by default when creating simple applications like console applications. This seems to vary but.. It certainly doesn’t for me. But that’s fine, all we have to do is edit our csproj file and change our target framework to net6.0 like so :

<TargetFramework>net6.0</TargetFramework>

If you build and you get the following :

The current .NET SDK does not support targeting .NET 6.0.  Either target .NET 5.0 or lower, or use a version of the .NET SDK that supports .NET 6.0

The first thing to check is

  1. Do you have the correct .NET 6 SDK installed. If not, install it.
  2. Is .NET 6 still in preview? Then make sure you have the latest version of Visual Studio *and* have the “Use previews of the .NET Core SDK” option ticked as per above.

And that’s it! You’re now all set up to use the juicy goodness of .NET 6, and all those early access features in preview versions you’ve been waiting for!

7 thoughts on “Getting Setup With .NET 6 Preview”

  1. Hi, I’m trying to use .Net framework 6.0 and installed it.
    I’m using Visual Studio version 16.9.2 and following are the specs of dotnet on my machine:

    dotnet –list-sdks
    3.1.407 [C:\Program Files\dotnet\sdk]
    5.0.201 [C:\Program Files\dotnet\sdk]
    6.0.100-preview.2.21155.3 [C:\Program Files\dotnet\sdk]

    dotnet –version
    6.0.100-preview.2.21155.3
    ——————————————————————-

    net6.0

    ————————————————————————————————
    I also checked the checkbox with the option to allow “use preview of the .Net core SDK” in tools and restarted + rebooted my system.

    But, I still get the following error. Kindly help me.

    Error NETSDK1045 The current .NET SDK does not support targeting .NET 6.0. Either target .NET 5.0 or lower, or use a version of the .NET SDK that supports .NET 6.0. testwasm2 C:\Program Files\dotnet\sdk\5.0.201\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.TargetFrameworkInference.targets 141

    Reply
      • No, I don’t have that file anywhere in the project. I’m trying to create a Blazor Web Assembly App. Also, I tried editing the .csproj file of the project and still gets the same error.

        Reply
        • Weird. Can you upload the project to Github or similar, and send me the link to wade [at] dotnetcoretutorials.com and let’s see if we can work it out.

          Reply
  2. I found a global.json file in the ‘repos’ folder which consisted of the Visual Studio project files and has the following code in it.

    {
    “sdk”: {
    “version”: “5.0.201”
    }
    }

    Please let me if I can directly edit the version to the 6.0 preview version.

    Reply
    • 100%. You can either remove this file, or you can make it “6.0.100-preview.2.21155.3” (However this then makes all your repos use that SDK). Alternatively, you can place a global.json in your actual project with the 6.0 SDK to force it to use the updated version.

      Reply

Leave a Comment