使用Azure Pipelines任务发布Asp Net Core SPA

时间:2019-09-09 21:45:12

标签: asp.net-core azure-pipelines

我有一个ASP.NET Core 2.2 SPA .csproj项目文件:

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

  <PropertyGroup>
    <TargetFramework>netcoreapp2.2</TargetFramework>
  </PropertyGroup>

  <Target Name="PublishRunWebpack" AfterTargets="ComputeFilesToPublish">
    <Exec WorkingDirectory="$(SpaRoot)" Command="npm install --python=python2.7" />
    <Exec WorkingDirectory="$(SpaRoot)" Command="npm run build -- --prod" />
    <Exec WorkingDirectory="$(SpaRoot)" Command="npm run build:ssr -- --prod" Condition=" '$(BuildServerSideRenderer)' == 'true' " />
    <ItemGroup>
      <DistFiles Include="$(SpaRoot)dist\**; $(SpaRoot)dist-server\**" />
      <DistFiles Include="$(SpaRoot)node_modules\**" Condition="'$(BuildServerSideRenderer)' == 'true'" />
      <ResolvedFileToPublish Include="@(DistFiles->'%(FullPath)')" Exclude="@(ResolvedFileToPublish)">
        <RelativePath>%(DistFiles.Identity)</RelativePath>
        <CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory>
      </ResolvedFileToPublish>
    </ItemGroup>
  </Target>

</Project>

要构建该项目并将其部署到Azure,我正在使用Azure Pipelines:

trigger:
- master

variables:
  buildConfiguration: 'Release'
  buildPlatform: 'any cpu'
  azureSubscription: 'Azure'
  system.debug: true

jobs:
- job: Prepare
  pool:
    vmImage: 'Ubuntu-16.04'
  steps:
  - task: DotNetCoreCLI@2
    displayName: Build
    inputs:
      command: build
      projects: '**/*.csproj'
      arguments: '--configuration $(buildConfiguration)'
  - task: DotNetCoreCLI@2
    displayName: Publish
    inputs:
      command: publish
      publishWebProjects: false
      projects: '**/*.csproj'
      arguments: '--configuration $(buildConfiguration) --output $(Build.ArtifactStagingDirectory)'
      zipAfterPublish: true
  - task: PublishPipelineArtifact@0
    inputs:
      artifactName: Artifacts 
      targetPath: '$(Build.ArtifactStagingDirectory)'
- deployment: Release
  dependsOn: Prepare
  condition: succeeded()
  pool:
    vmImage: Ubuntu-16.04
  environment: production
  strategy:
    runOnce:
      deploy:
        steps:
        - task: DownloadPipelineArtifact@1
          displayName: Artifacts
          inputs:
            artifactName: Artifacts
        - task: AzureRmWebAppDeployment@4
          displayName: Web
          inputs:
            package: '$(Build.ArtifactStagingDirectory)/Proj.Web.zip'
            azureSubscription: '$(azureSubscription)'
            appType: 'Web App On Windows'
            webAppName: 'proj-demo'

在将项目构建和部署到一台计算机上时,此方法有效。

但是现在我需要将项目部署到2台不同的机器上。

要实现这一点,我认为我需要:

  1. 从CSProj中删除PublishRunWebpack任务;

  2. 将PublishRunWebpack中的命令移至Azure Pipelines

    代替运行命令:

     npm run build -- --prod
    

    我需要运行两次:

     npm run build -- --prod.machine1
    
     npm run build -- --prod.machine2
    

我的主要问题是如何在ASP.NET Core中构建ASP.NET Core项目和Angular项目,并且仍然构建要部署的工件。

0 个答案:

没有答案