简体   繁体   English

在 Ubuntu 20.04 上运行 dotnet 应用程序

[英]Run dotnet application on Ubuntu 20.04

I am newbie in net core on Linux and i have a question.我是 Linux 上 net core 的新手,我有一个问题。 I installed .net core 5 and wrote hello world app with name "hello".我安装了 .net core 5 并编写了名为“hello”的 hello world 应用程序。 After, I go to the project bin directory and run my app like:之后,我转到项目 bin 目录并运行我的应用程序,如下所示:

dotnet hello.dll

All fine.一切都很好。 But i see "hello" (shared library) file in the bin directory too.但是我在 bin 目录中也看到了“hello”(共享库)文件。 I can run it in terminal like:我可以在终端中运行它,如:

./hello

All works... But when i copy files in another location (away from project directory), i can't run my app like: ./hello I get message "Segmentation fault (core dumped)" in terminal.一切正常...但是当我将文件复制到另一个位置(远离项目目录)时,我无法运行我的应用程序,例如:./hello 我在终端中收到消息“Segmentation fault (core dumped)”。

Someone, please, tell me, why after copy files, command "./hello" doesn't work (but dotnet hello.dll works).请有人告诉我,为什么复制文件后,命令“./hello”不起作用(但 dotnet hello.dll 起作用)。

Ubuntu 20.04 Ubuntu 20.04

.NET SDK installed: 5.0.301 .NET SDK 安装:5.0.301

.NET runtimes installed: 5.0.7安装的 .NET 运行时:5.0.7

UPDATE project location:更新项目位置:

/RiderProjects/RabbitMq-example/RabbitMq-example/bin/Debug/net5.0

i copy only net5.0 folder to:我只将 net5.0 文件夹复制到:

/RiderProjects/RMQ/net5.0

And I get Segmentation fault.我得到了分割错误。

If i copy full bin folder (like:如果我复制完整的 bin 文件夹(例如:

/RiderProjects/RMQ/bin/Debug/net5.0

All fine.一切都很好。

Steps:脚步:

  1. Create folder (eg HelloApp)创建文件夹(例如HelloApp)
  2. In folder, open terminal and use dotnet new console在文件夹中,打开终端并使用dotnet new console
  3. After project creating, use dotnet publish in this folder (bin folder will be create after build action) (By the current step I have RiderProjects/HelloApp/bin/Debug/net5.0/publish)创建项目后,在此文件夹中使用dotnet publish (构建操作后将创建 bin 文件夹)(按当前步骤,我有 RiderProjects/HelloApp/bin/Debug/net5.0/publish)
  4. Copy publish/ folder (with files) to another location (in my case, it is RiderProjects/publish)将发布/文件夹(包含文件)复制到另一个位置(在我的情况下,它是 RiderProjects/publish)
  5. dotnet HelloApp.dll in publish folder work perfectly, but ./HelloApp doesn't work发布文件夹中的dotnet HelloApp.dll工作正常,但./HelloApp不起作用

If you installed the dotnet runtime via snap install you can access it via "sudo dotnet ..." only.如果您通过 snap install 安装了 dotnet 运行时,则只能通过“sudo dotnet ...”访问它。 I had the same problem in VS Code, it runs the dotnet commands without sudo and I recived the "Segmentation fault (core dumped)" error.我在 VS Code 中遇到了同样的问题,它在没有 sudo 的情况下运行 dotnet 命令,我收到了“分段错误(核心转储)”错误。 I solved by installing the dotnet runtime via apt-get (now is installed in "/usr/bin ..." and works without sudo (see: https://docs.microsoft.com/en-us/dotnet/core/install/linux-ubuntu#2004- ))我通过 apt-get 安装 dotnet 运行时解决了(现在安装在“/usr/bin ...”中,无需 sudo 即可工作(请参阅: https : //docs.microsoft.com/en-us/dotnet/core/安装/linux-ubuntu#2004- ))

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

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