MySQL -> .NET Core Dependency error (MySql.Data)

2019-09-08 03:23发布

问题:

We're trying to connect to a MySQL database through .NET Core. Everything works local but on our server where gitlab-ci is running it fails building. Therefore failing the build.

The error thrown: error NU1001: The dependency MySql.Data >= 7.0.6-IR31 could not be resolved. This is weird since it works on our local machines, but not on the CI running within docker.

running dotnet restore and dotnet run locally works. dotnet restore works also on the server and you can see the MySql.Data package is installed. Yet when running the unittests it breaks because the dependency could not be resolved. Maybe not linux compatible?

What are we doing wrong?

the project.json file:

{
  "dependencies": {
    "Microsoft.NETCore.App": {
      "version": "1.0.0",
      "type": "platform"
    },
    "Microsoft.AspNetCore.Mvc": "1.0.0",
    "Microsoft.AspNetCore.Server.Kestrel": "1.0.0",
    "Microsoft.AspNetCore.Diagnostics": "1.0.0",
    "Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore": "1.0.0",
    "Microsoft.Extensions.Configuration": "1.0.0",
    "Microsoft.Extensions.Configuration.CommandLine": "1.0.0",
    "Microsoft.Extensions.Configuration.Binder": "1.0.0",
    "Microsoft.Extensions.Configuration.EnvironmentVariables": "1.0.0",
    "Microsoft.Extensions.Configuration.Json": "1.0.0",
    "Microsoft.Extensions.Configuration.FileExtensions": "1.0.0",
    "Microsoft.Extensions.Logging": "1.0.0",
    "Microsoft.Extensions.Logging.Console": "1.0.0",
    "Microsoft.Extensions.Logging.Debug": "1.0.0",
    "Microsoft.Extensions.Options.ConfigurationExtensions": "1.0.0",
    "Microsoft.EntityFrameworkCore": "1.0.0",
    "DotNetAirbrake": "1.0.33",
    "Geitenbelang.AnimalManager.Api.Models": "1.0.0-*",
    "Geitenbelang.AnimalManager.Api.Database": "1.0.0-*",
    "AutoMapper": "5.1.1",
    "MySql.Data.EntityFrameworkCore": "7.0.6-IR31"
  },

  "frameworks": {
    "netcoreapp1.0": {}
  },

  "buildOptions": {
    "emitEntryPoint": true,
    "preserveCompilationContext": true
  },

  "runtimeOptions": {
    "configProperties": {
      "System.GC.Server": true
    }
  },

  "publishOptions": {
    "include": [
      "wwwroot",
      "Views",
      "Areas/**/Views",
      "appsettings.json",
      "web.config"
    ]
  }
}

回答1:

In addition to Lajos Arpad i got curious and investigated a bit. It seems when installing dependencies on Windows it save the nuget package under the following path: packages\MySql.Data.EntityFrameworkCore\7.0.6-IR31

On Linux on the other hand it installs the package on this path: packages\MySql.Data.EntityFrameworkCore\7.0.6-ir31

As declared in the nuspec file of MySql.Data.EntityFrameworkCore the version is defined as 7.0.6-IR31

As i restore the packages with the command dotnet restore can I conclude dotnet restore is doing some weird shit regarding restoring. Changing the version in the nuspec file on Linux to 7.0.6-ir31 solved my problem. As this is a bug (not respecting capitals in version) i'm going to fill out a bug report.

Link to bugreport: https://github.com/dotnet/cli/issues/5155



回答2:

Recently I had a similar problem with another dependency. After a long process of torture I realized that the dependency need to be installed via an installer, or if that is not possible in your case, then you can copy. Here you can get the package and information if this is not installed on the server yet: https://www.nuget.org/packages/MySql.Data.EntityFrameworkCore/7.0.6-IR31.

At this folder

c:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\

you have several folders with .NET Frameworks. You need to make sure that the dll and xml files you need are there.



回答3:

I ran into exactly the same issue with the same package (works fine on my Windows machine locally, fails when Jenkins runs dotnet restore and dotnet build in a docker container). Following on from Baklap4's answer, as part of the dockerfile I added the following line

RUN echo "{ \"packages\": \"packages\" }" >> global.json

in combination with

RUN dotnet restore --packages "packages"

resulting in it restoring all packages into the container's "packages" folder, and all projects within knowing to look for them in that folder. Once I know where the packages are I can run

RUN mv MySql.Data/7.0.6-ir31 MySql.Data/7.0.6-IR31
RUN mv MySql.Data.EntityFrameworkCore/7.0.6-ir31   MySql.Data.EntityFrameworkCore/7.0.6-IR31

to rename those folders to uppercase.