我不明白我做错了什么。我正在尝试通过Windows命令提示符安装ElectronNET.CLI包(https://www.nuget.org/packages/ElectronNET.CLI):
dotnet tool install ElectronNET.CLI --version 11.5.1
但是我收到了错误消息:
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.
我的 .csproj 文件:
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>net5.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="ElectronNET.API" Version="11.5.1" />
</ItemGroup>
</Project>
我创建了global.json
文件,以覆盖我的SDK的全局版本。因为我尝试安装的包针对net5,当前项目版本是net5,但我的全局SDK版本是.net6。global.json:
{
"sdk": {
"version": "5.0.103"
}
}
什么原因导致 NuGet 包管理器认为我正在使用 .NET Framework 的 .net50 版本,而不是 .net5.0?我在哪里可以更改这个版本?
例如,当我创建另一个针对 netcore 3.1 版本的 c# 项目,并使用 ElectronNet API 和 CLI 的 9.31.2 版本时,一切都安装并运行良好。
更新:我使用 nuget.exe update -self 命令更新了 nuget.exe,但新版本仍然出现相同的错误。
更新2:我尝试通过 Visual Studio 安装 CLI 工具。消息更加令人困惑:
![enter image description here](https://istack.dev59.com/mh3zE.webp)
dotnet build
失败并显示相同的消息(package ... is not compatible
),但现在它说已经安装的nuget包ElectronNET.API 11.5.1与net50不兼容!同时,Visual Studio IDE成功构建并运行此项目(通过IIS Express)!只有当我尝试使用dotnet build
时,错误才会神奇地出现在IDE中:
![enter image description here](https://istack.dev59.com/fBRcX.webp)
找到了类似的问题https://developercommunity.visualstudio.com/t/error-msb4018-the-resolvepackagedependencies-task/1266042,但没有解决方案。
然后我基于.NET 5创建了一个新的干净的Blazor项目。Visual Studio成功构建它,但是dotnet build
却不行。它会显示以下信息:
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
根据此帖子 框架.NETCore,版本=v5.0的参考程序集未找到,我发现在
C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework
和C:\Program Files\Reference Assemblies\Microsoft\Framework
中都没有.net5文件夹。我重新安装了Visual Studio和net5,Sdk出现在C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETCore\v5.0
中,但构建错误仍然存在。显然,dotnet
将我的<TargetFramework>net5.0</TargetFramework>
视为net50(.NETFramework,版本=v5.0),我不知道为什么。