ASP.NET Core 发布

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 Filesdotnetsdk1.0.0SdksMicrosoft.NET.SdkuildMicrosoft.NET.Sdk.targets(92,5): error : Assets file 'D:SiteGCClass4objproject.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:SiteGCClass4GCClass4.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 的子目录中,该目录位于项目的 .in elease etcoreapp1.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

引用:http://www.bkjia.com/Asp_Netjc/1199209.html

原文地址:https://www.cnblogs.com/zjoch/p/6706975.html