我有一些用Java编写的REST服务,我需要在ASP.NET中重写 . 我不习惯MS世界,但想想它有多难,对吧?

所以我去了Visual Studio 2017.创建了一个“ASP.NET核心Web应用程序(.NET Core)”项目 . 这似乎是正确的事情 .

开始为REST服务编写一些代码,但是当它集成MySQL时,问题就开始了 .

Dependendencies - >管理NuGet包 - >安装MySQL.Data 6.9.9生成:

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)
One or more packages are incompatible with .NETCoreApp,Version=v1.1.

哦,好好阅读MySQL Connetcor NET 7.x应该解决这个问题 . 在MySQL下载站点上寻找MySQL Connetcor NET 7.07 .

安装它并将C:\ Program Files(x86)\ MySQL \ MySQL Connector Net 7.0.7 \ Assemblies \ v4.5.1 \ MySql.Data.dll添加到项目依赖项 - >程序集 .

编译问题:

MySqlConnection con ...;
conn.Open();  <--------

错误CS0012类型“DbConnection”在未引用的程序集中定义 . 您必须添加对程序集'System.Data,Version = 4.0.0.0的引用

好的,所以添加:C:\ Program Files(x86)\ Reference Assemblies \ Microsoft \ Framework.NETFramework \ v4.0 \ System.Data.dll

同一行上的新错误:

Error   CS0012  The type 'Component' is defined in an assembly that is not referenced. You must add a reference to assembly 'System, Version=4.0.0.0

好的,所以添加:C:\ Program Files(x86)\ Reference Assemblies \ Microsoft \ Framework.NETFramework \ v4.0 \ System.dll

同一行上的新错误:

Error   CS0012  The type 'MarshalByRefObject' is defined in an assembly that is not referenced. You must add a reference to assembly'mscorlib, Version=4.0.0.0

好的,所以添加:C:\ Program Files(x86)\ Reference Assemblies \ Microsoft \ Framework.NETFramework \ v4.0 \ mscorlib.dll

现在,60个错误如:

Error   CS0518  Predefined type 'System.Void' is not defined or imported
Error   CS0518  Predefined type 'System.String' is not defined or imported
Error   CS0518  Predefined type 'System.Object' is not defined or imported

ARH!我在这里错过了什么?

我以为我导入了错误的库,所以我查看了:C:\ Program Files(x86)\ Reference Assemblies \ Microsoft \ Framework.NETCore \ v4.5

(注意.Netcore而不是.Netframework子目录)

但在这里:System.Data.dll是无法使用的 . 我猜System.Data.dll无法用于.NETCore?

任何帮助都会得到满足!如何从ASP.NetCore应用程序运行MySQL?

干杯!