【Azure DevOps系列】使ASP.NET Core應用程序托管到Azure Web App Service


使用Azure DevOps Project設置ASP.NET項目

file

我們需要先在Azure面板中創建一個Azure WebApp服務,此處步驟我將省略,然后點擊部署中心如下圖所示:

file

此處我選擇的是Azure Repos,當然大家也可以選擇GithubLocal GitFTP

file
我們需要提前在Azure DevOps中提前創建好應用程序,我這邊已經提前創建好了名稱為Blog
.
file

創建完后我們會在Azure DevOps Pipeline中看到默認為我們生成的管道信息,他是一個構建剛才那個應用程序並發布的過程。這個過程還是挺方便的,省去了我們一些的配置直接將這些給我們配置好,當然CD其實也配置好了,最終這個應用程序會發布到我們在在這之前創建的Azure WebApp中。

file

file

通過如下該圖我們可以看到已經可以訪問通了,雖然
為錯誤頁面其實也沒關系的,是因為我數據庫一些信息未進行配置,現在呢我們已經將應用程序部署到Azure WebApp中了。當然CI和CD規則我們也可以將其進行修改的。

file

我們來看看管道的默認配置,默認的構建過程如下圖所示。

file

下面代碼片段是azure-pipelines.yml文件的相關配置如下所示

# ASP.NET Core
# Build and test ASP.NET Core projects targeting .NET Core.
# Add steps that run tests, create a NuGet package, deploy, and more:
# https://docs.microsoft.com/azure/devops/pipelines/languages/dotnet-core

trigger:
- master

jobs:
- job: ASPNETCore
  pool:
    vmImage: 'ubuntu-latest'
  steps:
  # - task: UseDotNet@2
  #   inputs:
  #     packageType: 'sdk'
  #     version: '3.1.x'

  - task: DotNetCoreCLI@2
    displayName: Build
    inputs:
      command: build
      projects: '**/*.sln'
      arguments: '--configuration Release -p:Version=10.5.$(Build.BuildId)-official'

  - task: DotNetCoreCLI@2
    displayName: Test
    inputs:
      command: test
      projects: '**/*Tests/*.csproj'
      arguments: '--configuration Release'

  - task: DotNetCoreCLI@2
    inputs:
      command: publish
      publishWebProjects: True
      arguments: '--configuration Release -p:Version=10.5.$(Build.BuildId)-official --output $(Build.ArtifactStagingDirectory)'
      zipAfterPublish: True

  - task: PublishBuildArtifacts@1
    inputs:
      pathtoPublish: '$(Build.ArtifactStagingDirectory)' 
      artifactName: 'Drop'

當然在上面步驟中的DotNetCoreCLI@2任務會發布並並打包應用程序,我們可以在下圖所示頁面中進行下載發布后的應用程序。

file


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM