升级到ASP.NET Core 2.0 - 包与netcoreapp2.0不兼容

32

我正在尝试升级到.NET Core 2.0,但是在所有已安装引用的包上都遇到了这些错误。

可能的问题:

输出中出现了对netcoreapp1.0的引用:

Microsoft.EntityFrameworkCore.Tools.DotNet 2.0.0包不兼容netcoreapp1.0 (.NETCoreApp, Version = v1.0)。 Microsoft.EntityFrameworkCore.Tools.DotNet 2.0.0支持:netcoreapp2.0 (.NETCoreApp,Version = v2.0) 一个或多个包与.NETCoreApp,Version = v1.0不兼容。 检测到的包:从2.1.1的Microsoft.ApplicationInsights.AspNetCore到2.0.0   Microsoft.AspNetCore.All (> = 2.0.0) -> Microsoft.AspNetCore.ApplicationInsights.HostingStartup (> = 2.0.0) -> Microsoft.ApplicationInsights.AspNetCore (> = 2.1. 1)   Application (> = 1.0.0) -> Microsoft.ApplicationInsights.AspNetCore (> = 2.0.0)

之后,我收到了所有组件的此消息:

Microsoft.AspNetCore.ANYPACKAGE 2.0.0包不兼容netcoreapp2.0 (.NETCoreApp, Version = v2.0)。Microsoft.AspNetCore.WebSockets 2.0.0包支持:netstandard2.0 (.NETStandard,Version = v2.0)

这是手册:

https://learn.microsoft.com/en-us/aspnet/core/migration/1x-to-2x/

SDK已更新为2.0:

enter image description here

这是我的csproj文件:

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

  <PropertyGroup>
    <TargetFramework>netcoreapp2.0</TargetFramework>
  </PropertyGroup>

  <PropertyGroup>
    <AssetTargetFallback>$(AssetTargetFallback);portable-net45+win8+wp8+wpa81;</AssetTargetFallback>
  </PropertyGroup>

  <ItemGroup>
    <Compile Remove="wwwroot\lib\kendo-ui-core\**" />
    <Content Remove="wwwroot\lib\kendo-ui-core\**" />
    <EmbeddedResource Remove="wwwroot\lib\kendo-ui-core\**" />
    <None Remove="wwwroot\lib\kendo-ui-core\**" />
  </ItemGroup>

  <ItemGroup>
    <Content Include="wwwroot\css\bootstrap-lumen.css" />
    <Content Include="wwwroot\css\bootstrap-sand.css" />
    <Content Include="wwwroot\css\bootstrap-sand.min.css" />
    <Content Include="wwwroot\js\application-role-index.js" />
    <Content Include="wwwroot\js\family-index.js" />
    <Content Include="wwwroot\js\jquery-3.2.1.min.js" />
    <Content Include="wwwroot\js\modal-action-store.js" />
    <Content Include="wwwroot\js\populate-district.js" />
    <Content Include="wwwroot\js\store-index.js" />
    <Content Include="wwwroot\js\type-index.js" />
    <Content Include="wwwroot\js\user-index.js" />
    <Content Include="wwwroot\js\jquery.filtertable.min.js" />
    <Content Include="wwwroot\js\machine-index.js" />
  </ItemGroup>
  <ItemGroup>
    <PackageReference Include="Bootstrap.v3.Datetimepicker" Version="4.17.45" />
    <PackageReference Include="Bootstrap.v3.Datetimepicker.CSS" Version="4.17.45" />
    <PackageReference Include="Microsoft.AspNetCore.All" Version="2.0.0" />
    <PackageReference Include="Microsoft.ApplicationInsights.AspNetCore" Version="2.0.0" />
    <PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="2.0.0" />
    <PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="2.0.0" />
    <PackageReference Include="Microsoft.VisualStudio.Web.CodeGenerators.Mvc" Version="2.0.0" />
    <PackageReference Include="Newtonsoft.Json" Version="10.0.3" />
    <PackageReference Include="NuGet.CommandLine" Version="4.1.0" />
  </ItemGroup>
  <ItemGroup>
    <DotNetCliToolReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Tools" Version="2.0.0" />
    <DotNetCliToolReference Include="Microsoft.EntityFrameworkCore.Tools.DotNet" Version="2.0.0" />
  </ItemGroup>

</Project>

提前感谢任何帮助。

编辑:更多信息

编译解决方案后,我收到了以下消息:

1>CSC:错误 CS1703:已导入具有等效标识的多个程序集:'C:\ Users \ user \.nuget \ packages \ microsoft.netcore.app \ 2.0.0 \ ref \ netcoreapp2.0 \ System.ComponentModel.dll'和'C:\ Users \ user \.nuget \ packages \ system.componentmodel \ 4.3.0 \ ref \ netstandard1.0 \ System.ComponentModel.dll'。 删除重复引用之一。


当您创建一个全新的.NET Core 2项目并添加EF时会发生什么? - TrevorBrooks
3个回答

39

此外,这个错误可能是由于使用过时的NuGet版本引起的。具体来说,版本4.0.0会出现此问题。将NuGet升级到4.3.0解决了我的问题。

VSTS代理似乎使用4.0.0版本,所以为了解决这个问题,可以在构建步骤中运行NuGet版本安装任务,以升级构建管道中运行的NuGet版本。


3
加入这个步骤后,问题得到解决。 - Maciek
2
你能详细说明一下任务是什么吗?我在TFS 2017.2中没有看到它。 - Daniel A. Thompson
@DanielA.Thompson,请添加 NuGet Tool Installer 任务,并将 Version of NuGet.exe to install 更改为相应的版本。 - giokoguashvili
本地 TFS 2017 也有同样的问题。构建代理默认使用 NuGet 4.0.0,即使在 Visual Studio 中使用了更高版本的 NuGet。 - nkr

21

通过将 Visual Studio 更新到最新版本(对我来说是15.3.3),解决了这个问题。

此外,请确保将 SDK 更新到2.0版本,NuGet 更新到最新版本。


4
SDK下载链接:https://github.com/dotnet/core/blob/master/release-notes/download-archives/2.0.0-download.md。 - GraehamF

-1

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接