Azure Build 管道将 DLL 生成到一个 Bin 文件夹中

Azure Build pipeline generate DLLs into one Bin folder

我正在尝试将使用 Devops 构建管道生成的多个项目 DLL 复制到一个文件夹中:

我在 Devops 中有以下项目结构,两个 .NET CORE 3.1 控制台应用程序:

我在 Devops 中写了一个构建管道,下面是代码:

trigger:
- none

pool:
  vmImage: 'windows-latest'

variables:
  buildProjects: '**/*.csproj'
  buildConfiguration: 'Release'
  solution: '**/*.sln'
  ArtifactName: drop

jobs:
- job: Main_Build
  displayName: Main Build
  
  steps:
  - task: UseDotNet@2
    displayName: Use .Net Core 3.1.x SDK
    inputs:
      packageType: 'sdk'
      version: '3.1.x'
  
  - task: DotNetCoreCLI@2
    displayName: Restore Packages
    inputs:
      command: 'restore'
      projects: '$(solution)'
      feedsToUse: 'select'

  - task: DotNetCoreCLI@2
    displayName: Build
    inputs:
      command: 'build'
      projects: '$(buildProjects)'
      arguments: '--configuration $(buildConfiguration)'

  - task: DotNetCoreCLI@2
    displayName: Publish
    inputs:
      command: 'publish'
      publishWebProjects: false      
      projects: '$(buildProjects)'
      arguments: '--configuration $(buildConfiguration) --output $(Build.ArtifactStagingDirectory)/PressTrust/Bin'
      zipAfterPublish: false   

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

它在以下文件夹结构中发布了工件:

但是,如果您可以看到 PressTrustBatchJob 和 PressTrustPurge,则会创建两个单独的文件夹,并且所有 ddl 都在该文件夹中。我想构建所有 dll 并将其复制到一个文件夹中:

我如何构建 dll 并生成像 PressTrust/Bin 这样的工件 --> 两个项目的所有 dll 都应该在 Bin 文件夹中,它不应该创建单独的项目文件夹。

我尝试使用复制任务,但它也在复制文件夹,而不是仅复制文件夹内的文件。

解决方案是在 *.csproj 中添加 PropertyGroup.OutputPath 指向主文件夹 ../Release 应用程序:

<Project Sdk="Microsoft.NET.Sdk"> 
 
  <PropertyGroup> 
    <OutputType>Exe</OutputType> 
    <TargetFramework>netcoreapp3.1</TargetFramework> 
  </PropertyGroup> 
 
  <PropertyGroup Condition="'$(Configuration)'=='Release'"> 
    <OutputPath>../</OutputPath> 
  </PropertyGroup> 
 
</Project> 

然后更改操作以使用 '**/*.sln' 代替 **/*.csproj:

    - task: DotNetCoreCLI@2
      displayName: Build
      inputs:
        command: 'build'
        projects: '$(solution)'
        arguments: '--configuration $(buildConfiguration)'

    - task: DotNetCoreCLI@2
      displayName: Publish
      inputs:
        command: 'publish'
        publishWebProjects: false      
        projects: '$(solution)'
        arguments: '--configuration $(buildConfiguration) --output $(Build.ArtifactStagingDirectory)/PressTrust/Bin'
        zipAfterPublish: false