简体   繁体   English

您如何在 azure deveops 管道中构建单个项目工件

[英]How do you build individual project artifacts in azure deveops pipeline

I have multiple projects contained in my repo that I would like to build individual zip artifact to deploy them each separately.我的存储库中包含多个项目,我想构建单独的 zip 工件以分别部署它们。 Currently, the pipeline builds one zip artifact that contains all the projects.目前,管道构建了一个包含所有项目的 zip 工件。 How do I configure my azure-pipelines.yml file to accomplish this task?如何配置我的 azure-pipelines.yml 文件来完成此任务? Below is my current file.下面是我当前的文件。

trigger:
- master

pool:
  vmImage: 'windows-latest'

variables:
  solution: '**/*.sln'
  buildPlatform: 'Any CPU'
  buildConfiguration: 'Release'

steps:
- task: NuGetToolInstaller@1

- task: NuGetCommand@2
  inputs:
    restoreSolution: '$(solution)'

- task: VSBuild@1
  inputs:
    solution: '$(solution)'
    msbuildArgs: '/p:DeployOnBuild=true /p:WebPublishMethod=Package 
/p:PackageAsSingleFile=true /p:SkipInvalidConfigurations=true 
/p:DesktopBuildPackageLocation="$(build.artifactStagingDirectory)\WebApp.zip" 
/p:DeployIisAppPath="Default Web Site"'
    platform: '$(buildPlatform)'
    configuration: '$(buildConfiguration)'

- task: VSTest@2
  inputs:
    platform: '$(buildPlatform)'
    configuration: '$(buildConfiguration)'

- task: PublishBuildArtifacts@1
  inputs:
    PathtoPublish: '$(Build.ArtifactStagingDirectory)'
    ArtifactName: 'drop'
    publishLocation: 'Container'

You can change the build parameter /p:PackageAsSingleFile=false which will prevent all the projects from being zipped together.您可以更改构建参数/p:PackageAsSingleFile=false这将阻止所有项目被压缩在一起。 If you want to move the built files after the build, before the Publish Artifacts step, you can create a Copy files task that will copy the project's build folder to another location within the '$(Build.ArtifactStagingDirectory)'如果您想在构建后移动构建的文件,在发布工件步骤之前,您可以创建一个复制文件任务,将项目的构建文件夹复制到“$(Build.ArtifactStagingDirectory)”中的另一个位置

steps:脚步:

  • task: CopyFiles@2 displayName: 'Copy Project Files' inputs: SourceFolder: '$\\ProjectName\\bin$(BuildConfiguration)' Contents: '****' TargetFolder: '$(build.artifactstagingdirectory)\\ProjectName' CleanTargetFolder: true任务:CopyFiles@2 displayName:'Copy Project Files' 输入:SourceFolder:'$\\ProjectName\\bin$(BuildConfiguration)' 内容:'****' TargetFolder:'$(build.artifactstagingdirectory)\\ProjectName' CleanTargetFolder:true

Though these will all still be placed within the 'drop' folder or whatever the $(build.artifactstagingdirectory) is called.尽管这些仍然会被放置在 'drop' 文件夹或任何 $(build.artifactstagingdirectory) 被调用的地方。 The only way to separate artifacts is to create separate pipelines for each project.分离工件的唯一方法是为每个项目创建单独的管道。

It depends on how you define the MSBuild arguments.这取决于您如何定义 MSBuild 参数。 The /p:DesktopBuildPackageLocation="$(build.artifactStagingDirectory)\\WebApp.zip" /p:DeployIisAppPath="Default Web Site" is the direct cause of the issue, it calls msbuild to package all projects into one WebApp.zip file. /p:DesktopBuildPackageLocation="$(build.artifactStagingDirectory)\\WebApp.zip" /p:DeployIisAppPath="Default Web Site"是导致该问题的直接原因,它调用 msbuild 将所有项目打包到一个WebApp.zip文件中。

With msbuildArgs: '/p:DeployOnBuild=true /p:WebPublishMethod=Package /p:PackageAsSingleFile=true /p:SkipInvalidConfigurations=true /p:PackageLocation="$(build.artifactStagingDirectory)"' you can have separate ProjectName.zip files under $(build.artifactStagingDirectory) path.使用msbuildArgs: '/p:DeployOnBuild=true /p:WebPublishMethod=Package /p:PackageAsSingleFile=true /p:SkipInvalidConfigurations=true /p:PackageLocation="$(build.artifactStagingDirectory)"'您可以拥有单独的ProjectName.zip文件在$(build.artifactStagingDirectory)路径下。

And then you can use one Publish Build Artifact task to publish whole $(build.artifactStagingDirectory) directory which contains ProjectA.zip , ProjectB.zip ...然后您可以使用一个Publish Build Artifact task来发布包含ProjectA.zipProjectB.zip ... 的整个$(build.artifactStagingDirectory)目录。

Also you can use several Publish Build Artifact tasks in one pipeline for your several output xx.zip files.您还可以在一个管道中为多个输出xx.zip文件使用多个Publish Build Artifact tasks

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 您如何使用C#以编程方式从最新的Team City构建中下载工件? - How do you programatically download the artifacts from the latest Team City build using C#? 如何获得要在构建机器上构建的NUnit测试项目? - How do you get an NUnit test project to build on a build machine? 如何在发布服务器项目而不是客户端的 Azure DevOps 上为 Blazor WebAssembly 托管应用程序创建构建管道? - How to create a build pipeline for Blazor WebAssembly Hosted app on Azure DevOps that publishes the server project not the client? 如何使用NAnt 0.90构建Windows Workflow项目? - How do you build a Windows Workflow Project with NAnt 0.90? 如何以编程方式从 Azure DevOps 下载最新的构建工件? - How to download the latest build artifacts from Azure DevOps programmatically? 如何使用 Visual Studio Code CLI 创建具有个人身份验证的 MVC 项目 - How do you create a MVC project with Individual Authentication using Visual Studio Code CLI 如何强制Console App Project在构建中包含一个文件夹? - How do you force a Console App Project to include a folder in the build? 如何更正 Azure 管道中的 package 版本名称并删除构建 ID - How to correct package version name in Azure pipeline and remove build ID 如何在 azure devOps 中设置用于构建统一项目的管道 - How to set pipeline for building unity project in azure devOps 如何从测试项目修复 Azure Devops 构建错误 CS0246 - How do I fix Azure Devops build error CS0246 from test project
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM