Linux 将带有类库的.Net核心MVC应用程序部署到Ubuntu 16.04:
我想构建一个简单的.net core MVC应用程序,其中包含一个用于数据访问的类库,以了解如何在Linux上构建/部署/运行core。不像我希望的那么简单 编辑:如果有人感兴趣,这里有一份解决方案: 我组装了一个VirtualBox VM,带有Ubuntu服务器16.04,并按照以下说明安装了dotnet core: 我在VS 2015的主机(Win10)上安装了所有最新的必要位,并创建了一个带有MVC应用程序和名为“DataAccess”的单一类库的解决方案。这是EF Core使用他们最新的核心提供商与MySQL对话。当我运行/调试它时,它在Win10主机上完美地运行。调出数据,看起来很棒 主机和虚拟机上的“dotnet--version”提供了: 1.0.0-preview2-003121 但是,当我将其部署到Ubuntu VM时,在类库依赖项上出现以下错误:Linux 将带有类库的.Net核心MVC应用程序部署到Ubuntu 16.04:,linux,ubuntu,asp.net-core,asp.net-core-mvc,Linux,Ubuntu,Asp.net Core,Asp.net Core Mvc,我想构建一个简单的.net core MVC应用程序,其中包含一个用于数据访问的类库,以了解如何在Linux上构建/部署/运行core。不像我希望的那么简单 编辑:如果有人感兴趣,这里有一份解决方案: 我组装了一个VirtualBox VM,带有Ubuntu服务器16.04,并按照以下说明安装了dotnet core: 我在VS 2015的主机(Win10)上安装了所有最新的必要位,并创建了一个带有MVC应用程序和名为“DataAccess”的单一类库的解决方案。这是EF Core使用他们最
Project corecrossplatform (.NETCoreApp,Version=v1.0) will be compiled because the version or bitness of the CLI changed since the last build
Compiling corecrossplatform for .NETCoreApp,Version=v1.0
/opt/dotnet/corecrossplatform/project.json(24,23): error NU1002: The dependency DataAccess does not support framework .NETCoreApp,Version=v1.0.
Compilation failed.
0 Warning(s)
1 Error(s)
Time elapsed 00:00:00.0187782
Project CoreCrossPlatformFlat (.NETCoreApp,Version=v1.0) will be compiled because the version or bitness of the CLI changed since the last build
Compiling CoreCrossPlatformFlat for .NETCoreApp,Version=v1.0
/opt/dotnet/corecrossplatform/src/CoreCrossPlatformFlat/project.json(25,52): error NU1001: The dependency MySql.Data.EntityFrameworkCore >= 7.0.4-IR-191 could not be resolved.
Compilation failed.
0 Warning(s)
1 Error(s)
无论我运行“dotnet还原”还是“dotnet运行”,都会发生这种情况。说实话,我甚至不确定我是否正确部署了这个东西。文档不完整,我在猜测。我将项目文件夹“src\corecrossform”(包含bin、Program.cs、appsettings.json等)中的所有内容复制到VM上,这就是我在VM中执行“dotnet”命令的地方
DataAccess.json文件:
{
"version": "1.0.0-*",
"dependencies": {
"Microsoft.EntityFrameworkCore": "1.0.0",
"MySql.Data.Core": "7.0.4-IR-191",
"MySql.Data.EntityFrameworkCore": "7.0.4-IR-191",
"NETStandard.Library": "1.6.0"
},
"frameworks": {
"netstandard1.6": {
"imports": "dnxcore50"
}
}
}
MVC project.json:
{
"dependencies": {
"Microsoft.NETCore.App": {
"version": "1.0.0",
"type": "platform"
},
"Microsoft.AspNetCore.Diagnostics": "1.0.0",
"Microsoft.AspNetCore.Mvc": "1.0.0",
"Microsoft.AspNetCore.Razor.Tools": {
"version": "1.0.0-preview2-final",
"type": "build"
},
"Microsoft.AspNetCore.Server.IISIntegration": "1.0.0",
"Microsoft.AspNetCore.Server.Kestrel": "1.0.0",
"Microsoft.AspNetCore.StaticFiles": "1.0.0",
"Microsoft.Extensions.Configuration.EnvironmentVariables": "1.0.0",
"Microsoft.Extensions.Configuration.Json": "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.VisualStudio.Web.BrowserLink.Loader": "14.0.0",
"DataAccess": "1.0.0-*"
},
"tools": {
"BundlerMinifier.Core": "2.0.238",
"Microsoft.AspNetCore.Razor.Tools": "1.0.0-preview2-final",
"Microsoft.AspNetCore.Server.IISIntegration.Tools": "1.0.0-preview2-final"
},
"frameworks": {
"netcoreapp1.0": {
"imports": [
"dotnet5.6",
"portable-net45+win8"
]
}
},
"buildOptions": {
"emitEntryPoint": true,
"preserveCompilationContext": true
},
"runtimeOptions": {
"configProperties": {
"System.GC.Server": true
}
},
"publishOptions": {
"include": [
"wwwroot",
"Views",
"Areas/**/Views",
"appsettings.json",
"web.config"
]
},
"scripts": {
"prepublish": [ "bower install", "dotnet bundle" ],
"postpublish": [ "dotnet publish-iis --publish-folder %publish:OutputPath% --framework %publish:FullTargetFramework%" ]
}
}
需要注意的是:当我使用“dotnetnew”运行示例项目并恢复时,通过上面的教程链接运行,它运行良好
我错过了什么?另一个附带问题:将此类应用程序发布到Linux机箱的最佳方式是什么?我在这一点上接近了吗
多谢
编辑:整个下午我都在踢这匹死马,我比较了我在网上找到的一些与“NU1002”错误相关的注释,并生成了示例项目“dotnet new”。我尝试将project.json文件(MVC和classlib)的“framework”部分更改为以下内容,但没有成功…相同的错误:
"frameworks": {
"netcoreapp1.0": {
"dependencies": {
"Microsoft.NETCore.App": {
"type": "platform",
"version": "1.0.0"
}
},
"imports": [
"dnxcore50",
"dotnet5.6",
"portable-net45+win8"
]
}
}
编辑:非常感谢goaty:正如他在评论中指出的那样,复制整个解决方案并构建它,最终成功构建。但是,我无法运行它而不出错。它似乎无法恢复MySQL EF核心依赖项:
Project corecrossplatform (.NETCoreApp,Version=v1.0) will be compiled because the version or bitness of the CLI changed since the last build
Compiling corecrossplatform for .NETCoreApp,Version=v1.0
/opt/dotnet/corecrossplatform/project.json(24,23): error NU1002: The dependency DataAccess does not support framework .NETCoreApp,Version=v1.0.
Compilation failed.
0 Warning(s)
1 Error(s)
Time elapsed 00:00:00.0187782
Project CoreCrossPlatformFlat (.NETCoreApp,Version=v1.0) will be compiled because the version or bitness of the CLI changed since the last build
Compiling CoreCrossPlatformFlat for .NETCoreApp,Version=v1.0
/opt/dotnet/corecrossplatform/src/CoreCrossPlatformFlat/project.json(25,52): error NU1001: The dependency MySql.Data.EntityFrameworkCore >= 7.0.4-IR-191 could not be resolved.
Compilation failed.
0 Warning(s)
1 Error(s)
DataAccess
库存在于src/目录之外。因此,web项目无法找到引用。
我推荐这种结构
src/
|---DataAccess/
|---CoreCrossPlatform/
希望有帮助:)我刚刚查看了您的解决方案。看起来在src/corecrossform文件夹中只有web项目。类库不在那里?@goaty-真奇怪。可能根本就没有拉链?重新提供了一份新的副本。谢谢。你的新上传说访问被拒绝:)@goaty-Ha!哇!已公开,请重试。另请注意:DataAccess项目中有一个“SQL”文件夹。我在其中加入了一个脚本,用于创建和植入mysql数据库和表,以进行测试。