第一步:運行 dotnet restore 命令,以還原項目中指定的依賴項html
dotnet restore
第二步:使用 dotnet build 命令爲目標平臺上的應用建立調試版本。 若是不指定想要生成的運行時標識符,則 dotnet build 命令將會建立僅適用於當前系統運行時 ID 的版本。 可以使用如下命令生成目標平臺適用的應用:linux
dotnet build -r centos.7-x64
目標平臺.NET Core 運行時標識符 (RID) 目錄json
Windows 7 / Windows Server 2008 R2 win7-x64 win7-x86
Windows 8 / Windows Server 2012 win8-x64 win8-x86 win8-arm
Windows 8.1 / Windows Server 2012 R2 win81-x64 win81-x86 win81-arm
Windows 10 / Windows Server 2016 win10-x64 win10-x86 win10-arm win10-arm64
Red Hat Enterprise Linux rhel.7-x64 rhel.7.0-x64 rhel.7.1-x64 rhel.7.2-x64 rhel.7.3-x64 rhel.7.4-x64
Ubuntu ubuntu.14.04-x64 ubuntu.14.10-x64 ubuntu.15.04-x64 ubuntu.15.10-x64 ubuntu.16.04-x64 ubuntu.16.10-x64
CentOS centos.7-x64
Debian debian.8-x64
Fedora fedora.23-x64 fedora.24-x64
OpenSUSE opensuse.13.2-x64 opensuse.42.1-x64
Oracle Linux ol.7-x64 ol.7.0-x64 ol.7.1-x64 ol.7.2-x64
Currently supported Ubuntu derivatives linuxmint.17-x64 linuxmint.17.1-x64 linuxmint.17.2-x64 linuxmint.17.3-x64 linuxmint.18-x64
OS X RIDs osx.10.10-x64 osx.10.11-x64 osx.10.12-x64
注:若是沒有經過,提示以下相似信息:ubuntu
C:\Program Files\dotnet\sdk\1.0.0\Sdks\Microsoft.NET.Sdk\build\Microsoft.NET.Sdk.targets(92,5): error : Assets file 'D:\Site\GCClass4\obj\project.assets.json' doesn't have a target for '.NETCoreApp,Version=v1.0/win81-x64'. Ensure you have restored this project for TargetFramework='netcoreapp1.0' and RuntimeIdentifier='win81-x64'. [D:\Site\GCClass4\GCClass4.csproj]centos
請修改你的.csproj文件,以下(只添加紅色這一行,紫色修改成你要的目標RID):app
<Project Sdk="Microsoft.NET.Sdk.Web"> <PropertyGroup> <TargetFramework>netcoreapp1.0</TargetFramework> <RuntimeIdentifiers></RuntimeIdentifiers>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore" Version="1.0.3" />
<PackageReference Include="Microsoft.AspNetCore.Mvc" Version="1.0.2" />
<PackageReference Include="Microsoft.AspNetCore.StaticFiles" Version="1.0.1" />
<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="1.0.1" />
<PackageReference Include="Microsoft.VisualStudio.Web.BrowserLink" Version="1.0.1" />
</ItemGroup>
</Project>centos.7-x64
再次執行「第一步」和「第二步」,經過後在繼續如下步驟asp.net
第三步:調試並測試該程序後,能夠經過對兩個目標平臺使用 dotnet publish 命令來爲每一個做爲目標的平臺建立要與應用一塊兒部署的文件,以下所示:ide
dotnet publish -c release -r centos.7-x64
-c 發佈時要使用的配置。 默認值爲 Debug。測試
-r 發佈針對給定運行時的應用程序。 有關能夠使用的運行時標識符 (RID) 列表,請參閱 RID 目錄。ui
這將爲目標平臺建立一個應用的發行版(而不是調試版)。 生成的文件位於名爲 publish 的子目錄中,該目錄位於項目的 .\bin\release\netcoreapp1.0\<runtime_identifier> 子目錄的子目錄中。 請注意,每一個子目錄中都包含完整的啓動應用所需的文件集(既有應用文件,也有全部 .NET Core 文件)。
參考:https://docs.microsoft.com/en-us/dotnet/articles/core/tools/dotnet-build
https://docs.microsoft.com/en-us/dotnet/articles/standard/frameworks
https://docs.microsoft.com/en-us/dotnet/articles/core/rid-catalog