NRD
NRD

Reputation: 23

How do I Publish using Azure DevOps?

I am trying to setup CI/CD pipeline and publish process for .NET Core 2.1 sample project (it's default project that comes out of the box) using Azure DevOps. So far I have not alter the default code nor have added/removed any references in the project. It's building and running without any error locally.

I have created a simple build pipeline with tasks like Restore, Build and Publish.

For some reason, Publish fails with the following error.

##[section]Starting: Publish
==============================================================================
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.149.0
Author       : Microsoft Corporation
Help         : [More Information](https://go.microsoft.com/fwlink/?linkid=832194)
==============================================================================
[command]C:\windows\system32\chcp.com 65001
Active code page: 65001
[command]"C:\Program Files\dotnet\dotnet.exe" publish "D:\a\1\s\Devops Demo\Devops Demo.csproj" --configuration release --output D:\a\1\a\Devops Demo
Microsoft (R) Build Engine version 15.9.20+g88f5fadfbe for .NET Core
Copyright (C) Microsoft Corporation. All rights reserved.

MSBUILD : error MSB1008: Only one project can be specified.
Switch: Demo

For switch syntax, type "MSBuild /help"
##[error]Error: C:\Program Files\dotnet\dotnet.exe failed with return code: 1
##[error]Dotnet command failed with non-zero exit code on the following projects : D:\a\1\s\Devops Demo\Devops Demo.csproj
##[section]Finishing: Publish

I have Googled and founded several people complaining about this error but no body has any definite solution for it.

So far I have not tried anything fancy in my project and CI/CD config. Above error is a blocker for me as I am unable to proceed with my simple devops setup.

Please let me know if you have any suggestion for me to fix this error.

My YAML is as below,

pool:
  name: Hosted VS2017
#Your build pipeline references an undefined variable named ‘Parameters.RestoreBuildProjects’. Create or edit the build pipeline for this YAML file, define the variable on the Variables tab. See https://go.microsoft.com/fwlink/?linkid=865972
#Your build pipeline references an undefined variable named ‘Parameters.RestoreBuildProjects’. Create or edit the build pipeline for this YAML file, define the variable on the Variables tab. See https://go.microsoft.com/fwlink/?linkid=865972
#Your build pipeline references the ‘BuildConfiguration’ variable, which you’ve selected to be settable at queue time. Create or edit the build pipeline for this YAML file, define the variable on the Variables tab, and then select the option to make it settable at queue time. See https://go.microsoft.com/fwlink/?linkid=865971
#Your build pipeline references the ‘BuildConfiguration’ variable, which you’ve selected to be settable at queue time. Create or edit the build pipeline for this YAML file, define the variable on the Variables tab, and then select the option to make it settable at queue time. See https://go.microsoft.com/fwlink/?linkid=865971

steps:
- task: DotNetCoreCLI@2
  displayName: Restore
  inputs:
    command: restore
    projects: '$(Parameters.RestoreBuildProjects)'

- task: DotNetCoreCLI@2
  displayName: Build
  inputs:
    projects: '$(Parameters.RestoreBuildProjects)'
    arguments: '--configuration $(BuildConfiguration)'

- task: DotNetCoreCLI@2
  displayName: Publish
  inputs:
    command: publish
    publishWebProjects: True
    arguments: '--configuration $(BuildConfiguration) --output $(build.artifactstagingdirectory)'
    workingDirectory: 'Devops Demo'

- task: PublishBuildArtifacts@1
  displayName: 'Publish Artifact'
  inputs:
    PathtoPublish: '$(build.artifactstagingdirectory)'

Upvotes: 2

Views: 7177

Answers (1)

Shayki Abramczyk
Shayki Abramczyk

Reputation: 41545

The error is because in your --output D:\a\1\a\Devops Demo don't have " " and the value is contains space, so just fix the folder name to "D:\a\1\a\Devops Demo".

From the .yaml I can see you use the variable $(build.artifactstagingdirectory) so change it to "$(build.artifactstagingdirectory)".

Upvotes: 5

Related Questions