.Net Core Runtime安装说明

时间:2022-05-07
本文章向大家介绍.Net Core Runtime安装说明,主要内容包括.Net 下载中心、.Net Core应用程序、ASP.Net Core应用程序、Server Hosting、基本概念、基础应用、原理机制和需要注意的事项等,并结合实例形式分析了其使用技巧,希望通过本文能帮助到大家理解应用这部分内容。

在开发阶段,都是直接安装.Net Core的SDK,但是在部署的时候你还是直接装SDK吗?当然直接装SDK也没什么问题,也可以少一些麻烦。但是如果你像我一样不喜欢在产线上装SDK,只想装Runtime,那么这篇文章可能会对你有帮助。这里我们谈的都是针对便携式发布的应用程序。

.Net 下载中心

https://www.microsoft.com/net/download/all

你可以在这里下载所有.Net相关的运行时或者SDK。这里我们主要看看.Net Core。

.Net Core应用程序

如使用便携式发布的,那发布的程序中不会包含.Net Core运行时,在部署到服务器的时候就需要安装对应的.Net Core运行时。可直接按照官方的文档,使用包管理器来安装。

例如:Linux Ubuntu 16.04

curl https://packages.microsoft.com/keys/microsoft.asc | gpg --dearmor > microsoft.gpg
sudo mv microsoft.gpg /etc/apt/trusted.gpg.d/microsoft.gpg
sudo sh -c 'echo "deb [arch=amd64] https://packages.microsoft.com/repos/microsoft-ubuntu-xenial-prod xenial main" > /etc/apt/sources.list.d/dotnetdev.list'
sudo apt-get install apt-transport-https
sudo apt-get update
sudo apt-get install dotnet-runtime-2.0.6

这样你的程序就可以正常运行了。

ASP.Net Core应用程序

如果你的是ASP.Net Core应用程序,你会发现使用上述方式安装了.net core运行时之后,你的程序还是无法正常运行。会出现大概类似下面这样的错误:

Error:
 An assembly specified in the application dependencies manifest (ZKEACMS.WebHost.deps.json) was not found:
 package: 'Microsoft.ApplicationInsights.AspNetCore', version: '2.1.1'
 path: 'lib/netstandard1.6/Microsoft.ApplicationInsights.AspNetCore.dll'
 This assembly was expected to be in the local runtime store as the application was published using the following target manifest files:
 aspnetcore-store-2.0.0-linux-x64.xml;aspnetcore-store-2.0.0-osx-x64.xml;aspnetcore-store-2.0.0-win7-x64.xml;aspnetcore-store-2.0.0-win7-x86.xml

这是因为只安装了.Net Core运行时,而没有安装ASP.NET Core运行时

当然,你也可以在发布的时候带上它:

<PropertyGroup>
 <PublishWithAspNetCoreTargetManifest>false</PublishWithAspNetCoreTargetManifest> 
</PropertyGroup>

或者直接在运行时里面补上它就可以了。下载它,然后解压到dotnet的安装目录

wget -O aspnetcore-store.tar.gz https://download.microsoft.com/download/8/D/A/8DA04DA7-565B-4372-BBCE-D44C7809A467/aspnetcore-store-2.0.6-linux-x64.tar.gz
tar zxf aspnetcore-store.tar.gz -C /usr/share/dotnet

然后你就可以运行你的程序了。

Server Hosting

微软已经为你打包好了.Net Core Runtime和ASP.Net Core Runtime,可以不用先装.Net Core Runtime再装ASP.Net Core Runtime,直接下载就可以使用了:

mkdir dotnet
wget -O https://download.microsoft.com/download/8/D/A/8DA04DA7-565B-4372-BBCE-D44C7809A467/dotnet-hosting-2.0.6-linux-x64.tar.gz
tar zxf aspnetcore-store.tar.gz -C dotnet

Windows比较简单,直接安装Windows Server Hosting就可以了。

不过,为什么不可以通过包管理工具,直接安装.Net Core Runtime和ASP.Net Core Runtime呢?

原文链接:http://www.zkea.net/codesnippet/detail/post-98.html