Azure Pipelines生成后事件复制命令失败

问题描述

当我的Azure Pipeline在存在生成后事件的项目上进行构建时,我遇到复制错误,该事件将生成的.dll复制到解决方案中的其他文件夹中。

有问题的解决方案是ASP.NET Core(更具体地说是Blazor Server App)。

它应该经历的过程是:

  1. 构建项目
  2. 构建后事件将项目bin文件夹中生成的.dll复制到同一解决方案中另一个项目中的Modules文件夹中

.csproj中的构建后事件:

  <Target Name="PostBuild" AfterTargets="PostBuildEvent">
    <Exec Command="copy $(TargetPath) $(SolutionDir)Server\MySolution.Server\Modules\" />
  </Target>

此副本可以在VS中按预期方式工作,但是我已经假设它也可以在Pipelines中正常工作,但是我可以看到它在上面抛出了错误,因此可能缺少某些内容或需要采取的步骤在管道中进行制作以允许成功执行此复制操作。

根据我在日志中看到的内容,“ copy”命令失败,但是正如我提到的那样,这在VS中工作正常,但是一旦管道尝试构建,复制命令就会失败!

有关构建的“我的管道”配置:

- task: DotNetCoreCLI@2
  displayName: 'Build Solution'
  inputs:
    command: 'build'
    projects: 'MySolution/MySolution.sln'

我看到的有关复制失败的特定错误

2020-09-22T22:34:01.2727771Z /home/vsts/work/1/s/MySolution/Shared/Modules/MySolution.Theme.Material/MySolution.Theme.Material.csproj(36,5): error MSB3073: The command "copy /home/vsts/work/1/s/MySolution/Shared/Modules/MySolution.Theme.Material/bin/Debug/netstandard2.1/MySolution.Theme.Material.dll /home/vsts/work/1/s/MySolution/Server\MySolution.Server\Modules\" exited with code 127.

包含错误(出于完整性)的完整输出

2020-09-22T22:33:33.5852128Z ##[section]Starting: Build Solution
2020-09-22T22:33:33.5866102Z ==============================================================================
2020-09-22T22:33:33.5866437Z Task         : .NET Core
2020-09-22T22:33:33.5866800Z Description  : Build,test,package,or publish a dotnet application,or run a custom dotnet command
2020-09-22T22:33:33.5867126Z Version      : 2.175.0
2020-09-22T22:33:33.5867363Z Author       : Microsoft Corporation
2020-09-22T22:33:33.5867729Z Help         : https://docs.microsoft.com/azure/devops/pipelines/tasks/build/dotnet-core-cli
2020-09-22T22:33:33.5868125Z ==============================================================================
2020-09-22T22:33:33.9961797Z Info: .NET Core SDK/runtime 2.2 and 3.0 are Now End of Life(EOL) and have been removed from all hosted agents. If you're using these SDK/runtimes on hosted agents,kindly upgrade to newer versions which are not EOL,or else use UseDotNet task to install the required version.
2020-09-22T22:33:34.0033069Z [command]/usr/bin/dotnet build /home/vsts/work/1/s/MySolution/MySolution.sln -dl:CentralLogger,"/home/vsts/work/_tasks/DotNetCoreCLI_5541a522-603c-47ad-91fc-a4b1d163081b/2.175.0/dotnet-build-helpers/Microsoft.TeamFoundation.distributedTask.MSBuild.Logger.dll"*ForwardingLogger,"/home/vsts/work/_tasks/DotNetCoreCLI_5541a522-603c-47ad-91fc-a4b1d163081b/2.175.0/dotnet-build-helpers/Microsoft.TeamFoundation.distributedTask.MSBuild.Logger.dll"
2020-09-22T22:33:34.2910272Z Microsoft (R) Build Engine version 16.7.0+7fb82e5b2 for .NET
2020-09-22T22:33:34.2911156Z copyright (C) Microsoft Corporation. All rights reserved.
2020-09-22T22:33:34.2911472Z 
2020-09-22T22:33:35.0270052Z   Determining projects to restore...
2020-09-22T22:33:39.3163149Z   Restored /home/vsts/work/1/s/MySolution/Shared/Modules/MySolution.Theme.Material.Demo/MySolution.Theme.Material.Demo.csproj (in 195 ms).
2020-09-22T22:33:40.0504837Z   Restored /home/vsts/work/1/s/MySolution/Shared/Modules/MySolution.Theme.Material/MySolution.Theme.Material.csproj (in 190 ms).
2020-09-22T22:33:40.0540508Z   Restored /home/vsts/work/1/s/MySolution/Shared/Modules/MySolution.Theme.Material.Admin/MySolution.Theme.Material.Admin.csproj (in 160 ms).
2020-09-22T22:34:01.2236036Z   MySolution.Theme.Material -> /home/vsts/work/1/s/MySolution/Shared/Modules/MySolution.Theme.Material/bin/Debug/netstandard2.1/MySolution.Theme.Material.dll
2020-09-22T22:34:01.2363173Z   /bin/sh: 2: /tmp/tmp2e509e5e0d8a4a0dbf2e8ff4c7235b88.exec.cmd: copy: not found
2020-09-22T22:34:01.2380595Z ##[error]MySolution/Shared/Modules/MySolution.Theme.Material/MySolution.Theme.Material.csproj(36,5): Error MSB3073: The command "copy /home/vsts/work/1/s/MySolution/Shared/Modules/MySolution.Theme.Material/bin/Debug/netstandard2.1/MySolution.Theme.Material.dll /home/vsts/work/1/s/MySolution/Server\MySolution.Server\Modules\" exited with code 127.
2020-09-22T22:34:01.2382849Z /home/vsts/work/1/s/MySolution/Shared/Modules/MySolution.Theme.Material/MySolution.Theme.Material.csproj(36,5): error MSB3073: The command "copy /home/vsts/work/1/s/MySolution/Shared/Modules/MySolution.Theme.Material/bin/Debug/netstandard2.1/MySolution.Theme.Material.dll /home/vsts/work/1/s/MySolution/Server\MySolution.Server\Modules\" exited with code 127.
2020-09-22T22:34:01.2582713Z 
2020-09-22T22:34:01.2583274Z Build Failed.
2020-09-22T22:34:01.2583756Z 
2020-09-22T22:34:01.2585185Z Services/Infinity/ThemeChangeSvc.cs(19,22): warning CS0414: The field 'ThemeChangeSvc.isFirst' is assigned but its value is never used [/home/vsts/work/1/s/MySolution/Shared/MySolution.Shared/MySolution.Shared.csproj]
2020-09-22T22:34:01.2587083Z /usr/share/dotnet/sdk/3.1.402/Microsoft.Common.CurrentVersion.targets(2084,5): warning MSB3277: Found conflicts between different versions of "Microsoft.CodeAnalysis" that Could not be resolved.  These reference conflicts are listed in the build log when log verbosity is set to detailed. [/home/vsts/work/1/s/MySolution/Shared/MySolution.Infrastructure/MySolution.Infrastructure.csproj]
2020-09-22T22:34:01.2588614Z /usr/share/dotnet/sdk/3.1.402/Microsoft.Common.CurrentVersion.targets(2084,5): warning MSB3277: Found conflicts between different versions of "Microsoft.CodeAnalysis.CSharp" that Could not be resolved.  These reference conflicts are listed in the build log when log verbosity is set to detailed. [/home/vsts/work/1/s/MySolution/Shared/MySolution.Infrastructure/MySolution.Infrastructure.csproj]
2020-09-22T22:34:01.2590436Z _Imports.razor(20,7): warning CS0105: The using directive for 'MySolution.Shared.Dto.Account' appeared prevIoUsly in this namespace [/home/vsts/work/1/s/MySolution/Shared/Modules/MySolution.Theme.Material/MySolution.Theme.Material.csproj]
2020-09-22T22:34:01.2594561Z _Imports.razor(22,7): warning CS0105: The using directive for 'MySolution.Shared.Dto.Account' appeared prevIoUsly in this namespace [/home/vsts/work/1/s/MySolution/Shared/Modules/MySolution.Theme.Material/MySolution.Theme.Material.csproj]
2020-09-22T22:34:01.2595871Z _Imports.razor(26,7): warning CS0105: The using directive for 'MySolution.Shared.Data' appeared prevIoUsly in this namespace [/home/vsts/work/1/s/MySolution/Shared/Modules/MySolution.Theme.Material/MySolution.Theme.Material.csproj]
2020-09-22T22:34:01.2597755Z Pages/ExternalAuth/Success.razor(21,35): warning CS1998: This async method lacks 'await' operators and will run synchronously. Consider using the 'await' operator to await non-blocking API calls,or 'await Task.Run(...)' to do cpu-bound work on a background thread. [/home/vsts/work/1/s/MySolution/Shared/Modules/MySolution.Theme.Material/MySolution.Theme.Material.csproj]
2020-09-22T22:34:01.2599598Z Shared/Layouts/FrontEndLayout.razor(130,or 'await Task.Run(...)' to do cpu-bound work on a background thread. [/home/vsts/work/1/s/MySolution/Shared/Modules/MySolution.Theme.Material/MySolution.Theme.Material.csproj]
2020-09-22T22:34:01.2601156Z Shared/Layouts/FrontEndLayout.razor(146,30): warning CS0168: The variable 'ex' is declared but never used [/home/vsts/work/1/s/MySolution/Shared/Modules/MySolution.Theme.Material/MySolution.Theme.Material.csproj]
2020-09-22T22:34:01.2602997Z Pages/Account/Contact.razor(104,or 'await Task.Run(...)' to do cpu-bound work on a background thread. [/home/vsts/work/1/s/MySolution/Shared/Modules/MySolution.Theme.Material/MySolution.Theme.Material.csproj]
2020-09-22T22:34:01.2604537Z Pages/Account/Login.razor(276,26): warning CS0168: The variable 'ex' is declared but never used [/home/vsts/work/1/s/MySolution/Shared/Modules/MySolution.Theme.Material/MySolution.Theme.Material.csproj]
2020-09-22T22:34:01.2606141Z Shared/Components/Breadcrumbs.razor(60,74): warning CS4014: Because this call is not awaited,execution of the current method continues before the call is completed. Consider applying the 'await' operator to the result of the call. [/home/vsts/work/1/s/MySolution/Shared/Modules/MySolution.Theme.Material/MySolution.Theme.Material.csproj]
2020-09-22T22:34:01.2607637Z Pages/Account/Profile.razor(325,26): warning CS0168: The variable 'ex' is declared but never used [/home/vsts/work/1/s/MySolution/Shared/Modules/MySolution.Theme.Material/MySolution.Theme.Material.csproj]
2020-09-22T22:34:01.2609316Z Pages/Account/Profile.razor(332,54): warning CS1998: This async method lacks 'await' operators and will run synchronously. Consider using the 'await' operator to await non-blocking API calls,or 'await Task.Run(...)' to do cpu-bound work on a background thread. [/home/vsts/work/1/s/MySolution/Shared/Modules/MySolution.Theme.Material/MySolution.Theme.Material.csproj]
2020-09-22T22:34:01.2610765Z /usr/share/dotnet/sdk/3.1.402/Microsoft.Common.CurrentVersion.targets(2084,5): warning MSB3277: Found conflicts between different versions of "Microsoft.CodeAnalysis" that Could not be resolved.  These reference conflicts are listed in the build log when log verbosity is set to detailed. [/home/vsts/work/1/s/MySolution/Server/MySolution.Storage/MySolution.Storage.csproj]
2020-09-22T22:34:01.2612279Z /usr/share/dotnet/sdk/3.1.402/Microsoft.Common.CurrentVersion.targets(2084,5): warning MSB3277: Found conflicts between different versions of "Microsoft.CodeAnalysis.CSharp" that Could not be resolved.  These reference conflicts are listed in the build log when log verbosity is set to detailed. [/home/vsts/work/1/s/MySolution/Server/MySolution.Storage/MySolution.Storage.csproj]
2020-09-22T22:34:01.2613833Z _Imports.razor(20,7): warning CS0105: The using directive for 'MySolution.Shared.Dto.Account' appeared prevIoUsly in this namespace [/home/vsts/work/1/s/MySolution/Shared/Modules/MySolution.Theme.Material/MySolution.Theme.Material.csproj]
2020-09-22T22:34:01.2615276Z _Imports.razor(22,7): warning CS0105: The using directive for 'MySolution.Shared.Dto.Account' appeared prevIoUsly in this namespace [/home/vsts/work/1/s/MySolution/Shared/Modules/MySolution.Theme.Material/MySolution.Theme.Material.csproj]
2020-09-22T22:34:01.2616604Z _Imports.razor(26,7): warning CS0105: The using directive for 'MySolution.Shared.Data' appeared prevIoUsly in this namespace [/home/vsts/work/1/s/MySolution/Shared/Modules/MySolution.Theme.Material/MySolution.Theme.Material.csproj]
2020-09-22T22:34:01.2618521Z Pages/ExternalAuth/Success.razor(21,or 'await Task.Run(...)' to do cpu-bound work on a background thread. [/home/vsts/work/1/s/MySolution/Shared/Modules/MySolution.Theme.Material/MySolution.Theme.Material.csproj]
2020-09-22T22:34:01.2620562Z Shared/Layouts/FrontEndLayout.razor(130,or 'await Task.Run(...)' to do cpu-bound work on a background thread. [/home/vsts/work/1/s/MySolution/Shared/Modules/MySolution.Theme.Material/MySolution.Theme.Material.csproj]
2020-09-22T22:34:01.2715254Z Shared/Layouts/FrontEndLayout.razor(146,30): warning CS0168: The variable 'ex' is declared but never used [/home/vsts/work/1/s/MySolution/Shared/Modules/MySolution.Theme.Material/MySolution.Theme.Material.csproj]
2020-09-22T22:34:01.2717047Z Shared/Components/Breadcrumbs.razor(60,execution of the current method continues before the call is completed. Consider applying the 'await' operator to the result of the call. [/home/vsts/work/1/s/MySolution/Shared/Modules/MySolution.Theme.Material/MySolution.Theme.Material.csproj]
2020-09-22T22:34:01.2719017Z Pages/Account/Contact.razor(104,or 'await Task.Run(...)' to do cpu-bound work on a background thread. [/home/vsts/work/1/s/MySolution/Shared/Modules/MySolution.Theme.Material/MySolution.Theme.Material.csproj]
2020-09-22T22:34:01.2720552Z Pages/Account/Login.razor(276,26): warning CS0168: The variable 'ex' is declared but never used [/home/vsts/work/1/s/MySolution/Shared/Modules/MySolution.Theme.Material/MySolution.Theme.Material.csproj]
2020-09-22T22:34:01.2723159Z Pages/Account/Profile.razor(325,26): warning CS0168: The variable 'ex' is declared but never used [/home/vsts/work/1/s/MySolution/Shared/Modules/MySolution.Theme.Material/MySolution.Theme.Material.csproj]
2020-09-22T22:34:01.2724872Z Pages/Account/Profile.razor(332,or 'await Task.Run(...)' to do cpu-bound work on a background thread. [/home/vsts/work/1/s/MySolution/Shared/Modules/MySolution.Theme.Material/MySolution.Theme.Material.csproj]
2020-09-22T22:34:01.2726467Z Pages/Account/Login.razor(152,17): warning CS0414: The field 'Login.LoginSuccess' is assigned but its value is never used [/home/vsts/work/1/s/MySolution/Shared/Modules/MySolution.Theme.Material/MySolution.Theme.Material.csproj]
2020-09-22T22:34:01.2727771Z /home/vsts/work/1/s/MySolution/Shared/Modules/MySolution.Theme.Material/MySolution.Theme.Material.csproj(36,5): error MSB3073: The command "copy /home/vsts/work/1/s/MySolution/Shared/Modules/MySolution.Theme.Material/bin/Debug/netstandard2.1/MySolution.Theme.Material.dll /home/vsts/work/1/s/MySolution/Server\MySolution.Server\Modules\" exited with code 127.
2020-09-22T22:34:01.2729322Z     28 Warning(s)
2020-09-22T22:34:01.2729492Z     1 Error(s)
2020-09-22T22:34:01.2729614Z 
2020-09-22T22:34:01.2729796Z Time Elapsed 00:00:26.88
2020-09-22T22:34:01.2882759Z ##[error]Error: The process '/usr/bin/dotnet' Failed with exit code 1
2020-09-22T22:34:01.2888191Z Info: Azure Pipelines hosted agents have been updated to contain .Net Core 3.x (3.1) SDK/Runtime along with 2.1. Unless you have locked down a SDK version for your project(s),3.x SDK might be picked up which might have breaking behavior as compared to prevIoUs versions. 
2020-09-22T22:34:01.2889095Z Some commonly encountered changes are: 
2020-09-22T22:34:01.2890684Z If you're using `Publish` command with -o or --Output argument,you will see that the output folder is Now being created at root directory rather than Project File's directory. To learn about more such changes and troubleshoot,refer here: https://docs.microsoft.com/en-us/azure/devops/pipelines/tasks/build/dotnet-core-cli?view=azure-devops#troubleshooting
2020-09-22T22:34:01.2896528Z ##[error]Dotnet command Failed with non-zero exit code on the following projects : /home/vsts/work/1/s/MySolution/MySolution.sln
2020-09-22T22:34:01.2943673Z ##[section]Finishing: Build Solution

我需要任何进一步的信息,请告诉我。

解决方法

您的构建代理正在运行Linux(路径使用/,并且存在/home目录)。 Linux没有命令copy。它在VS中有效,因为您正在使用Windows。

2020-09-22T22:34:01.2363173Z / bin / sh:2:tmp / tmp2e509e5e0d8a4a0dbf2e8ff4c7235b88.exec.cmd:复制:找不到

要么在Windows代理上运行构建,要么使用MSBuild的内置Copy任务:

<Target Name="CopyAfterBuild" AfterTargets="PostBuildEvent">
  <Copy
    SourceFiles="$(TargetPath)"
    DestinationFolder="$(SolutionDir)Server\MySolution.Server\Modules\"
  />    
</Target>

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...