OpenAPI UI dll load failure from release pipeline only
Got a function app which is being deployed to an Azure serverless deployment. I have a Function App "Functions" project and corresponding "Functions.Tests" unit test project. When doing a zip deploy from Visual Studio, everything is working correctly. When trying to go thru Azure Devops build and release pipelines, I am getting a Could not load file or assembly 'D:\home\site\wwwroot\bin\Functions.Tests.dll'. The system cannot find the file specified. error. There is nothing special as far as the pipeline script that is standing out, and a little surprised the OpenAPI UI would be looking for the unit test project at all. Below are the yamls
build.yaml
trigger:
branches:
include:
- main
pool:
vmImage: "windows-latest"
variables:
solution: "**.*.sln"
buildPlatform: "x64"
buildConfiguration: "Release"
name: $(Year:yyyy).$(Month).$(DayOfMonth)$(Rev:.r)
stages:
- stage: Function_Service
displayName: 'Function App Build'
jobs:
- job:
steps:
- template: templates/functions-template.yml
templates/functions-template.yml
steps:
- task: VersionDotNetCoreAssemblies@2
inputs:
Path: "$(Build.SourcesDirectory)"
VersionNumber: "$(Build.BuildNumber)"
Injectversion: False
VersionRegex: '\d+\.\d+\.\d+\.\d+'
FilenamePattern: ".csproj"
OutputVersion: "OutputedVersion"
- task: DotNetCoreCLI@2
inputs:
command: 'build'
arguments: '--configuration $(buildConfiguration)'
displayName: 'dotnet build $(buildConfiguration)'
- task: DotNetCoreCLI@2
displayName: 'Run Unit Tests VS Test Coverage'
inputs:
command: test
projects: '**/*Tests/*.csproj'
arguments: '--configuration $(buildConfiguration) --collect "Code Coverage"'
- task: DotNetCoreCLI@2
displayName: 'Run Unit Tests Cobertura Report Support'
inputs:
command: test
projects: '**/*Tests/*.csproj'
arguments: '--configuration $(buildConfiguration) --collect "XPlat Code Coverage"'
- task: DotNetCoreCLI@2
displayName: 'Install ReportGenerator Tool'
inputs:
command: custom
custom: tool
arguments: 'install --global dotnet-reportgenerator-globaltool --version 4.8.11'
- script: 'reportgenerator -reports:$(Agent.TempDirectory)/**/coverage.cobertura.xml -targetdir:$(Build.SourcesDirectory)/coverlet/reports -reporttypes:"Cobertura"'
displayName: 'Generate Code Coverage Report'
- task: PublishCodeCoverageResults@1
displayName: 'Publish Code Coverage Results'
inputs:
codeCoverageTool: Cobertura
summaryFileLocation: '$(Build.SourcesDirectory)/coverlet/reports/Cobertura.xml'
failIfCoverageEmpty: false
- task: DotNetCoreCLI@2
inputs:
command: publish
publishWebProjects: False
arguments: '--configuration $(buildConfiguration) --output $(Build.ArtifactStagingDirectory)'
zipAfterPublish: True
- task: PublishBuildArtifacts@1
inputs:
pathtoPublish: '$(Build.ArtifactStagingDirectory)'
artifactName: 'Functions-Artifact'
The release pipeline is a single task taking the zip files from $(System.DefaultWorkingDirectory)/_Functions-Artifact/Functions-solution/*.zip to deploy the service.
@JacobJGalloway Thanks for the issue! I'm also shocked it requires any test project! Just before going further, could you confirm that:
- You can successfully run your function app locally?
- You can successfully perform the right-click publish to Azure?
@justinyoo That is correct. I can run locally and get the OpenApi UI and if I do a right-click publish zip deploy in Visual Studio, the deployed service does properly render the OpenAPI swagger UI. Question, is there something in the auto-generation using the solution instead of the project file? I was surprised that the auto-generation would know the test project exists.
Question, is there something in the auto-generation using the solution instead of the project file? I was surprised that the auto-generation would know the test project exists.
When building and testing .DLL files for this library, it uses the solution file. But I don't think it's relevant to your test project at all. What if you create a new Function app with a test project and deploy it to Azure through the pipeline?
@JacobJGalloway Can you try this workaround? https://github.com/Azure/azure-functions-openapi-extension/issues/281#issuecomment-942883598
I've experienced the same issue when deploying from a bitbucket pipeline. The workaround that works for me is as follows:
- Configure the solution to not build the unit test project in release
- Update the bitbucket pipeline to use pipe atlassian/azure-functions-deploy:2.0.0 (I was using version 1.0.1)
Another thing I noticed will trying to work around this problem: Using the Azure App service Bash DebugConsole, I was able to copy the unit test dll and xunit dll's to the bin folder. This caused the error message to disapear. Instead it resulted in a default swagger file without any of the information about the function methods.
Facing exactly the same issue. Any solutions. I already tried building from .csproj files instead of .sln file (excluding/including the test project). In some article/solution it was mentioned to add IsPublishable property to false . That also didn't work. Any help would be appreciated. Kind of stuck!