0
votes

I have solution contains multi projects, and I'm trying to build Azure devops pipeline on single project (.csproj), when build I have this error.

##[error]C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\MSBuild\Current\Bin\Microsoft.Common.CurrentVersion.targets(5574,5): Error MSB3073: The command "XCOPY /Y D:\a\1\s\XXX\XXX\bin\Release\XXX.dll UndefinedNuget\lib\net40" exited with code 4.

and this is my azure-pipelines.yml file

trigger:
- Sprint47

pool:
  vmImage: 'windows-latest'
  
variables:
  solution: '**/*.sln'
  buildPlatform: 'AnyCPU'
  buildConfiguration: 'Release'

steps:

- task: VSBuild@1
  inputs:
    solution: 'XXX\XXX\XXX.csproj'
    msbuildArgs: '/p:Configuration=Release /p:Platform=AnyCPU /p:DeployOnBuild=true /p:WebPublishMethod=Package /p:PackageAsSingleFile=true /p:SkipInvalidConfigurations=true /p:PackageLocation="$(build.artifactStagingDirectory)"'
    platform: 'AnyCPU'
    configuration: 'Release'

- task: VSTest@2
  inputs:
    platform: '$(buildPlatform)'
    configuration: '$(buildConfiguration)'

- task: PublishBuildArtifacts@1

How I can solve this problem.

1

1 Answers

0
votes

First, you should add the nuget restore task to restore the necessary nuget packages to make sure that the required dlls are copied into bin folder.

Like this:

steps:
- task: NuGetToolInstaller@1   
  inputs:
    versionSpec: 5.x
    
- task: NuGetCommand@2
  inputs:
    restoreSolution: '$(solution)'

- task: VSBuild@1
   inputs:
    solution: 'XXX\XXX\XXX.csproj'
    msbuildArgs: '/p:Configuration=Release /p:Platform=AnyCPU /p:DeployOnBuild=true /p:WebPublishMethod=Package /p:PackageAsSingleFile=true /p:SkipInvalidConfigurations=true /p:PackageLocation="$(build.artifactStagingDirectory)"'
    platform: 'AnyCPU'
    configuration: 'Release'

Besides, you should check the command XCOPY /Y .... under the csproj file. Make sure the xcopy /Y file1 path1 is legal.

I noticed UndefinedNuget\lib\net40 and you should check whether the property is parsed correctly. Use a right property or path.

Also, please add /R additionally to run the command.

Like this:

XCOPY /Y /E /R file1 path1

Do not forget to share the XCOPY command with us to troubleshoot the issue if these above do not help.