Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Setup of azure-pipelines.yml "No web project was found in the repository" with ASP.NET Core

I need help to setup my azure-pipelines.yml build file because I cannot find any good tutorial, sample or other kind of help anywhere.

I follow this tutorial by Microsoft https://learn.microsoft.com/en-us/azure/devops/pipelines/languages/dotnet-core?view=azure-devops but despite all information they give I still get errors.

azure-pipelines.yml

# ASP.NET Core
# Build and test ASP.NET Core projects targeting .NET Core.
# Add steps that run tests, create a NuGet package, deploy, and more:
# https://learn.microsoft.com/azure/devops/pipelines/languages/dotnet-core

trigger:
- master

pool:
  vmImage: 'Ubuntu-16.04'

variables:
  buildConfiguration: 'Release'

steps:
# - script: dotnet build --configuration $(buildConfiguration)
#   displayName: 'dotnet build $(buildConfiguration)'

- task: DotNetCoreInstaller@0
  inputs:
    version: '2.2.202' # replace this value with the version that you need for your project

- script: dotnet restore

- task: DotNetCoreCLI@2
  displayName: Build
  inputs:
    command: build
    projects: '**/*.csproj'
    arguments: '--configuration Release' # Update this to match your need

# do this after you've built your app, near the end of your pipeline in most cases
# for example, you do this before you deploy to an Azure web app on Windows
- task: DotNetCoreCLI@2
  inputs:
    command: publish
    publishWebProjects: True
    arguments: '--configuration $(BuildConfiguration) --output $(Build.ArtifactStagingDirectory)'
    zipAfterPublish: True

- task: PublishBuildArtifacts@1
  inputs:
    ArtifactName: 'drop'

Log

enter image description here

##[section]Starting: DotNetCoreCLI
==============================================================================
Task         : .NET Core
Description  : Build, test, package, or publish a dotnet application, or run a custom dotnet command. For package commands, supports NuGet.org and authenticated feeds like Package Management and MyGet.
Version      : 2.150.1
Author       : Microsoft Corporation
Help         : [More Information](https://go.microsoft.com/fwlink/?linkid=832194)
==============================================================================
##[error]No web project was found in the repository. Web projects are identified by presence of either a web.config file or wwwroot folder in the directory.
##[error]Project file(s) matching the specified pattern were not found.
##[section]Finishing: DotNetCoreCLI

Why these error and what am I doing wrong?

Additional information - I can build and publish from Visual Studio to my Azure web app. My API is working. I just cannot do it as part of CI / CD. - I don't understand this error because I don't understand why the DotNetCore are requesting a web.config.

like image 859
Bastien Vandamme Avatar asked Jan 27 '23 10:01

Bastien Vandamme


1 Answers

It only worked for me when I gave it the path to my Web API (set **/*WebApi.csproj to your own location).

But just as importantly, I had to assure the build agent it was NOT a web project by setting publishWebProjects to false.

- task: DotNetCoreCLI@2
  displayName: '📗📗📗 Publish 📗📗📗'
  inputs:
    command: publish
    projects: '**/*WebApi.csproj'
    publishWebProjects: False
    arguments: '--configuration $(BuildConfiguration) --output $(Build.ArtifactStagingDirectory)'
    zipAfterPublish: True

Q: Are emojis necessary in the publish definition?
A: Yes, emojis are necessary. (Actually, no. But it would be less silly than having to set publishWebProjects to false.)

like image 178
Slothario Avatar answered May 21 '23 03:05

Slothario