首页 > 解决方案 > 从 `systemd` 脚本运行的 `dotnet` 命令找不到 AspNetCore 3.0,但可以从命令行运行

问题描述

我有一个 linux ubuntu 16.04 服务器,用于托管一堆 .NET Core 站点和应用程序(它是一个登台服务器),还有一堆使用 .NET Core 2.0 和 2.1 的应用程序。服务器使用带有代理的 nginx 通过网络提供内容。

我刚刚部署了一个 ASP.NET Core 3.0 MVC 网站,按照此处的说明安装 ASP.NET Core 3.0 运行时,https://docs.microsoft.com/en-us/dotnet/core/install/linux-package -manager-ubuntu-1604

如果我dotnet MyApp.dll直接从命令行运行,它会启动并运行良好,在端口 5000 上提供服务,一切正常。但是,如果我尝试使用 systemd 服务启动应用程序,它将无法正常工作,并出现以下错误journalctl

Feb 11 13:57:18 ip-172-31-2-223 systemd[1]: Started IBA Showcase Test API.
Feb 11 13:57:18 ip-172-31-2-223 dotnet[19193]: It was not possible to find any compatible framework version
Feb 11 13:57:18 ip-172-31-2-223 dotnet[19193]: The specified framework 'Microsoft.AspNetCore.App', version '3.0.0' was not found.
Feb 11 13:57:18 ip-172-31-2-223 dotnet[19193]:   - Check application dependencies and target a framework version installed at:
Feb 11 13:57:18 ip-172-31-2-223 dotnet[19193]:       /usr/share/dotnet/
Feb 11 13:57:18 ip-172-31-2-223 dotnet[19193]:   - Installing .NET Core prerequisites might help resolve this problem:
Feb 11 13:57:18 ip-172-31-2-223 dotnet[19193]:       https://go.microsoft.com/fwlink/?LinkID=798306&clcid=0x409
Feb 11 13:57:18 ip-172-31-2-223 dotnet[19193]:   - The .NET Core framework and SDK can be installed from:
Feb 11 13:57:18 ip-172-31-2-223 dotnet[19193]:       https://aka.ms/dotnet-download
Feb 11 13:57:18 ip-172-31-2-223 dotnet[19193]:   - The following versions are installed:
Feb 11 13:57:18 ip-172-31-2-223 dotnet[19193]:       2.1.13 at [/usr/share/dotnet/shared/Microsoft.AspNetCore.App]
Feb 11 13:57:18 ip-172-31-2-223 dotnet[19193]:       2.2.7 at [/usr/share/dotnet/shared/Microsoft.AspNetCore.App]

我在文件夹中的 .service 文件/etc/systemd/system非常简单,如下所示:

[Unit]
Description=IBA Showcase Test API
Wants=network.target

[Service]
Type=simple
User=www-data
Group=www-data
Environment="DOTNET_CLI_TELEMETRY_OPTOUT=1"
Environment="ASPNETCORE_ENVIRONMENT=Staging"
Environment="ASPNETCORE_URLS=http://*:5000"
WorkingDirectory=/var/www/ibashowcase/api/
ExecStart=/usr/bin/dotnet IBA.Showcase.API.dll
Restart=on-failure

[Install]
WantedBy=multi-user.target

任何提示将不胜感激。

标签: ubuntuasp.net-coresystemdasp.net-core-3.0

解决方案


推荐阅读