第一步:运行 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