5

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.

Bastien Vandamme
  • 17,659
  • 30
  • 118
  • 200
  • Linked to https://stackoverflow.com/q/55796711/196526 – Bastien Vandamme Apr 23 '19 at 08:40
  • Hi Bastien Vandamme; a good way of debugging this kind of pipeline is to install an agent on your development box - then, you can examine the state of the files in the agent's working directory after it has failed. For example, you can check whether a web.config file was present or not. – Vince Bowdren Apr 23 '19 at 08:47
  • Well, here the web.config is not present but I don't want it. ASP.NET Core, I don't need one. So I don't get the error because this is not an error... right? Not right? So what am I missing? And, by the way I just checked again and I have a web.config in my artifact :-s – Bastien Vandamme Apr 23 '19 at 08:54

1 Answers1

11

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.)

Slothario
  • 2,830
  • 3
  • 31
  • 47