ASP.NET Core 發布,asp.netcore發布
第一步:運行 dotnet restore 命令,以還原項目中指定的依賴項
dotnet restore
第二步:使用 dotnet build 命令為目標平台上的應用創建調試版本。 如果不指定想要生成的運行時標識符,則 dotnet build 命令將會創建僅適用於當前系統運行時 ID 的版本。 可使用以下命令生成目標平台適用的應用:
dotnet build -r centos.7-x64
目標平台.NET Core 運行時標識符 (RID) 目錄
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
注:如果沒有通過,提示如下類似信息:
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]
請修改你的.csproj文件,如下(只添加紅色這一行,紫色修改為你要的目標RID):
<Project Sdk="Microsoft.NET.Sdk.Web"> <PropertyGroup> <TargetFramework>netcoreapp1.0</TargetFramework> <RuntimeIdentifiers>centos.7-x64</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>
再次執行“第一步”和“第二步”,通過后在繼續以下步驟
第三步:調試並測試該程序后,可以通過對兩個目標平台使用 dotnet publish 命令來為每個作為目標的平台創建要與應用一起部署的文件,如下所示:
dotnet publish -c release -r centos.7-x64
-c 發布時要使用的配置。 默認值為 Debug。
-r 發布針對給定運行時的應用程序。 有關可以使用的運行時標識符 (RID) 列表,請參閱 RID 目錄。
這將為目標平台創建一個應用的發行版(而不是調試版)。 生成的文件位於名為 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
