skip to Main Content

I’m trying to run an Azure pipeline but the build task keeps failing with error codes MSB3021, MSB3027.

I created a project with the weather .NET Core Web API and I want to create an Azure pipeline run with a self-hosted windows agent, but the build task keeps failing with these errors (I removed the paths to my folders):

##[error]C:\agent_work_tooldotnetsdk6.0.419Microsoft.Common.CurrentVersion.targets(4809,5): Error MSB3027: Could not copy "C:.nugetpackagesswashbuckle.aspnetcore.swagger6.2.3libnet6.0Swashbuckle.AspNetCore.Swagger.dll" to "C:\agent_work1sDevOpsProject/DevOpsProject.csprojSwashbuckle.AspNetCore.Swagger.dll". Exceeded retry count of 10. Failed.

Error MSB3021: Unable to copy file "C:Users.nugetpackagesswashbuckle.aspnetcore.swaggerui6.2.3libnet6.0Swashbuckle.AspNetCore.SwaggerUI.dll" to "C:Users\agent_work1sDevOpsProject/DevOpsProject.csprojSwashbuckle.AspNetCore.SwaggerUI.dll". Cannot create ‘C:Users\agent_work1sDevOpsProjectDevOpsProject.csproj’ because a file or directory with the same name already exists.

I don’t know what should I change so it works. Here are my YML files:

Azure pipeline yml:

trigger:
- none

variables:
- template: variables.yml

pool:
  vmImage: ubuntu-latest
  name: FirstAgentsPool

stages:
- stage: BuildValidation
  jobs:
  - job: Build
    steps:
    - task: UseDotNet@2
      inputs:
        version: 6.x
    - task: NuGetCommand@2
      displayName: 'dotnet restore'
      inputs:
        command: 'restore'
        restoreSolution: '$(sln)'
    - task: DotNetCoreCLI@2
      displayName: Build
      inputs:
        command: build
        projects: '$(solution)'
        publishWebProjects: false
        arguments: '--configuration $(buildConfiguration) /p:OutputPath="$(System.DefaultWorkingDirectory)$(solution)"'

Variables.yml:

variables:
  buildConfiguration: Release
  solution: DevOpsProject/DevOpsProject.csproj
  sln: DevOpsProject/DevOpsProject.sln

2

Answers


  1. Your build agent is trying to build in the same path as previous build. You should clean your directory before build.

    - job: cleanDirectory
        workspace:
          clean: outputs | resources | all
    

    This should clean up your directoy just put it before your build job. This is usefull when the build fails for some reason and you wanna build same version of your application.

    Login or Signup to reply.
  2. The value of "OutputPath" property should be a relative path rather than an absolute path. It used to set the path to the output directory of each project. It will create the specified relative path under the directory of each project that needs to be built within a solution, and then put the output of each project into the relative directory under their respective directories.

    enter image description here

    The "OutDir" property is different from the "OutputPath". The "OutDir" can be either a relative or an absolute path, and it can be used to set all the project outputs into one directory within a solution.

    enter image description here

    For more details, you can see "Common MSBuild project properties".


    In addition, when setting the output directories, you should avoid setting the folder names to be same with the project file (xxx.csproj) or solution file (xxx.sln). This might cause conflicts.


    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search