在Debian上运行.net core时出错 [英] Error Running .net core on Debian
问题描述
我正在尝试使用.net core编译并运行我的第一个跨平台应用程序,以迁移c#应用程序。我试图在Debian Stretch 9.3上运行它。
I'm trying to compile and run my first cross-platform app using .net core to migrate a c# app. I am trying to run this on Debian stretch 9.3
我已经运行了这两个命令。
I've run both of these commands.
dotnet build -r debian-x64
dotnet publish -c release -r debian-x64
dotnet build -r linux-x64
dotnet publish -c release -r linux-x64
我为每个文件夹得到文件夹,(bin\释放我分别使用SFTP复制到Linux盒的 netcoreapp2.0 linux-x64和bin发行版 netcoreapp2.0biandebian-x64)。
在Linux中,我进入该文件夹并运行.\program
I get folders for each of these, (bin\Release\netcoreapp2.0\linux-x64 and bin\Release\netcoreapp2.0\debian-x64 respectively) which I used SFTP to copy to my linux box. In linux, I cd into the folder and run .\program
在尝试使用特定于debian或通用的Linux编译代码。
Error:
An assembly specified in the application dependencies manifest (nfz_core.deps.json) was not found:
package: 'runtime.linux-x64.Microsoft.NETCore.App', version: '2.0.0'
path: 'runtimes/linux-x64/lib/netcoreapp2.0/Microsoft.CSharp.dll'
我认为我可能在csproj中做错了文件,但似乎无法弄清楚我做错了什么。
I think I may have done something wrong in my csproj file, but I can't seem to figure out what I did wrong.
这是我的.csproj文件
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp2.0</TargetFramework>
<RuntimeIdentifiers>win10-x64;debian-x64;linux-x64</RuntimeIdentifiers>
</PropertyGroup>
</Project>
我很感谢人们可以提供的任何见识。
I appreciate any insight people could give.
推荐答案
运行时:
dotnet publish -c release -r linux-x64
您要将此代码发布为自包含部署。这意味着所有.NET Core运行时,所有依赖关系以及与操作系统无关的所有内容都将与您的应用程序一起发布。 publish命令将您的构建置于以下位置:
You are asking this code to be published as a Self Contained Deployment. That means all of .NET Core runtime, all your dependencies and basically anything not OS-related is published along with your application. The publish command puts your build under:
bin\Release\netcoreapp2.0\linux-x64\publish
注意:这与 bin 不相同\发布\netcoreapp2.0\linux-x64\
。 linux-x64
目录包含 dotnet build
的输出,而不是 dotnet publish 。
Note: This is not the same as bin\Release\netcoreapp2.0\linux-x64\
. The linux-x64
directory contains the output of dotnet build
, not dotnet publish
.
在发布
目录中复制后,您可以直接运行程序(< c $ c> ./ program ),而不需要安装.NET Core。
Once you copy over the publish
directory, you can run your program directly (./program
) on the target OS, without needing .NET Core installed.
另一种方法是在依赖于框架的部署模式。在这种情况下,您不使用 -r linux-x64
进行构建。在这种情况下,您仍然可以复制发布
目录,但是您必须以 dotnet /path/to/your.dll$c运行应用程序$ c>。
An alternative is to run in Framework Dependent Deployment mode. You build without -r linux-x64
in that case. You still copy over the publish
directory in that case, but you must run the application as dotnet /path/to/your.dll
.
TLDR:在部署时始终复制发布
目录。
TLDR: Always copy the publish
directory when deploying.
这篇关于在Debian上运行.net core时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!