Error installing dotnet tool package because "it is not compatible with net50"

Viewed 5744

I can't understand what I'm doing wrong. I'm trying to install ElectronNET.CLI package (https://www.nuget.org/packages/ElectronNET.CLI) through windows cmd:

dotnet tool install ElectronNET.CLI --version 11.5.1

but I've got error message:

error NU1202: Package ElectronNET.CLI 11.5.1 is not compatible with net50
(.NETFramework,Version=v5.0) / any. 
Package ElectronNET.CLI 11.5.1 supports: net5.0 (.NETCoreApp,Version=v5.0) / any
The tool package could not be restored.
Tool 'electronnet.cli' failed to install. This failure may have been caused by:

* You are attempting to install a preview release and did not use the --version
option to specify the version.
* A package by this name was found, but it was not a .NET tool.
* The required NuGet feed cannot be accessed, perhaps because of an Internet con
nection problem.
* You mistyped the name of the tool.

My .csproj file:

<Project Sdk="Microsoft.NET.Sdk.Web">    
  <PropertyGroup>
    <TargetFramework>net5.0</TargetFramework>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="ElectronNET.API" Version="11.5.1" />
  </ItemGroup>    
</Project>

Also I've created global.json file to override my sdk's global version. Because the package I'm trying to install targets net5, and current project version is net5, but my global sdk version is .net6. global.json:

{
    "sdk": {
        "version": "5.0.103"
    }
}

What are the reasons describing that nuget package manager thinks I'm using .net50 (.NET Framework) instead of .net5.0? How and where can I change this version?

For instance, when I created another c# project with .netcore 3.1 version and ElectronNet API and CLI of 9.31.2 versions (that targets netcore 3.1), everything was installed and worked fine.

UPD: I updated nuget.exe using nuget.exe update -self, but the new version works the same way with the same error.

UPD2: Tried to instal cli tool through visual studio. The message is much more confusing: enter image description here

UPD3: I removed net6 preview sdk from my computer, updated visual studio to 16.8.6 (and then did a "repair" of IDE through vs installer). I cleared nuget cache. Seems that cli tool that I tried to install now is installed, but now cmd dotnet build failed with the same message (package ... is not compatible) but now it says that already installed nuget package ElectronNET.API 11.5.1 is not compatible with net50! At the same time Visual Studio IDE successfully builds and runs this project (through IIS Express)! Only when I'm trying to use dotnet build then errors are miraculously appearing in the IDE: enter image description here

Found similar problem https://developercommunity.visualstudio.com/t/error-msb4018-the-resolvepackagedependencies-task/1266042, but there are no solutions.

Then I created a new clean blazor project based on .net5. Visual Studio successfully builds it, but dotnet build no. It says:

C:\Program Files\dotnet\sdk\5.0.103\Microsoft.Common.CurrentVersion.targets(1180,5): 
error MSB3644: The reference assemblies for .NETFramework,Version=v5.0 were not found. 
To resolve this, install the Developer Pack (SDK/Targeting Pack) for this
framework version or retarget your application. You can download .NET Framework
Developer Packs at https://aka.ms/msbuild/developerpacks

What a nice surprise. According to this post The reference assemblies for framework .NETCore, Version=v5.0 were not found I've noticed that I have no .net5 folder neither in C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework nor in C:\Program Files\Reference Assemblies\Microsoft\Framework. I reinstalled visual studio along with net5. Sdk appeared in C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETCore\v5.0, but build error is the same. Obviously dotnet treats my <TargetFramework>net5.0</TargetFramework> as net50 (.NETFramework,Version=v5.0) and I don't know why.

2 Answers

Well it's not a workaround in general, but maybe it can helps someone. I built my project successfully, but dotnet.exe on my computer still behaviors very strange and unstable, I mean sometimes project still not building. I used the following advises of Perry Qian-MSFT:

  • deleted global nuget.config
  • removed all nuget cache files
  • reinstalled, repaired, restarted visual studio and .net5 sdk
  • installed ElectronNET.CLI globally instead of locally
  • set the MSBuildSDKsPath variable value to .net5 sdk folder (note: this variable was absent in my environment variables)
  • rebooted Windows periodically (I have Windows 7)

None of these steps helped. Then I tried to create sample project far away from my working folder and - cheers - dotnet build successfully built new .net5.0 project. Then I tried to move whole my working folder in different directories and after some fail variants it accidentally built successfully. Then I moved folder some more times, sometimes moving project was built successfully, sometimes not. At the end I moved my working folder back to project, convinced that it working and committed changes.

P.S.: Seems I need a new version of Windows... Thanks Perry Qian-MSFT for advices.

That is not a nuget package for vs projects but a package for dotnet cli tool.

So the right way to install it is to use cmd to install it into global dotnet cli.

1) Run CMD as Administrator

2) run the command to install it:

enter image description here

dotnet tool install --global ElectronNET.CLI --version 11.5.1

enter image description here

Besides, there is a similar issue about it.

Related