I have an older version of Visual Studio 2022 that came out with .NET 7. Due to system requirements reasons I cannot upgrade the Visual Studio 2022 to the most recent version that supports .NET 8.
I thus installed only the .NET 8 SDK and was hoping to use the 'msbuild' that comes with the older version of Visual Studio 2022 (.NET 7 - 17.6.5) to build my project targeting .NET 8.
Unfortunately when I run the msbuild command:
"C:\Program Files\Microsoft Visual Studio\2022\Community\MSBuild\Current\Bin\MSBuild.exe" "C:\Users\John\Desktop\Temp\BlazorApp1\BlazorApp1.sln" /property:Configuration=Debug
I get the following error:
error NETSDK1045: The current .NET SDK does not support targeting .NET 8.0. Either target .NET 7.0 or lower, or use a version of the .NET SDK that supports .NET 8.0
However, when I list my SDK using dotnet --list-sdks
I get:
2.1.4 [C:\Program Files\dotnet\sdk]
2.1.202 [C:\Program Files\dotnet\sdk]
2.1.401 [C:\Program Files\dotnet\sdk]
7.0.306 [C:\Program Files\dotnet\sdk]
8.0.302 [C:\Program Files\dotnet\sdk]
Why does msbuild
not see the installed sdk for .NET 8? Is it because it's the msbuild
that comes with Visual Studio 2022 for .NET 7? I know I could get the project to build using dotnet
and adding a global.json
file but unfortunately I can't use the dotnet
command, and must get msbuild
to build the project.
dotnet
tool has its own embedded copy of MSBuild.dotnet build
uses the embedded version anddotnet msbuild
is a pass-thru to the embedded MSBuild. If you have a workingmsbuild
command line, e.g.msbuild <something>
, you can change todotnet msbuild <something>
.