How to resolve the errors when Nugets need to be downgraded

41 views Asked by At

My computer is using .NET 6, while another developer is using .NET 8.

I got his code and I am getting this error now

System.IO.DirectoryNotFoundException:
'C:\Users\xyz.nuget\packages\mudblazor\6.0.2\staticwebassets'

I googled to fix this issue and realized that these nuget packages are for .NET 8, while my computer is on .NET 6:

enter image description here

When I try to update, I get this error

Error NU1202
Package Microsoft.AspNetCore.Components.Authorization 8.0.3 is not compatible with net6.0 (.NETCoreApp,Version=v6.0) / browser-wasm. Package Microsoft.AspNetCore.Components.Authorization 8.0.3 supports: net8.0 (.NETCoreApp,Version=v8.0)

How to resolve this issue with keeping my .NET 6 ?

1

There are 1 answers

0
Bip901 On BEST ANSWER

When a C# project targets a .NET version, it uses some features that are new to that version. Thus, all developers have to use that .NET SDK or newer.

You have 3 possible solutions:

Downgrade the project to .NET 6

Replace the <TargetFramework>net8.0</TargetFramework> tag in your ProjectNameHere.csproj file with <TargetFramework>net6.0</TargetFramework>

Upgrade your setup to .NET 8

You can't update a single component to .NET 8 while the rest of your computer is running .NET 6. Download and install .NET 8 from the linked Microsoft page.

Target both .NET 6 and 8 side-by-side

C# supports targeting multiple .NET version simultaneously with the TargetFrameworks tag.

You'd get 2 different version of your executable, one for each platform.

Note, however, that every time you use a .NET-8-only feature, you'd have to guard it with a precompiler condition:

#if NET8_0_OR_GREATER
  //... some .net8 specific code
#endif