0
votes

I am trying to copy multiple projects DLLs generated using with Devops build pipeline into one folder:

I have below projects structure in Devops, two .NET CORE 3.1 console applications:

enter image description here

I wrote a build pipeline in Devops and below is the code:

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' 

It published the artifacts in below folder structure:

enter image description here

However if you can see PressTrustBatchJob & PressTrustPurge two individual folders are created and all the ddls are in that folder. I want to build and copy all the dlls into one folder :

How can I build the dlls and generate artifacts like PressTrust/Bin --> and all dlls of both the projects should be in the Bin folder, it shouldn't create individual project folders.

I tried to use copy task but it is also copying folders also not files inside folders only.

1

1 Answers

1
votes

The solution is add PropertyGroup.OutputPath in *.csproj to point main folder ../ when Release application:

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

and then change action to use '**/*.sln' instead **/*.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