无法将MySQL Data Nuget包添加到ASP Core Project

时间:2017-09-19 09:48:30

标签: mysql asp.net asp.net-core visual-studio-mac

我正在尝试将MySQL Data Nuget包添加到我的ASP Web Core项目中,但是我收到此错误:

  

一个或多个软件包与.NETCoreApp,Version = v1.1(win-x86)不兼容。

我正在使用Visual Studio for Mac。这是我得到的完整错误日志:

Running non-parallel restore.
Reading project file /Users/dk/Documents/HM/Backend/HMBackend/HMBackend/HMBackend.csproj.
Restoring packages for /Users/dk/Documents/HM/Backend/HMBackend/HMBackend/HMBackend.csproj...
Restoring packages for .NETCoreApp,Version=v1.1...
Resolving conflicts for .NETCoreApp,Version=v1.1...
Scanning packages for runtime.json files...
Merging in runtimes defined in package/Microsoft.NETCore.DotNetHostPolicy 1.1.0.
Merging in runtimes defined in package/Microsoft.NETCore.Runtime.CoreCLR 1.1.1.
Merging in runtimes defined in package/Microsoft.NETCore.Platforms 1.1.0.
Merging in runtimes defined in package/Microsoft.NETCore.DotNetHostResolver 1.1.0.
Merging in runtimes defined in package/Microsoft.NETCore.Jit 1.1.1.
Merging in runtimes defined in package/Microsoft.NETCore.Windows.ApiSets 1.0.1.
Merging in runtimes defined in package/Microsoft.NETCore.Targets 1.1.0.
Merging in runtimes defined in package/Microsoft.NETCore.DotNetHost 1.1.0.
Restoring packages for .NETCoreApp,Version=v1.1 (win)...
Resolving conflicts for .NETCoreApp,Version=v1.1 (win)...
Restoring packages for .NETCoreApp,Version=v1.1 (win-x64)...
Resolving conflicts for .NETCoreApp,Version=v1.1 (win-x64)...
Restoring packages for .NETCoreApp,Version=v1.1 (win-x86)...
Resolving conflicts for .NETCoreApp,Version=v1.1 (win-x86)...
Checking compatibility of packages on .NETCoreApp,Version=v1.1.
Checking compatibility for HMBackend 1.0.0 with .NETCoreApp,Version=v1.1.
Checking compatibility for MySql.Data 6.9.9 with .NETCoreApp,Version=v1.1.
Package MySql.Data 6.9.9 is not compatible with netcoreapp1.1 (.NETCoreApp,Version=v1.1). Package MySql.Data 6.9.9 supports:
  - net40 (.NETFramework,Version=v4.0)
  - net45 (.NETFramework,Version=v4.5)
Checking compatibility for System.Diagnostics.FileVersionInfo 4.0.0 with .NETCoreApp,Version=v1.1 (win-x86).
Checking compatibility for System.Xml.XPath.XDocument 4.0.1 with .NETCoreApp,Version=v1.1 (win-x86).
Checking compatibility for runtime.any.System.Reflection.Extensions 4.3.0 with .NETCoreApp,Version=v1.1 (win-x86).
Checking compatibility for runtime.any.System.Reflection.Primitives 4.3.0 with .NETCoreApp,Version=v1.1 (win-x86).
Checking compatibility for Microsoft.NETCore.DotNetHost 1.1.0 with .NETCoreApp,Version=v1.1 (win-x86).
Checking compatibility for runtime.win.System.Console 4.3.0 with .NETCoreApp,Version=v1.1 (win-x86).
Checking compatibility for runtime.any.System.Diagnostics.Tools 4.3.0 with .NETCoreApp,Version=v1.1 (win-x86).
Checking compatibility for Microsoft.AspNetCore.Cryptography.Internal 1.1.2 with .NETCoreApp,Version=v1.1 (win-x86).
Checking compatibility for Microsoft.AspNetCore.DataProtection.Abstractions 1.1.2 with .NETCoreApp,Version=v1.1 (win-x86).
One or more packages are incompatible with .NETCoreApp,Version=v1.1 (win-x86).
Incompatible packages: 1
Package restore failed. Rolling back package changes for 'HMBackend'.

这是我的.csproj的样子:

<?xml version="1.0" encoding="UTF-8"?>
<Project Sdk="Microsoft.NET.Sdk.Web">
    <PropertyGroup>
        <TargetFramework>netcoreapp1.1</TargetFramework>
    </PropertyGroup>
    <ItemGroup>
        <Folder Include="wwwroot\" />
        <Folder Include="DAO\" />
        <Folder Include="Model\" />
        <Folder Include="Helpers\" />
    </ItemGroup>
    <ItemGroup>
        <PackageReference Include="Microsoft.AspNetCore" Version="1.1.2" />
        <PackageReference Include="Microsoft.AspNetCore.Mvc" Version="1.1.3" />
        <PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="1.1.2" />
        <PackageReference Include="System.Data.SqlClient" Version="4.3.1" />
        <PackageReference Include="Newtonsoft.Json" Version="10.0.3" />
        <PackageReference Include="System.Net.Http" Version="4.3.2" />
        <PackageReference Include="Microsoft.AspNetCore.Mvc.Versioning" Version="1.2.0" />
    </ItemGroup>
    <ItemGroup>
        <Compile Remove="Model\ResponseCallBack.cs" />
    </ItemGroup>
</Project>

如何解决此错误?

1 个答案:

答案 0 :(得分:1)

从NuGet输出:

Package MySql.Data 6.9.9 is not compatible with netcoreapp1.1 (.NETCoreApp,Version=v1.1). Package MySql.Data 6.9.9 supports: - net40 (.NETFramework,Version=v4.0) - net45 (.NETFramework,Version=v4.5)

MySql.Data NuGet包中包含.NET 4.0和4.5的程序集。您不能在.NET Core 1.1项目中使用它们。

选项:

  1. 查找另一个支持.NET Standard,PCL或.NET Core的MySql NuGet包或库。例如MySqlConnector
  2. 将项目更改为目标.NET Core 2.0。
    • 需要测试MySql.Data NuGet包以确定它是否与.NET Core 2.0兼容。虽然您可以使用从.NET Core 2.0项目中定位.NET的NuGet包,但不能保证程序集能够正常工作,因为它可能正在使用.NET Core 2.0不支持的某些API。