将部署简单的.Net核心控制台应用程序部署到linux服务器时遇到了一些问题。
我用这种方式创建了简单的控制台Hello world应用程序:
dotnet new console -o hello
然后我在devlop计算机上测试了这个应用程序
dotnet run
工作正常。
接下来我以这种方式创建了debian平台的发布
dotnet publish -c release -r debian.8-x64 --self-contained
现在我有一个分发文件夹
C:\Projects\C#\hello\bin\MCD\release\netcoreapp2.0\debian.8-x64
此外,我将文件夹debian.8-x64复制到我的linux计算机并使用Debias 8 OS
找到要执行的文件(~/debian.8-x64/hello
)并更改模式
chmod +x ./hello
现在我正在尝试执行文件
./hello
得到例外
root@my2ndbox:/home/alex/temp/debian.8-x64# ./hello
Error:
An assembly specified in the application dependencies manifest (hello.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'
Net framework安装在Linux机器上,版本与我的开发计算机相同
root@my2ndbox:/home/alex/temp/debian.8-x64# dotnet --version
2.0.2
可能导致此类错误的原因是什么?
答案 0 :(得分:2)
您正在复制错误的内容以进行部署。当您dotnet publish
时,您应该使用publish
目录的内容。对于您的情况,它应该是release/netcoreapp2.0/debian.8-x64/publish/
。
如果您使用非发布目录(release/netcoreapp2.0/debian.8-x64/
),它将假定您希望在开发模式下运行项目,并期望使用本地nuget缓存中的资产,这很可能会丢失在你的部署机器。
FWIW,你正在做一些非常奇怪的事情。首先,您需要决定是否要真正使用自包含部署。如果你是,你甚至不需要在你试图部署的机器上安装dotnet。
答案 1 :(得分:0)
您可能还想签出dotnet-packaging。它包含一个textview.movementMethod = MyLinkMovementMethod(fun(url: String) {
Log.e("URL", url)
})
命令行实用程序,可让您创建一个dotnet deb
文件(即Debian安装程序),您可以使用该文件在Debian上安装您的应用程序。它应该使您的部署更容易。
要开始使用,首先需要将此部分添加到.deb
文件中:
.csproj
然后,运行<ItemGroup>
<PackageReference Include="Packaging.Targets" Version="0.1.45" />
<DotNetCliToolReference Include="dotnet-deb" Version="0.1.45" />
<ItemGroup>
和dotnet restore
。这将创建一个dotnet deb -c Release -r debian.8-x64 -f netcoreapp2.0
文件,可用于将应用程序部署到Debian。
答案 2 :(得分:-1)
--self-contained
表示您不需要在目标计算机上安装.Net Core,因为所有需要的组件都在发布文件夹中
第二件事是重复参数,因为-r debian.8-x64
设置为true --self-contained
(换句话说,在设置运行时标识符后不需要--self-contained
)
最后在发布前尝试dotnet restore
。然后确保从./bin/[configuration]/[framework]/[runtime]
复制正确的东西(./bin/[configuration]/[framework]/
用于依赖于框架的部署)。您甚至可以通过参数-o
手动设置输出文件夹(例如dotnet publish -c release -r debian.8-x64 -o copyme
并将copyme
复制到您的&#34; linux服务器&#34;)