|
本文介绍了如何将ASP.NET Core应用部署到CAE(云原生应用引擎)。包括了创建CAE集群、配置ASP.NET Core应用和部署应用的详细步骤。
准备工作
1、确保已安装.NET Core SDK
zbhj0fiu2gmgfaj.png
(图片来源网络,侵删)
2、安装Visual Studio Code(可选,用于编辑和调试代码)
3、安装Git(可选,用于版本控制)
创建ASP.NET Core应用
1、打开命令行或终端,输入以下命令创建一个新的ASP.NET Core应用:
dotnet new webapp o MyAspNetCoreApp
2、进入项目目录:
cd MyAspNetCoreApp
添加CAE部署配置
1、在项目根目录下创建一个名为deployment的文件夹。
2、在deployment文件夹中创建一个名为appsettings.json的文件,添加以下内容:
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft": "Warning",
"Microsoft.Hosting.Lifetime": "Information"
}
},
"AllowedHosts": "*",
"ConnectionStrings": {
"DefaultConnection": "Server=(localdb)\mssqllocaldb;Database=MyAspNetCoreApp_DB;Trusted_Connection=True;MultipleActiveResultSets=true"
}
}
编写代码
1、打开src/MyAspNetCoreApp/Controllers/HomeController.cs文件,添加以下内容:
zbhjmscqlhhgahm.jpg
(图片来源网络,侵删)
using Microsoft.AspNetCore.Mvc;
using System.Threading.Tasks;
namespace MyAspNetCoreApp.Controllers
{
public class HomeController : Controller
{
public IActionResult Index()
{
return View();
}
}
}
2、在同一目录下创建一个名为Views/Home/Index.cshtml的文件,添加以下内容:
@{
ViewData["Title"] = "Home Page";
}
Welcome
Learn about [url=]building Web apps with ASP.NET Core[/url].
构建并部署到CAE服务器
1、在项目根目录下打开命令行或终端,输入以下命令构建应用:
dotnet build configuration Release output ./deployment/MyAspNetCoreApp/bin/Release/netcoreapp3.1/publish/ norestore selfcontained true p:PublishSingleFile=true p:PublishTrimmed=true p:DebugSymbols=false p:DebugType=None p:IncludeNativeLibrariesForSelfExtract=true p:GenerateRuntimeConfigurationFiles=false p:UseAppHost=false p:EnableOptimizations=true p:DeterministicLockFile=true p:TreatWarningsAsErrors=true p:WarningsAsErrors=NU1605 runtime winx64 framework netcoreapp3.1 outputpath bin/Release/netcoreapp3.1/publish/ noselfcontained false runtimeconfig deployment/appsettings.json r linuxx64 c Release o deployment/MyAspNetCoreApp/bin/Release/netcoreapp3.1/publish/ selfcontained true p:PublishSingleFile=true p:PublishTrimmed=true p:DebugSymbols=false p:DebugType=None p:IncludeNativeLibrariesForSelfExtract=true p:GenerateRuntimeConfigurationFiles=false p:UseAppHost=false p:EnableOptimizations=true p:DeterministicLockFile=true p:TreatWarningsAsErrors=true p:WarningsAsErrors=NU1605 runtime winx64 framework netcoreapp3.1 outputpath bin/Release/netcoreapp3.1/publish/ noselfcontained false runtimeconfig deployment/appsettings.json r linuxx64 c Release o deployment/MyAspNetCoreApp/bin/Release/netcoreapp3.1/publish/ selfcontained true p:PublishSingleFile=true p:PublishTrimmed=true p:DebugSymbols=false p:DebugType=None p:IncludeNativeLibrariesForSelfExtract=true p:GenerateRuntimeConfigurationFiles=false p:UseAppHost=false p:EnableOptimizations=true p:DeterministicLockFile=true p:TreatWarningsAsErrors=true p:WarningsAsErrors=NU1605 runtime winx64 framework netcoreapp3.1 outputpath bin/Release/netcoreapp3.1/publish/ noselfcontained false runtimeconfig deployment/appsettings.json r linuxx64 c Release o deployment/MyAspNetCoreApp/bin/Release/netcoreapp3.1/publish/ selfcontained true p:PublishSingleFile=true p:PublishTrimmed=true p:DebugSymbols=false p:DebugType=None p:IncludeNativeLibrariesForSelfExtract=true p:GenerateRuntimeConfigurationFiles=false p:UseAppHost=false p:EnableOptimizations=true p:DeterministicLockFile=true p:TreatWarningsAsErrors=true p:WarningsAsErrors=NU1605 runtime winx64 framework netcoreapp3.1 outputpath bin/Release/netcoreapp3.1/publish/ noselfcontained false runtimeconfig deployment/appsettings.json r linuxx64 c Release o deployment/MyAspNetCoreApp/bin/Release/netcoreapp3.1/publish/ selfcontained true p:PublishSingleFile=true p:PublishTrimmed=true p:DebugSymbols=false p:DebugType=None p:IncludeNativeLibrariesForSelfExtract=true p:GenerateRuntimeConfigurationFiles=false p:UseAppHost=false p:EnableOptimizations=true p:DeterministicLockFile=true p:TreatWarningsAsErrors=true p:WarningsAsErrors=NU1605 runtime winx64 framework netcoreapp3.1 outputpath bin/Release/netcoreapp3.1/publish/ noselfcontained false runtimeconfig deployment/appsettings.json r linuxx64 c Release o deployment/MyAspNetCoreApp/bin/Release/netcoreapp3.1/publish/ selfcontained true p:PublishSingleFile=true p:PublishTrimmed=true p:DebugSymbols=false p:DebugType=None p:IncludeNativeLibrariesForSelfExtract=true p:GenerateRuntimeConfigurationFiles=false p:UseAppHost=false p:EnableOptimizations=true p:DeterministicLockFile=true p:TreatWarningsAsErrors=true p:WarningsAsErrors=NU1605 runtime winx64 framework netcoreapp3.1 outputpath bin/Release/netcoreapp3.1/publish/ noselfcontained false runtimeconfig deployment/appsettings.json r linuxx64 c Release o deployment/MyAspNetCoreApp/bin/Release/netcoreapp3.1/publish/ selfcontained true p:PublishSingleFile=true p:PublishTrimmed=true p:DebugSymbols=false p:DebugType=None p:IncludeNativeLibrariesForSelfExtract=true p:GenerateRuntimeConfigurationFiles=false p:UseAppHost=false p:EnableOptimizations=true p:DeterministicLockFile=true p:TreatWarningsAsErrors=true p:WarningsAsErrors=NU1605 runtime winx64 framework netcoreapp3.1 outputpath bin/Release/netcoreapp3.1/publish/ noselfcontained false runtimeconfig deployment
下面是一个简单的介绍,描述了将ASP.NET Core应用程序部署到云应用引擎(Cloud Application Engine,简称CAE)的过程:
步骤 | 操作 | 说明 | 1 | 准备工作 | 确保已安装.NET Core SDK和CAE CLI工具 | 2 | 登录CAE | 使用CAE CLI登录到您的账户cae login | 3 | 创建项目 | 如果还没有ASP.NET Core项目,创建一个dotnet new webapp n MyAspNetApp | 4 | 切换到项目目录 | cd MyAspNetApp | 5 | 打包应用 | 使用dotnet命令打包应用程序dotnet publish c Release | 6 | 部署应用 | 使用CAE CLI部署应用cae deploy app MyAspNetApp path ./bin/Release/netcoreapp3.1/publish | 7 | 指定版本 | 如果需要,可以指定要部署的版本version 1.0.0 | 8 | 等待部署完成 | 部署过程中,CAE CLI会显示进度信息 | 9 | 检查部署状态 | 部署完成后,可以通过CAE控制台检查应用状态 | 10 | 访问应用 | 通过分配给应用的URL访问您的ASP.NET Core应用 |
请注意,介绍中的命令和参数可能需要根据您的具体环境和CAE的配置进行相应的调整,应用的名称、版本号以及发布的路径都可能需要根据您实际的项目设置进行修改,具体的CAE命令和参数可能会随着CAE版本的更新而发生变化,请参考最新的官方文档。
zbhj01eira0vyxe.jpg
(图片来源网络,侵删) |
|