Search code examples
azure-devopsazure-pipelinesazure-pipelines-release-pipelineazure-pipelines-tasks

How to include files and test assemblies from a class library project into published artifacts


I have a solution which includes a single NET Core 3.1 Web API project and several other projects which are NET Framework 4.8 Class Library projects.

In my build pipeline the solution builds without any problems, I have a very simple build, however I need output from this build such as test assemblies as well configuration files to be made available for my release pipeline. The reason is that my release pipeline is associated with Test Plans and Test Suites and is needed for running these test plans on demand.

In any when I publish artifacts from the build pipeline none of the test assemblies are included, the only things that get included are those files from the Web App which I do not need for my test purposes. I've read in a couple of different places that I could add the other projects as dependencies but that just doesn't seem right to me as those dependencies are really needed. Is there another way to have the build pipeline publish those other assemblies and files?

[UPDATE] Solution 1: One solution that I saw suggested elsewhere was to use the Copy files task to copy the assemblies to ${Build.ArtifactStagingDirectory} and then publish the artifacts but either it's not working or i'm doing something incorrectly. Here is my YAML definition for the 2 tasks:

task: CopyFiles@2
inputs:
Contents: '**'
TargetFolder: '${Build.ArtifactStagingDirectory}'

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

FWIW in the CopyFiles log I do see that the files are getting copied, for instance:

Copying d:\a\1\s\test\BaseTest.cs to ${Build.ArtifactStagingDirectory}\test\BaseTest.cs


Solution

  • These test assemblies will not auto include when you only build your class library project and publish your artifacts in build pipeline directly.

    ----Solution 
        ----NET Core 3.1 Web API project
        ----NET Framework 4.8 Class Library project 1
        ----NET Framework 4.8 Class Library project 2
        ...
        ----Test Project (Reference Class Library Project)
    

    If you build test project, it will auto include referenced Class Library Project. And when you publish the build artifacts, it will also include generated Test Assemblies.

    Another possibility is you did not choose the right path to copy dlls, it's using path which under class library project not test project.

    You need to copy the generated Test Assemblies to $(build.artifactstagingdirectory) first through Copy Files task and then publish with the artifact.

    enter image description here