无法解析“.NETCoreApp,Version=v2.1”的“Microsoft.NETCore.App(>= 2.1.0)”

zpjtge22  于 2023-10-21  发布在  .NET
关注(0)|答案(4)|浏览(114)

我尝试使用dotnet restore解析nugget包,但出现以下错误:
无法解析“.NETCoreApp,Version=v2.1”的“Microsoft.NETCore.App(>= 2.1.0)”
这是我的.csproj文件

<Project Sdk="Microsoft.NET.Sdk.Web">

  <PropertyGroup>
    <TargetFramework>netcoreapp2.1</TargetFramework>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="Autofac" Version="4.5.0" />
    <PackageReference Include="Autofac.Extensions.DependencyInjection" Version="4.1.0" />
    <PackageReference Include="Autofac.Extras.Moq" Version="4.2.0" />
    <PackageReference Include="BCrypt.Net-Core" Version="1.4.0" />
    <PackageReference Include="Easy.MessageHub" Version="3.2.1" />
    <PackageReference Include="hangfire" Version="1.6.17" />
    <PackageReference Include="Hangfire.MemoryStorage" Version="1.5.2" />
    <PackageReference Include="Microsoft.AspNetCore.App" Version="2.1.0-rc1-final" />
    <PackageReference Include="Microsoft.AspNetCore.Mvc" Version="2.1.0-rc1-final" />
    <PackageReference Include="Microsoft.Extensions.Configuration" Version="2.1.0-rc1-final" />
    <PackageReference Include="MongoDB.Driver" Version="2.4.4" />
    <PackageReference Include="Swashbuckle.AspNetCore" Version="1.1.0" />
    <PackageReference Include="System.Runtime.Extensions" Version="4.3.0" />
  </ItemGroup>

  <Target Name="ApplyXdtConfigTransform" BeforeTargets="_TransformWebConfig">
    <PropertyGroup>
      <_SourceWebConfig>$(MSBuildThisFileDirectory)Web.config</_SourceWebConfig>
      <_XdtTransform>$(MSBuildThisFileDirectory)Web.$(Configuration).config</_XdtTransform>
      <_TargetWebConfig>$(PublishDir)Web.config</_TargetWebConfig>
    </PropertyGroup>
    <Exec Command="dotnet transform-xdt --xml &quot;$(_SourceWebConfig)&quot; --transform &quot;$(_XdtTransform)&quot; --output &quot;$(_TargetWebConfig)&quot;" Condition="Exists('$(_XdtTransform)')" />
  </Target>
</Project>

我已经安装了dotnet-sdk-2.1.300-rc 1 -008673-win-x64,我正在使用Visual Studio 2017 v15.2

f0brbegy

f0brbegy1#

更新位于以下位置的nuget.config文件:

C:\Users\{username}\AppData\Roaming\NuGet\nuget.config

您需要像这样添加v3端点:

<configuration>
  <packageSources>
    <add key="nuget.org" value="https://api.nuget.org/v3/index.json" protocolVersion="3" />
    <add key="nuget.org" value="https://www.nuget.org/api/v2/" />   
    </packageSources>
sczxawaw

sczxawaw2#

您可以通过dotnet插件添加v3 nuget源代码:

dotnet nuget add source --name nuget.org https://api.nuget.org/v3/index.json

如果这不起作用,请尝试运行清除本地缓存:

dotnet nuget locals all --clear
dotnet restore --force

进一步阅读

tf7tbtn2

tf7tbtn23#

问题是Visual Studio版本。
解决方案是创建指向dotnet\sdk{{version}}\Sdks的MSBuildSdksPath环境变量,如以下链接https://github.com/aspnet/Announcements/issues/231所示

m3eecexj

m3eecexj4#

我在.net core 3.1.0中的项目也遇到了同样的问题,以下是步骤
dotnet nuget locals all --clear dotnet restore --force

相关问题