The current .NET SDK does not support targeting .NET Core 6.0. Brand new WPF Project VS Community 2022 17.9.5

46 views Asked by At

I had been working on a WPF project for several weeks, using VS 2022 17.9.2, targeting .Net 6.0, with no problems. Out of nowhere today, upon opening, I received a slate of errors relating to Could not find InitializeComponent() ... for a couple custom WPF controls. Ran through namespace checks, etc., searched the error, and couldn't resolve. Nothing had changed so I wasn't sure what else to check (no updates, etc.).

Decided to try updating VS after finding a couple old threads with similar unresolved problems. Updated to VS 2022 17.9.5. Now I receive the following error:

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

enter image description here

Tried opening a brand-new WPF project and I get the same error right off the bat. Used the Repair option in VS installer, no changes.

Tried changing the target framework in Properties and these are the only options available now:

enter image description here

If I try to select any of them, it returns to a blank selection.

I get the same error if I create a new WinUI3 project.

Really not sure where to even begin. The errors came out of nowhere as far as I can tell - I was working this morning without issue, didn't even restart my system (much less update anything, etc.), and upon opening the project in the afternoon, started receiving the initial errors. Seems to have happened between closing VS in the morning and opening it in the afternoon.

I had found a couple old threads with similar errors but they all seem to relate to VS 2019 not supporting .Net 6 and I am absolutely working in VS 2022.

Thank you for any input... I'm not an expert so if there's anything required to diagnose this problem I would be happy to provide it if asked.

EDIT

Tried a complete reinstall as noted below - it APPEARED to fix things but it did not in fact.

Completely reinstalled (2022, 17.9.5), selected all additional individual components/frameworks. Pulled the .NET SDK downloader from the MS website and ran Repair separately, no effect.

I can create a WPF solution and target .NET 5.0 initially, and things appear fine. If I target .NET 6.0 or higher, I get the same errors.

In addition, I am unable to change any settings (Application -> General)... Target Framework is blank, I get the same options as before (.NET 5.0, Core 3.0, Core 3.1), but selecting any option just results in the field going blank again (same thing for any other field I try changing).

I get the same error for all other project types now too - WinUI3, ASP.NET Web app, etc. Anything that targets .NET 6.0 or higher is throwing the error.

I also do not understand the error syntax; There is no .NET CORE 8.0 (or 6.0 or 5.0, etc). Why is it referring to these versions of .NET as Core?

This is extremely confusing and is preventing me from doing any work at all... any input or suggestions or requirements for additional information would be greatly appreciated.

EDIT

Based on this: https://learn.microsoft.com/en-us/dotnet/core/tools/sdk-errors/netsdk1045?source=recommendations

Ran command dotnet --list-sdks and received:

5.0.100 [C:\Program Files (x86)\dotnet\sdk] as the only output.

If I manually check Program Files (x86)\dotnet\sdk then that's the only SDK shown, but in Program Files\dotnet\sdk I can see 8.0.202 there.

Most of the other Questions/Answers for similar problems seem to relate to the global.json file issue, but that doesn't look like it is applicable to this problem, since VS doesn't believe any of these other frameworks exist, AFAIK.

EDIT

Found the separate for whatever reason .NET 8.0 SDK (not framework) installer and ran that. No effect. dotnet --info still only sees the 5.0 SDK.

[1]: https://i.stack.imgur.com/81Sna.png

EDIT

Manually reinstalled the .NET 6.0 SDK (x86) from github and that seems to have fixed the issue, but I still don't know why it happened to begin with, and why it would require me to run the standalone SDK installer outside of VS... Common sense would say that the SDKs would be installed/included with the runtime, as there are no separate options in the installer for just the SDKs.

https://github.com/dotnet/core/blob/main/release-notes/6.0/6.0.28/6.0.28.md?WT.mc_id=dotnet-35129-website

1

There are 1 answers

2
Barta On

Try uninstalling Visual Studio, then reinstalling it. And make sure you choose to download the .net 6 runtime from the 'individual components tab'. And also .net desktop dev for wpf.