Linux上的.Net Core可以使用'dotnet myapp.dll'运行,但是使用systemctl失败了

问题描述 投票:0回答:1

我试图通过遵循this tutorial中的指示在Ubuntu Server 16.04 LTS上托管ASP.Net Core MVC应用程序。

从Linux机器上,我使用git pull来引入我的项目。我使用dotnet build成功构建它,触发包恢复。我用dotnet publish -c Release -r linux-x64成功发布了它。我将目录更改为bin/Release/netcoreapp2.1并运行sudo cp ./*.* /var/aspnetcore/myapp/将文件复制到我托管项目的目录中。我导航到该目录并键入dotnet myapp.dll - 应用程序开始侦听端口5000和5001,并从另一台计算机,我可以在浏览器中键入我的域名并查看网站,这意味着Nginx反向代理和Kestrel必须是工作正常。

现在我想将应用程序作为服务运行,以便它从计算机启动,重新启动崩溃,记录错误等,但是当我键入sudo systemctl start kestrel-myapp.service时,它立即崩溃并尝试每10秒重新启动但失败。日志显示错误:An assembly in the application dependencies manifest (myapp.deps.json) was not found: package: 'Microsoft.EntityFrameworkCore.Relational.Design', version '1.1.5' path: 'lib/netstandard1.3/Microsoft.EntityFrameworkCore.Relational.Design.dll' Main process exited, code=exited, status=140/n/a

因此,版本1.1.5看起来很低,但我更新了所有的Nu​​Get包,但它仍然想要使用它。另外,我不明白为什么如果依赖项存在问题,它不会与dotnet myapp.dll崩溃。有人知道如何解决这个问题吗?

这是我的服务文件:

[Unit]
Description=myapp ASP.Net Core MVC Application

[Service]
WorkingDirectory=/var/aspnetcore/myapp
ExecStart=/usr/bin/dotnet /var/aspnetcore/myapp/myapp.dll
Restart=always
# Restart service after 10 seconds if the dotnet service crashes:
RestartSec=10
SyslogIdentifier=myapp
User=www-data
Environment=ASPNETCORE_ENVIRONMENT=Production
Environment=DOTNET_PRINT_TELEMETRY_MESSAGE=false

[Install]
WantedBy=multi-user.target

奖金问题:我在哪里将我的静态文件复制到我的wwwroot文件夹?应用程序运行但找不到我的任何javascript或css文件,我不确定它们属于哪里。

linux ubuntu asp.net-core .net-core
1个回答
1
投票

当你dotnet publish -c Release -r linux-x64它创建了几个目录。您想使用bin/Release/netcoreapp2.1/linux-x64/publish目录。其他目录也包含构建,但这些构建假设它们将在开发系统上运行。只有publish目录包含应该部署的位。其他目录包含假定它们在开发环境中运行的位。

它运行dotnet myapp.dll时有效,因为您仍然以普通用户身份运行,并且它会看到您的本地开发资产,包括nuget缓存。

当您通过systemctl运行时,它运行为root,它没有任何本地nuget缓存,并且不能使用代码的开发(非published)版本。

© www.soinside.com 2019 - 2024. All rights reserved.