Ali
Ali

Reputation: 927

Azure Function Build Pipelines Fails when Unit Test Project references the Function project

I am using Visual Studio 2019 Community Edition and I have a multi-tier solution. Below is a screenshot of that.

Please note, it's a sample project to replicate a production solution, so, namings probably are not really important here.

enter image description here

Project specifications: (all netcoreapp3.1)

  1. Sample.AzureFunction.Api - Target Framework: netcoreapp3.1and Azure Function version: 3.0.7
  2. { Application, Model, ClassLibrary1, and ClassLibrary2 } - Target Framework: netcoreapp3.1 and all are `.netcore class library' projects.
  3. ApiTests - Target Framework: netcoreapp3.1

The Problem

The Azure Build Pipeline fails when there is a reference from the ApiTest project to the Sample.AzureFunction.Api. If I remove the project reference, the build continues to be green. Here is a screenshot from the build errors when the build step is running in the pipeline.

Basically, all the errors are complaining about not finding some dlls. For example, CSC : error CS0006: Metadata file 'D:\a\1\s\publish_output\Application.dll' could not be found [D:\a\1\s\Sample.AzureFunction.Api\Tests\ApiTests\ApiTests.csproj]

enter image description here

Few Notes:

  1. The build step in the pipeline is .net core added automatically by Azure DevOps.
  2. I don't have a dedicated Agent and I use the Azure Pipelines that comes by default when creating a new CI.
  3. Agent specification is windows-2019

I used the classic view to create the pipeline (no YAML) but I could grab the following YAML from the generated steps by clicking on each of them and copying the YAML:

enter image description here

I've spent a day on resolving this issue and I'm running out of ideas now. Any thoughts would be appreciated.

Upvotes: 1

Views: 992

Answers (1)

Krzysztof Madej
Krzysztof Madej

Reputation: 40553

If you remove --output argument your build will succeeded.

It looks like your folder publish_output was cleared before compiling test project. Thus it can't find these dlls there.

Furthermore, you don't need rather to publish as an artifact all dlls. Please use publish command to create artifact for code which is going to be deployed:

- task: DotNetCoreCLI@2
  inputs:
    command: publish
    publishWebProjects: True
    arguments: '--configuration $(BuildConfiguration) --output $(Build.ArtifactStagingDirectory)'
    zipAfterPublish: True

# this code takes all the files in $(Build.ArtifactStagingDirectory) and uploads them as an artifact of your build.
- task: PublishBuildArtifacts@1
  inputs:
    pathtoPublish: '$(Build.ArtifactStagingDirectory)' 
    artifactName: 'myWebsiteName'

I listed publish_output folder after running your original pipeline and you can find there these files:

Application.deps.json
ClassLibrary1.deps.json
Function1
Sample.AzureFunction.Api.deps.json
bin
host.json

Upvotes: 1

Related Questions