这是我的csproj
目标net6.0
:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="HtmlAgilityPack" Version="1.11.45" />
<PackageReference Include="System.Drawing.Common" Version="6.0.0" />
</ItemGroup>
</Project>
它需要两个库HtmlAgilityPack和System.Drawing.Common。两者都兼容.Net 6.0(根据nuget(。在本地,我安装了用于net6.0:的.NET SDK
dotnet --info
.NET SDK (reflecting any global.json):
Version: 6.0.400
Commit: 7771abd614
Runtime Environment:
OS Name: Windows
OS Version: 10.0.19043
OS Platform: Windows
RID: win10-x64
Base Path: C:Program Filesdotnetsdk6.0.400
global.json file:
Not found
Host:
Version: 6.0.8
Architecture: x64
Commit: 55fb7ef977
.NET SDKs installed:
6.0.400 [C:Program Filesdotnetsdk]
.NET runtimes installed:
Microsoft.AspNetCore.App 6.0.8 [C:Program FilesdotnetsharedMicrosoft.AspNetCore.App]
Microsoft.NETCore.App 6.0.8 [C:Program FilesdotnetsharedMicrosoft.NETCore.App]
Microsoft.WindowsDesktop.App 6.0.8 [C:Program FilesdotnetsharedMicrosoft.WindowsDesktop.App]
然而,当我运行dotnet restore
时,我得到了这个错误:
Determining projects to restore...
C:Repostesttest.csproj : error NU1100: Unable to resolve 'HtmlAgilityPack (>= 1.11.45)' for 'net6.0'.
C:Repostesttest.csproj : error NU1100: Unable to resolve 'System.Drawing.Common (>= 6.0.0)' for 'net6.0'.
Failed to restore C:Repostesttest.csproj (in 104 ms).
我在这里错过了什么?我认为dotnet restore
应该没有错误地完成。
根据@PMF的建议。
- 运行
dotnet restore -v detailed
,得到相同的错误 - 从输出中找到全局
nuget.config
文件(C:UsersadminAppDataRoamingNuGetNuGet.Config
( - 已检查配置:
<?xml version="1.0"?>
<configuration>
<packageSources>
</packageSources>
</configuration>
- 添加了nuget:
<?xml version="1.0"?>
<configuration>
<packageSources>
<add key="NuGet" value="https://api.nuget.org/v3/index.json" />
</packageSources>
</configuration>
之后dotnet restore
按预期工作。