在開發階段,都是直接安裝.Net Core的SDK,可是在部署的時候你仍是直接裝SDK嗎?固然直接裝SDK也沒什麼問題,也能夠少一些麻煩。可是若是你像我同樣不喜歡在產線上裝SDK,只想裝Runtime,那麼這篇文章可能會對你有幫助。這裏咱們談的都是針對便攜式發佈的應用程序。html
https://www.microsoft.com/net...linux
你能夠在這裏下載全部.Net相關的運行時或者SDK。這裏咱們主要看看.Net Core。json
如使用便攜式發佈的,那發佈的程序中不會包含.Net Core運行時,在部署到服務器的時候就須要安裝對應的.Net Core運行時。可直接按照官方的文檔,使用包管理器來安裝。ubuntu
例如: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
這樣你的程序就能夠正常運行了。app
若是你的是ASP.Net Core應用程序,你會發現使用上述方式安裝了.net core運行時以後,你的程序仍是沒法正常運行。會出現大概相似下面這樣的錯誤:curl
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運行時。工具
固然,你也能夠在發佈的時候帶上它:post
<PropertyGroup> <PublishWithAspNetCoreTargetManifest>false</PublishWithAspNetCoreTargetManifest> </PropertyGroup>
或者直接在運行時裏面補上它就能夠了。下載它,而後解壓到dotnet的安裝目錄url
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
而後你就能夠運行你的程序了。
微軟已經爲你打包好了.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呢?