在 Debian 上运行 .net core 时出错 [英] Error Running .net core on Debian
问题描述
我正在尝试使用 .net core 编译和运行我的第一个跨平台应用程序以迁移 c# 应用程序.我正在尝试在 Debian 9.3 上运行它
我已经运行了这两个命令.
dotnet build -r debian-x64dotnet 发布 -c 发布 -r debian-x64dotnet build -r linux-x64dotnet 发布 -c 发布 -r linux-x64
我获得了每个文件夹(分别为 binRelease etcoreapp2.0linux-x64 和 binRelease etcoreapp2.0debian-x64),我使用 SFTP 将其复制到我的 linux 机器上.在 linux 中,我 cd 进入文件夹并运行 .program
我在尝试使用 debian 特定的或通用的 linux 编译代码时收到以下错误.
错误:未找到应用程序依赖项清单 (nfz_core.deps.json) 中指定的程序集:包:'runtime.linux-x64.Microsoft.NETCore.App',版本:'2.0.0'路径:'运行时/linux-x64/lib/netcoreapp2.0/Microsoft.CSharp.dll'
我想我的 csproj 文件可能做错了什么,但我似乎无法弄清楚我做错了什么.
这是我的 .csproj 文件
<OutputType>Exe</OutputType><TargetFramework>netcoreapp2.0</TargetFramework><RuntimeIdentifiers>win10-x64;debian-x64;linux-x64</RuntimeIdentifiers></PropertyGroup></项目>
我感谢人们提供的任何见解.
运行时:
dotnet publish -c release -r linux-x64
您要求将此代码发布为 独立部署.这意味着所有 .NET Core 运行时、所有依赖项以及基本上与操作系统无关的任何内容都将与您的应用程序一起发布.发布命令将您的构建置于:
binRelease
etcoreapp2.0linux-x64publish
注意:这与binRelease
etcoreapp2.0linux-x64
不相同.linux-x64
目录包含 dotnet build
的输出,而不是 dotnet publish
.
复制publish
目录后,您可以直接在目标操作系统上运行您的程序(./program
),无需安装 .NET Core.>
另一种方法是在 框架依赖部署中运行 模式.在这种情况下,您无需 -r linux-x64
即可构建.在这种情况下,您仍然复制 publish
目录,但您必须以 dotnet/path/to/your.dll
的形式运行应用程序.
TLDR:部署时总是复制publish
目录.
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
I get folders for each of these, (binRelease etcoreapp2.0linux-x64 and binRelease etcoreapp2.0debian-x64 respectively) which I used SFTP to copy to my linux box. In linux, I cd into the folder and run .program
I get the following error while trying to use either the debian specific or generic linux compiled code.
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'
I think I may have done something wrong in my csproj file, but I can't seem to figure out what I did wrong.
Here is my .csproj file
<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.
When you run:
dotnet publish -c release -r linux-x64
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:
binRelease
etcoreapp2.0linux-x64publish
Note: This is not the same as binRelease
etcoreapp2.0linux-x64
. The linux-x64
directory contains the output of dotnet build
, not dotnet publish
.
Once you copy over the publish
directory, you can run your program directly (./program
) on the target OS, without needing .NET Core installed.
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: Always copy the publish
directory when deploying.
这篇关于在 Debian 上运行 .net core 时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!