3

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.

Zhuravlev A.
  • 386
  • 4
  • 12
  • 2
    _"nuget package manager thinks I'm using .net50 instead of .net5.0?"_ -- look at the error message again. `"net50"` _is_ .NET 5.0. The nomenclature is confusing, but if you look at the plain English names, it should help you resolve the discrepancy. The error message tells you exactly the targeted runtime versions involved, and you're (apparently) trying to use a .NET Core (.NET Standard?) library with a .NET Framework assembly. – Peter Duniho Mar 01 '21 at 06:38
  • @PeterDuniho thanks but I clearly see what nuget tells: it tells that I use .NET Framework instead of .net. But as you can see I use project of .net5 version, NOT .NET Framework. – Zhuravlev A. Mar 01 '21 at 06:57

3 Answers3

1

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.

Zhuravlev A.
  • 386
  • 4
  • 12
1

had a similar error with dotnet-t4 not being compatible with .net6.

enter image description here

It was that environment variable MSBuildSDKsPath pointing to an old sdk .. fixing it manually to match the current sdk referenced in global.json fixed the issue

Ahmed Kotb
  • 6,269
  • 6
  • 33
  • 52
0

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.

Mr Qian
  • 21,064
  • 1
  • 31
  • 41
  • Thanks, I see that it can't be installed to vs project. But as I mentioned before, initially I tried to install package through windows cmd. Exactly as you recommended. It doesn't work on my machine. Even running cmd as admin. – Zhuravlev A. Mar 01 '21 at 09:45
  • Could you please share the error message with us? Or could powershell run the command? – Mr Qian Mar 01 '21 at 09:46
  • See the beginning of the post. "error NU1202: ..." – Zhuravlev A. Mar 01 '21 at 09:47
  • 1
    Try the following steps to troubleshoot the issue:1) close VS, delete global `nuget.config` file under `C:\Users\xxx\AppData\Roaming\NuGet` and then restart VS to re-generate the new file. 2) delete all cache files under `C:\Users\xxx\.nuget\packages`. After them, try to install it again. And do not fortget to add `--global` switch. – Mr Qian Mar 01 '21 at 09:52
  • I did actions as you recommended. Now after installing package cmd returns "package already installed". Well, ok, but after that, when I'm calling `dotnet tool electronize` (provided by installed package) then it says that another ALREADY installed package is not compatible: "Package ElectronNET.API 11.5.1 is not compatible with net50 (.NETFramework...". But Visual Studio builds project successfully. Then I figured out that cmd `dotnet build` fails with the same error. – Zhuravlev A. Mar 01 '21 at 20:33
  • Perry Qian-MSFT does your PATH environment variable contains paths to net5 sdk? – Zhuravlev A. Mar 02 '21 at 06:08
  • 1
    In my side, I only has the dotnet cli under PATH `C:\Program Files\dotnet\`. And please check if you have OS ENV `MSBuildSDKsPath` with a wrong path. Refer to [this link](https://stackoverflow.com/questions/63642470/vs2019-msbuild-sdkresolver-fails-to-run-when-using-c-sharp/63667373#63667373). Besides, when you type `dotnet --version`, does it show `5.0.103`? Another, please install the win10 sdk additionally and there is [a similar issue](https://stackoverflow.com/questions/49268779/the-reference-assemblies-for-framework-netcore-version-v5-0-were-not-found). – Mr Qian Mar 02 '21 at 08:10
  • 1
    Open CMD as Administrator and then run `dotnet tool uninstall --global ElectronNET.CLI`. Also, you can use `dotnet tool list --local` to check the `ElectronNET.CLI` tool package's info. And you can uninstall any info about it with Manifest under [this document](https://learn.microsoft.com/en-us/dotnet/core/tools/dotnet-tool-uninstall). I think you have to uninstall the local tool `ElectronNET.CLI`. My guess is that you have two version of it, one is on the local and another is on the global. You have to uninstall them all. And then install it into the global. – Mr Qian Mar 02 '21 at 08:17
  • Last, you can open control pane-->Programs and Features and then right-click on the related net core developer sdk-->Repair. – Mr Qian Mar 02 '21 at 08:18
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/229395/discussion-between-zhuravlev-a-and-perry-qian-msft). – Zhuravlev A. Mar 02 '21 at 13:12