简体   繁体   English

MySQL-> .NET Core依赖关系错误(MySql.Data)

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

We're trying to connect to a MySQL database through .NET Core. 我们正在尝试通过.NET Core连接到MySQL数据库。 Everything works local but on our server where gitlab-ci is running it fails building. 一切都在本地运行,但在运行gitlab-ci的服务器上,构建失败。 Therefore failing the build. 因此,构建失败。

The error thrown: error NU1001: The dependency MySql.Data >= 7.0.6-IR31 could not be resolved. 引发的错误: 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. 这很奇怪,因为它适用于我们的本地计算机,而不适用于在docker中运行的CI。

running dotnet restore and dotnet run locally works. 运行dotnet restoredotnet run本地运行。 dotnet restore works also on the server and you can see the MySql.Data package is installed. dotnet restore在服务器上也可以使用,您可以看到已安装MySql.Data软件包。 Yet when running the unittests it breaks because the dependency could not be resolved. 但是,在运行单元测试时,它会中断,因为无法解决依赖性。 Maybe not linux compatible? 也许与Linux不兼容?

What are we doing wrong? 我们做错了什么?

the project.json file: project.json文件:

{
  "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"
    ]
  }
}

In addition to Lajos Arpad i got curious and investigated a bit. 除了拉霍斯·阿尔帕德(Lajos Arpad),我还好奇并进行了一些调查。 It seems when installing dependencies on Windows it save the nuget package under the following path: packages\\MySql.Data.EntityFrameworkCore\\7.0.6-IR31 似乎在Windows上安装依赖项时,它将nuget包保存在以下路径下: 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 另一方面,在Linux上,它将在以下路径上安装软件包: 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 如在MySql.Data.EntityFrameworkCore的nuspec文件中声明的,版本定义为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. 当我使用dotnet restore命令还原软件包时,可以得出结论, dotnet restoredotnet restore方面做dotnet restore奇怪。 Changing the version in the nuspec file on Linux to 7.0.6-ir31 solved my problem. 将Linux上nuspec文件中的版本更改为7.0.6-ir31解决了我的问题。 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 链接到错误报告: https : //github.com/dotnet/cli/issues/5155

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 . 如果尚未在服务器上安装软件包和信息,则可以在这里获取: 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. .NET Frameworks有几个文件夹。 You need to make sure that the dll and xml files you need are there. 您需要确保所需的dll和xml文件在那里。

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). 我使用相同的软件包遇到了完全相同的问题(在Windows本地计算机上可以正常运行,当Jenkins在docker容器中运行dotnet restore和dotnet build时失败)。 Following on from Baklap4's answer, as part of the dockerfile I added the following line 从Baklap4的答案开始,作为dockerfile的一部分,我添加了以下行

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. 结果是将所有包还原到容器的“ packages”文件夹中,并且所有项目都知道要在该文件夹中查找它们。 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. 将这些文件夹重命名为大写。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM