Azure Pipelines post-构建事件复制命令失败

Azure Pipelines post-build event copy command failure

当我的 Azure Pipeline 在存在 post-build 事件的项目上进行构建时,我收到复制错误,该事件将构建的 .dll 复制到解决方案中其他位置的文件夹中。

有问题的解决方案是 ASP.NET 核心(更具体地说,是 Blazor 服务器应用程序)。

它应该经历的过程是:

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

来自 .csproj 的 post-build 事件:

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

此副本在 VS 中按预期工作,但我假设这在 Pipelines 中也能正常工作,但我可以看到它抛出了一个错误,所以我可能缺少某些东西或我的步骤需要在 Pipelines 中进行制作才能成功执行此复制操作。

根据我在日志中看到的内容,“复制”命令失败,但正如我所提到的,这在 VS 中运行良好,但一旦 Pipelines 尝试构建,复制命令就会失败!

我的问题构建管道配置:

- 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,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.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,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.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,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.2620562Z Shared/Layouts/FrontEndLayout.razor(130,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.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,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.2719017Z Pages/Account/Contact.razor(104,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.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,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.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

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

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

2020-09-22T22:34:01.2363173Z /bin/sh: 2: tmp/tmp2e509e5e0d8a4a0dbf2e8ff4c7235b88.exec.cmd: copy: not found

运行 您在 Windows 代理上构建或使用 MSBuild 的 built-in Copy 任务:

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