ASP.NET Core 发布的具体操作

下面使用C# 编写的ASP.NET Core Web项目示例说明发布的全过程。

1、创建项目

选择“文件” > “新建” > “项目”。 在“添加新项目”对话框中,在“已安装” “Visaul C#”  “Web” 项目类型窗格中选择“ASP.NET Core Web 应用程序”,在“名称”文本框中输入项目名称如“MmPS”,点击 确定(如下图1),然后在中心窗格中选择“Web应用程序(模型视图控制器)”模板, 然后选择“确定”按钮(如下图2)。

图1

图2

2、添加Web项目应用程序的源代码的各种逻辑

本项目是已经建好的,无需创建。此步骤省略。

3、发布Web项目

发布已经完善的Web项目应用程序,首先是定义应用的目标平台。

1、编辑项目资源

在“解决方案资源管理器”中右键单击项目(而非解决方案),然后选择“编辑 MmPS.csproj”。在MmPS.csproj文件(该文件用于定义应用的目) <PropertyGroup> 部分中添加<RuntimeIdentifiers> 标记,然后指定每个目标平台的运行时标识符 (RID)。 请注意,如果是多个系统,还需要添加分号来分隔 RID。 不同系统的RID会不同,具体请查看运行时标识符目录,获取运行时标识符列表。例如,以下示例表明应用在 64 位 Windows 10 操作系统和 64 位 OS X 10.11 版本的操作系统上运行。

在MmPS.csproj文件中添加

<PropertyGroup>     <RuntimeIdentifiers>ubuntun.16.04-x64;osx.10.11-x64

</RuntimeIdentifiers>

</PropertyGroup>

2、发布应用

调试并测试程序后,为应用的每个目标平台创建要与应用一起发布的文件。从Visual Studio发布应用,执行以下操作:

l 在“解决方案资源管理器”中右键单击项目(而非解决方案),然后选择“发布”,如下图3。

l 在“发布”选项卡上,选择“发布”。 Visual Studio将包含应用程序的文件写入本地文件系统。“发布”选项卡现在显示单个配置文件 FolderProfile。 该配置文件的配置设置显示在选项卡的“摘要”部分。目标运行时用于标识已发布的运行时,目标位置用于标识独立部署文件的写入位置。

l 默认情况下,Visual Studio 将所有已发布文件写入单个目录。 为了方便起见,最好为每个目标运行时创建单个配置文件,并将已发布文件置于特定于平台的目录中。 这包括为每个目标平台创建单独的发布配置文件。

l 根据平台单独发布应用程序

现在执行下列操作,为每个平台重新生成应用程序:

1、在“发布”对话框中选择“创建新配置文件”。

在“选取发布目标”对话框中,将“选择文件夹”位置更改为 bin\Release\PublishOutput\ubuntun.16.04-x64。 选择“确定”。

在配置文件列表中选择新配置文件 (FolderProfile1) ,并确保“目标运行时”为 ubuntun.16.04-x64。 如果不是,请选择“设置”。 在“配置文件设置”对话框中,将“目标运行时”更改为 ubuntun.16.04-x64,然后选择“保存”。 否则,选择“取消”。

2、选择“发布”,发布 64 位 ubuntun.16.04平台的应用。

3、其他平台类似操作即可

再次按照上述步骤创建 osx.10.11-x64 平台的配置文件。 “目标位置”为 bin\Release\PublishOutput\osx.10.11-x64,“目标运行时”为 osx.10.11-x64。Visual Studio 分配给此配置文件的名称是 FolderProfile2。

请注意,每个目标位置中都包含启动应用所需的完整文件集(既包含应用文件,又包含所有 .NET Core 文件)。同时与应用程序的文件一起,发布过程将发出包含应用调试信息的程序数据库 (.pdb) 文件。 该文件主要用于调试异常。 可以选择不使用应用程序文件打包该文件。 但是,如果要调试应用的发布版本,则应保存该文件。

4、可以把已经发布的文件部署到其他系统中了, 例如,可以使用简单的 copy 命令将其打包为 Zip 文件,或者使用选择的安装包进行部署(下面会把发布的文件部署到ubuntun.16.04-x64)。

下面是本项目完整的 MmPS.csproj 文件。

<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup Label="Globals">

<SccProjectName>SAK</SccProjectName>

<SccProvider>SAK</SccProvider>

<SccAuxPath>SAK</SccAuxPath>

<SccLocalPath>SAK</SccLocalPath>

</PropertyGroup>

<PropertyGroup>

<TargetFramework>netcoreapp2.0</TargetFramework>

<RuntimeIdentifiers>ubuntun.16.04-x64;osx.10.11-x64</RuntimeIdentifiers>

</PropertyGroup>

<ItemGroup>

<Compile Remove="Models\authority.cs" />

<Compile Remove="Models\log.cs" />

<Compile Remove="Models\menu.cs" />

<Compile Remove="Models\module.cs" />

<Compile Remove="Models\nodes.cs" />

<Compile Remove="Models\roles.cs" />

<Compile Remove="Models\source.cs" />

<Compile Remove="Models\TestUser.cs" />

<Compile Remove="Models\user.cs" />

<Compile Remove="Models\userinrole.cs" />

</ItemGroup>

<ItemGroup>

<Content Remove="appsettings.Development.json" />

<Content Remove="Views\Index.cshtml" />

</ItemGroup>

<ItemGroup>

<None Remove="Models\MMPS.txt" />

<None Remove="Properties\PublishProfiles\CustomProfile.pubxml" />

<None Remove="Views\Log.js" />

<None Remove="Views\Log\Log.js" />

<None Remove="Views\OrganizationInfo\OrganizationInfo.js" />

<None Remove="Views\Update\UpdateUpload.js" />

</ItemGroup>

<ItemGroup>

<Content Include="Views\Device\Device.js" />

<Content Include="Views\Log\Log.js" />

<Content Include="Views\Menu\Menu.js" />

<Content Include="Views\OrganizationInfo\OrganizationInfo.js" />

<Content Include="Views\Roles\Roles.js" />

<Content Include="Views\Source\Source.js">

<CopyToOutputDirectory>Never</CopyToOutputDirectory>

</Content>

<Content Include="Views\Update\UpdateUpload.js" />

<Content Include="Views\UserInfo\UserInfo.js">

<CopyToOutputDirectory>Never</CopyToOutputDirectory>

</Content>

</ItemGroup>

<ItemGroup>

<PackageReference Include="AutoMapper" Version="6.1.1" />

<PackageReference Include="Dapper" Version="1.50.2" />

<PackageReference Include="Microsoft.AspNetCore.All" Version="2.0.0" />

<PackageReference Include="Microsoft.AspNetCore.Session" Version="2.0.0" />

<PackageReference Include="Microsoft.EntityFrameworkCore" Version="2.0.0" />

<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="2.0.0" />

<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="2.0.0" />

<PackageReference Include="Microsoft.Extensions.Configuration" Version="2.0.0" />

<PackageReference Include="Microsoft.Extensions.Configuration.FileExtensions" Version="2.0.0" />

<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="2.0.0" />

<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="2.0.0" />

<PackageReference Include="MySql.Data.EntityFrameworkCore.Design" Version="8.0.8-dmr" />

<PackageReference Include="NETStandard.Library" Version="2.0.0" />

<PackageReference Include="newtonsoft.json" Version="10.0.3" />

<PackageReference Include="Pomelo.EntityFrameworkCore.MySql" Version="2.0.0-rtm-10062" />

<PackageReference Include="System.ComponentModel" Version="4.3.0" />

</ItemGroup>

<ItemGroup>

<DotNetCliToolReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Tools" Version="2.0.0" />

</ItemGroup>

<ItemGroup>

<None Include="wwwroot\js\kindeditor\kindeditor-all-min.js" />

<None Include="wwwroot\js\kindeditor\kindeditor-all.js" />

<None Include="wwwroot\js\kindeditor\lang\ar.js" />

<None Include="wwwroot\js\kindeditor\lang\en.js" />

<None Include="wwwroot\js\kindeditor\lang\ko.js" />

<None Include="wwwroot\js\kindeditor\lang\ru.js" />

<None Include="wwwroot\js\kindeditor\lang\zh-CN.js" />

<None Include="wwwroot\js\kindeditor\lang\zh-TW.js" />

<None Include="wwwroot\js\kindeditor\plugins\anchor\anchor.js" />

<None Include="wwwroot\js\kindeditor\plugins\autoheight\autoheight.js" />

<None Include="wwwroot\js\kindeditor\plugins\baidumap\baidumap.js" />

<None Include="wwwroot\js\kindeditor\plugins\clearhtml\clearhtml.js" />

<None Include="wwwroot\js\kindeditor\plugins\code\code.js" />

<None Include="wwwroot\js\kindeditor\plugins\code\prettify.js" />

<None Include="wwwroot\js\kindeditor\plugins\emoticons\emoticons.js" />

<None Include="wwwroot\js\kindeditor\plugins\filemanager\filemanager.js" />

<None Include="wwwroot\js\kindeditor\plugins\fixtoolbar\fixtoolbar.js" />

<None Include="wwwroot\js\kindeditor\plugins\flash\flash.js" />

<None Include="wwwroot\js\kindeditor\plugins\image\image.js" />

<None Include="wwwroot\js\kindeditor\plugins\insertfile\insertfile.js" />

<None Include="wwwroot\js\kindeditor\plugins\lineheight\lineheight.js" />

<None Include="wwwroot\js\kindeditor\plugins\link\link.js" />

<None Include="wwwroot\js\kindeditor\plugins\map\map.js" />

<None Include="wwwroot\js\kindeditor\plugins\media\media.js" />

<None Include="wwwroot\js\kindeditor\plugins\multiimage\images\swfupload.swf" />

<None Include="wwwroot\js\kindeditor\plugins\multiimage\multiimage.js" />

<None Include="wwwroot\js\kindeditor\plugins\pagebreak\pagebreak.js" />

<None Include="wwwroot\js\kindeditor\plugins\plainpaste\plainpaste.js" />

<None Include="wwwroot\js\kindeditor\plugins\preview\preview.js" />

<None Include="wwwroot\js\kindeditor\plugins\quickformat\quickformat.js" />

<None Include="wwwroot\js\kindeditor\plugins\table\table.js" />

<None Include="wwwroot\js\kindeditor\plugins\template\template.js" />

<None Include="wwwroot\js\kindeditor\plugins\wordpaste\wordpaste.js" />

</ItemGroup>

<ItemGroup>

<ProjectReference Include="..\DownloadHelper\DownloadHelper.csproj" />

<ProjectReference Include="..\MmPS.Application\MmPS.Application.csproj" />

<ProjectReference Include="..\MmPS.Common.Data\MmPS.Common.Data.csproj" />

<ProjectReference Include="..\MmPS.EntityFrameworkCore\MmPS.EntityFrameworkCore.csproj" />

</ItemGroup>

<ItemGroup>

<Folder Include="Properties\PublishProfiles\" />

</ItemGroup>

<ItemGroup>

<Content Update="wwwroot\js\views\source.js">

<CopyToOutputDirectory>Never</CopyToOutputDirectory>

</Content>

<Content Update="wwwroot\js\views\userInfo.js">

<CopyToOutputDirectory>Never</CopyToOutputDirectory>

</Content>

</ItemGroup>

<ProjectExtensions><VisualStudio><UserProperties bower_1json__JSONSchema="" /></VisualStudio></ProjectExtensions>

</Project>

ASP.NET Core 2.0 MVC 发布部署--------- ASP.NET Core 发布的具体操作的更多相关文章

  1. ASP.NET Core 2.0 MVC项目实战

    一.前言 毕业后入职现在的公司快有一个月了,公司主要的产品用的是C/S架构,再加上自己现在还在学习维护很老的delphi项目,还是有很多不情愿的.之前实习时主要是做.NET的B/S架构的项目,主要还是 ...

  2. ASP.NET CORE 1.0 MVC API 文档用 SWASHBUCKLE SWAGGER实现

    from:https://damienbod.com/2015/12/13/asp-net-5-mvc-6-api-documentation-using-swagger/ 代码生成工具: https ...

  3. Asp.net Core 1.0.1升级到Asp.net Core 1.1.0 Preview版本发布到Windows Server2008 R2 IIS中的各种坑

    Asp.net Core 1.0.1升级到Asp.net Core 1.1.0后,程序无法运行了 解决方案:在project.json中加入runtime节点 "runtimes" ...

  4. C# 6 与 .NET Core 1.0 高级编程 - 41 ASP.NET MVC(上)

    译文,个人原创,转载请注明出处(C# 6 与 .NET Core 1.0 高级编程 - 41 ASP.NET MVC(上)),不对的地方欢迎指出与交流. 章节出自<Professional C# ...

  5. C# 6 与 .NET Core 1.0 高级编程 - 41 ASP.NET MVC(中)

    译文,个人原创,转载请注明出处(C# 6 与 .NET Core 1.0 高级编程 - 41 ASP.NET MVC(中)),不对的地方欢迎指出与交流. 章节出自<Professional C# ...

  6. C# 6 与 .NET Core 1.0 高级编程 - 41 ASP.NET MVC(下)

    译文,个人原创,转载请注明出处(C# 6 与 .NET Core 1.0 高级编程 - 41 ASP.NET MVC(下)),不对的地方欢迎指出与交流. 章节出自<Professional C# ...

  7. asp.net core 3.0 MVC JSON 全局配置

    asp.net core 3.0 MVC JSON 全局配置 System.Text.Json(default) startup配置代码如下: using System.Text.Encodings. ...

  8. C# 6 与 .NET Core 1.0 高级编程 - 40 ASP.NET Core(上)

    译文,个人原创,转载请注明出处(C# 6 与 .NET Core 1.0 高级编程 - 40 章  ASP.NET Core(上)),不对的地方欢迎指出与交流. 章节出自<Professiona ...

  9. C# 6 与 .NET Core 1.0 高级编程 - 40 ASP.NET Core(下)

    译文,个人原创,转载请注明出处(C# 6 与 .NET Core 1.0 高级编程 - 40 章  ASP.NET Core(下)),不对的地方欢迎指出与交流. 章节出自<Professiona ...

  10. 探索 ASP.Net Core 3.0系列三:ASP.Net Core 3.0中的Service provider validation

    前言:在本文中,我将描述ASP.NET Core 3.0中新的“validate on build”功能. 这可以用来检测您的DI service provider是否配置错误. 具体而言,该功能可检 ...

随机推荐

  1. Omeed 线段树

    目录 题面 题解 代码 题面 2.12 - - - 题解 大概还是挺妙的? 首先基础分和连击分互不干扰,所以可以分开统计. 基础分的统计比较简单,等于: \[A \sum_{i = l}^{r} p_ ...

  2. 【BZOJ4802】欧拉函数(Pollard_rho)

    [BZOJ4802]欧拉函数(Pollard_rho) 题面 BZOJ 题解 这么大的范围肯定不好杜教筛. 考虑欧拉函数的计算式,显然只需要把\(n\)分解就好了. 直接\(Pollard\_rho\ ...

  3. cin/cout与scanf/printf的比较

    转自http://www.cnblogs.com/penelope/articles/2426577.html  cin .cout   基本说明: cin是标准输入流对象,代表标准输入设备(键盘), ...

  4. 学习 opencv---(11)OpenC 边缘检测:Canny算子,Sobel算子,Laplace算子,Scharr滤波器

    本篇文章中,我们将一起学习OpenCV中边缘检测的各种算子和滤波器——Canny算子,Sobel算子,Laplace算子以及Scharr滤波器.文章中包含了五个浅墨为大家准备的详细注释的博文配套源代码 ...

  5. HDU--2722

    原题链接:http://acm.hdu.edu.cn/showproblem.php?pid=2722 分析:简单最短路,读入数据烦. #include<iostream> #includ ...

  6. array_uintersect、array_uintersect_assoc、array_uintersect_uassoc 的使用方法

    和 array_intersect 类似,只不过 array_uintersect* 系列函数的值比较使用自定义函数: 键的比较,array_uintersect.array_uintersect_a ...

  7. 手机 safari mac 调试

    1.下载 safari technology preview 2.iphone 设置: 打开“设置”程序,进入“Safari”->“高级”页面开启“Web检查器” 3.mac 上打开 safar ...

  8. Android缓存

    一个利用内存缓存和磁盘缓存图片的例子 public class BitmapCache { public static final String TAG = "debug"; pr ...

  9. 「Python」7个不一样的代码写法

    打印index 对于一个列表,或者说一个序列我们经常需要打印它的index,一般传统的做法或者说比较low的写法: 更优雅的写法是多用enumerate 两个序列的循环 我们会经常对两个序列进行计算或 ...

  10. python中拷贝对象的区别

    一.赋值.引用 在python中赋值语句总是建立对象的引用值,而不是复制对象.因此,python变量更像是指针,而不是数据存储区域 这点和大多数语音类似吧,比如C++.Java等 1.先看个例子: v ...