Azure DevOps 构建管道中的 NUKE 构建失败

NUKE Build in Azure DevOps Build Pipeline Failing

所以我在我的解决方案中实施了 NUKE 构建系统,并且一切都 100% 在本地工作。

在 Azure DevOps 中是另一回事,我的 YAML 任务如下所示:

- task: CmdLine@2
  displayName: 'NUKE Build'
  inputs:
    script:
      .\src\build package --cfg $(buildConfiguration) --pak $(Build.ArtifactStagingDirectory)

而 NUKE 确实 运行,但它失败并出现错误,指出它无法找到我的解决方案文件:

Expected file to exist: D:\a\s\**\*.sln

下面是整个命令行日志输出:

2022-04-08T18:39:07.9969860Z ##[section]Starting: NUKE Build
2022-04-08T18:39:08.0228304Z ==============================================================================
2022-04-08T18:39:08.0228652Z Task         : Command line
2022-04-08T18:39:08.0228978Z Description  : Run a command line script using Bash on Linux and macOS and cmd.exe on Windows
2022-04-08T18:39:08.0229274Z Version      : 2.201.1
2022-04-08T18:39:08.0229490Z Author       : Microsoft Corporation
2022-04-08T18:39:08.0230495Z Help         : https://docs.microsoft.com/azure/devops/pipelines/tasks/utility/command-line
2022-04-08T18:39:08.0230888Z ==============================================================================
2022-04-08T18:39:09.5867757Z Generating script.
2022-04-08T18:39:09.6086899Z Script contents: shell
2022-04-08T18:39:09.6117246Z .\src\build package --cfg Release --pak D:\a\a
2022-04-08T18:39:09.6712303Z ========================== Starting Command Output ===========================
2022-04-08T18:39:09.7222712Z ##[command]"C:\Windows\system32\cmd.exe" /D /E:ON /V:OFF /S /C "CALL "D:\a\_temp\ec061a9c-d293-42ca-8b24-3d57ab43d6b1.cmd""
2022-04-08T18:39:10.1964079Z PowerShell Desktop version 5.1.20348.558
2022-04-08T18:39:11.9025685Z Microsoft (R) .NET Core SDK version 6.0.201
2022-04-08T18:39:12.1269858Z 
2022-04-08T18:39:12.1299946Z Welcome to .NET 6.0!
2022-04-08T18:39:12.1300642Z ---------------------
2022-04-08T18:39:12.1301057Z SDK Version: 6.0.201
2022-04-08T18:39:12.1301258Z 
2022-04-08T18:39:12.1301590Z ----------------
2022-04-08T18:39:12.1302080Z Installed an ASP.NET Core HTTPS development certificate.
2022-04-08T18:39:12.1303932Z To trust the certificate run 'dotnet dev-certs https --trust' (Windows and macOS only).
2022-04-08T18:39:12.1304429Z Learn about HTTPS: https://aka.ms/dotnet-https
2022-04-08T18:39:12.1305954Z ----------------
2022-04-08T18:39:12.1306300Z Write your first app: https://aka.ms/dotnet-hello-world
2022-04-08T18:39:12.1306678Z Find out what's new: https://aka.ms/dotnet-whats-new
2022-04-08T18:39:12.1307948Z Explore documentation: https://aka.ms/dotnet-docs
2022-04-08T18:39:12.1308586Z Report issues and find source on GitHub: https://github.com/dotnet/core
2022-04-08T18:39:12.1309267Z Use 'dotnet --help' to see available commands or visit: https://aka.ms/dotnet-cli
2022-04-08T18:39:12.1311891Z --------------------------------------------------------------------------------------
2022-04-08T18:39:27.0014563Z ##[warning]Exception has been thrown by the target of an invocation.
2022-04-08T18:39:27.1770000Z [90m18:39:26[0m[90m [[0m[33;1mWRN[0m[90m] [0mException has been thrown by the target of an invocation.[0m
2022-04-08T18:39:27.1771426Z System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation.[0m
2022-04-08T18:39:27.1773524Z  ---> System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation.[0m
2022-04-08T18:39:27.1774228Z  ---> System.ArgumentException: Expected file to exist: D:\a\s\**\*.sln (Parameter 'path')[0m
2022-04-08T18:39:27.1774784Z [90m   at Nuke.Common.Assert.FileExists(String path, String message, String argumentExpression)[0m
2022-04-08T18:39:27.1775284Z [90m   at Nuke.Common.IO.TextTasks.ReadAllLines(String path, Encoding encoding)[0m
2022-04-08T18:39:27.1775809Z [90m   at Nuke.Common.ProjectModel.SolutionSerializer.DeserializeFromFile[T](String solutionFile)[0m
2022-04-08T18:39:27.1776522Z [90m   --- End of inner exception stack trace ---[0m
2022-04-08T18:39:27.1777060Z [90m   at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor, Boolean wrapExceptions)[0m
2022-04-08T18:39:27.1778369Z [90m   at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)[0m
2022-04-08T18:39:27.1779002Z [90m   at System.Reflection.MethodBase.Invoke(Object obj, Object[] parameters)[0m
2022-04-08T18:39:27.1779785Z [90m   at Nuke.Common.ProjectModel.SolutionAttribute.GetValue(MemberInfo member, Object instance)[0m
2022-04-08T18:39:27.1782574Z [90m   at Nuke.Common.ValueInjection.ValueInjectionAttributeBase.<>c__DisplayClass0_0.<TryGetValue>b__0()[0m
2022-04-08T18:39:27.1783085Z [90m   --- End of inner exception stack trace ---[0m
2022-04-08T18:39:27.1783634Z [90m   at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor, Boolean wrapExceptions)[0m
2022-04-08T18:39:27.1784428Z [90m   at System.Delegate.DynamicInvokeImpl(Object[] args)[0m
2022-04-08T18:39:27.1784965Z [90m   at System.Delegate.DynamicInvoke(Object[] args)[0m
2022-04-08T18:39:27.1786056Z [90m   at Nuke.Common.ControlFlow.SuppressErrorsIf(Boolean condition, Delegate action, Object defaultValue, Boolean includeStackTrace, Boolean logWarning)[0m
2022-04-08T18:39:27.2272867Z ?
2022-04-08T18:39:27.2274719Z [97;1m¦¦¦+   ¦¦+¦¦+   ¦¦+¦¦+  ¦¦+¦¦¦¦¦¦¦+[0m
2022-04-08T18:39:27.2275048Z [97;1m¦¦¦¦+  ¦¦¦¦¦¦   ¦¦¦¦¦¦ ¦¦++¦¦+----+[0m
2022-04-08T18:39:27.2275514Z [97;1m¦¦+¦¦+ ¦¦¦¦¦¦   ¦¦¦¦¦¦¦¦++ ¦¦¦¦¦+  [0m
2022-04-08T18:39:27.2275785Z [97;1m¦¦¦+¦¦+¦¦¦¦¦¦   ¦¦¦¦¦+-¦¦+ ¦¦+--+  [0m
2022-04-08T18:39:27.2276070Z [97;1m¦¦¦ +¦¦¦¦¦+¦¦¦¦¦¦++¦¦¦  ¦¦+¦¦¦¦¦¦¦+[0m
2022-04-08T18:39:27.2276350Z [97;1m+-+  +---+ +-----+ +-+  +-++------+[0m
2022-04-08T18:39:27.2276564Z ?
2022-04-08T18:39:27.2437288Z [36;1mNUKE Execution Engine version 6.0.1 (Windows,.NETCoreApp,Version=v5.0)[0m
2022-04-08T18:39:27.2438057Z ?
2022-04-08T18:39:27.7707082Z ##[warning]Could not complete checking build configurations within 500 milliseconds
2022-04-08T18:39:27.7732088Z [90m18:39:27[0m[90m [[0m[33;1mWRN[0m[90m] [0mCould not complete checking build configurations within [0m[36;1m500[0m milliseconds[0m
2022-04-08T18:39:31.8279552Z ##[group]Restore
2022-04-08T18:39:31.8446550Z ##[error]Target "Restore" failed
2022-04-08T18:39:31.8794936Z [90m18:39:31[0m[90m [[0m[31;1mERR[0m[90m] [0mTarget [0m[36;1mRestore[0m failed[0m
2022-04-08T18:39:31.8796042Z System.NullReferenceException: Object reference not set to an instance of an object.[0m
2022-04-08T18:39:31.8796591Z [90m   at Nuke.Common.ProjectModel.Solution.op_Implicit(Solution solution)[0m
2022-04-08T18:39:31.8797101Z [90m   at Build.<get_Restore>b__20_2(MSBuildSettings s) in D:\a\s\build\Build.cs:line 77[0m
2022-04-08T18:39:31.8797732Z [90m   at Nuke.Common.Tools.MSBuild.MSBuildTasks.MSBuild(Configure`1 configurator)[0m
2022-04-08T18:39:31.8798459Z [90m   at Build.<get_Restore>b__20_1() in D:\a\s\build\Build.cs:line 77[0m
2022-04-08T18:39:31.8798994Z [90m   at Nuke.Common.Execution.BuildExecutor.<>c.<Execute>b__4_2(Action x)[0m
2022-04-08T18:39:31.8799610Z [90m   at Nuke.Common.Utilities.Collections.EnumerableExtensions.ForEach[T](IEnumerable`1 enumerable, Action`1 action)[0m
2022-04-08T18:39:31.8800407Z [90m   at Nuke.Common.Execution.BuildExecutor.Execute(NukeBuild build, ExecutableTarget target, IReadOnlyCollection`1 previouslyExecutedTargets, Boolean failureMode)[0m
2022-04-08T18:39:31.8817982Z ##[endgroup]Restore
2022-04-08T18:39:31.8863504Z ##[group]Warnings & Errors
2022-04-08T18:39:31.8882060Z [90m[[0m[33;1mWRN[0m[90m] [0m[90m[0m[90m: [0mException has been thrown by the target of an invocation.[0m
2022-04-08T18:39:31.8884458Z [90m[[0m[33;1mWRN[0m[90m] [0m[90m[0m[90m: [0mCould not complete checking build configurations within [0m[36;1m500[0m milliseconds[0m
2022-04-08T18:39:31.8888070Z [90m[[0m[31;1mERR[0m[90m] [0m[90mRestore[0m[90m: [0mTarget [0m[36;1mRestore[0m failed[0m
2022-04-08T18:39:31.8889294Z ##[endgroup]Warnings & Errors
2022-04-08T18:39:31.8932545Z ?
2022-04-08T18:39:31.8933184Z [97;1m---------------------------------------[0m
2022-04-08T18:39:31.8933694Z [36;1mTarget             Status      Duration[0m
2022-04-08T18:39:31.8935167Z [97;1m---------------------------------------[0m
2022-04-08T18:39:31.9029244Z [31;1mRestore            Failed        < 1sec   // NullReferenceException: Object reference not set to an instance of an object.[0m
2022-04-08T18:39:31.9032700Z [33;1mPreBuild           NotRun              [0m
2022-04-08T18:39:31.9033326Z [33;1mBuildFrontend      NotRun              [0m
2022-04-08T18:39:31.9034546Z [33;1mCompile            NotRun              [0m
2022-04-08T18:39:31.9035764Z [33;1mPublish            NotRun              [0m
2022-04-08T18:39:31.9036389Z [33;1mPackage            NotRun              [0m
2022-04-08T18:39:31.9036847Z [97;1m---------------------------------------[0m
2022-04-08T18:39:31.9037329Z [36;1mTotal                            < 1sec[0m
2022-04-08T18:39:31.9037792Z [97;1m---------------------------------------[0m
2022-04-08T18:39:31.9038298Z ?
2022-04-08T18:39:31.9054882Z [31;1mBuild failed on 4/8/2022 6:39:31 PM. (?°?°)?? ???[0m
2022-04-08T18:39:32.1509226Z ##[error]Cmd.exe exited with code '-1'.
2022-04-08T18:39:32.2145341Z ##[section]Finishing: NUKE Build

但我确实有解决方案文件:

D:\a\s\src\MySolution.sln

我添加了一个 YAML 任务以 100% 确认它在那里(并且它在那里):

- task: CmdLine@2
  displayName: 'List Source Folder'
  inputs:
    script: 'tree $(Build.SourcesDirectory) /f'

这是清单:

2022-04-08T18:57:59.6501952Z ##[section]Starting: List Source Folder
2022-04-08T18:57:59.6793825Z ==============================================================================
2022-04-08T18:57:59.6794430Z Task         : Command line
2022-04-08T18:57:59.6794753Z Description  : Run a command line script using Bash on Linux and macOS and cmd.exe on Windows
2022-04-08T18:57:59.6795061Z Version      : 2.201.1
2022-04-08T18:57:59.6795267Z Author       : Microsoft Corporation
2022-04-08T18:57:59.6795600Z Help         : https://docs.microsoft.com/azure/devops/pipelines/tasks/utility/command-line
2022-04-08T18:57:59.6795961Z ==============================================================================
2022-04-08T18:58:02.0506033Z Generating script.
2022-04-08T18:58:02.0739760Z Script contents: shell
2022-04-08T18:58:02.0756595Z tree D:\a\s /f
2022-04-08T18:58:02.1475179Z ========================== Starting Command Output ===========================
2022-04-08T18:58:02.1898242Z ##[command]"C:\Windows\system32\cmd.exe" /D /E:ON /V:OFF /S /C "CALL "D:\a\_tempda783bd-9a97-4da8-8bef-3d739b2a3128.cmd""
2022-04-08T18:58:02.2402115Z Folder PATH listing for volume Temp
2022-04-08T18:58:02.2403508Z Volume serial number is 00000247 52D3:EF1F
2022-04-08T18:58:02.2404144Z D:\A\S
2022-04-08T18:58:02.2405018Z |   .gitignore
2022-04-08T18:58:02.2405560Z |   azure-pipelines.yml
2022-04-08T18:58:02.2406147Z |   clean.bat
2022-04-08T18:58:02.2406717Z |   nuget.config
2022-04-08T18:58:02.2407288Z |   README.md
2022-04-08T18:58:02.2407842Z |   
2022-04-08T18:58:02.2408341Z +---.nuke
2022-04-08T18:58:02.2409000Z |       build.schema.json
2022-04-08T18:58:02.2409391Z |       parameters.json
2022-04-08T18:58:02.2409867Z |       
2022-04-08T18:58:02.2410372Z +---build
2022-04-08T18:58:02.2410926Z |       .editorconfig
2022-04-08T18:58:02.2411502Z |       Build.cs
2022-04-08T18:58:02.2412097Z |       Configuration.cs
2022-04-08T18:58:02.2412876Z |       Directory.Build.props
2022-04-08T18:58:02.2413461Z |       Directory.Build.targets
2022-04-08T18:58:02.2414211Z |       _build.csproj
2022-04-08T18:58:02.2414923Z |       _build.csproj.DotSettings
2022-04-08T18:58:02.2415470Z |       
2022-04-08T18:58:02.2535989Z +---src
2022-04-08T18:58:02.2536325Z     |   build.cmd
2022-04-08T18:58:02.2536699Z     |   build.ps1
2022-04-08T18:58:02.2536957Z     |   build.sh
2022-04-08T18:58:02.2537193Z     |   MySolution.sln
2022-04-08T18:58:02.2537398Z     |   
.
.
.
Lot's of project folders/files here (removed for brevity)
.
.
.
2022-04-08T18:58:02.3340758Z                     
2022-04-08T18:58:02.3743539Z ##[section]Finishing: List Source Folder

我很茫然(为什么找不到它?),有人知道为什么会这样吗?

.nuke 标记根目录,因此您的解决方案文件位于从那里开始的 ./src/MySolution.sln 下,并且还应该像 parameters.json

中那样注意

原来……我以为是NUKE在找解决方案文件,其实完全不是这样。

错误:

Expected file to exist: D:\a\s\**\*.sln

是由于存在通常添加到标准 YAML 管道文件(用于 NuGet/MSBuild 任务)的变量,即

variables:
  solution: '**/*.sln'
  buildPlatform: 'Any CPU'
  buildConfiguration: 'Release'

- task: NuGetCommand@2
  displayName: 'Restore'
  inputs:
    command: 'restore'
    restoreSolution: '$(solution)'
    feedsToUse: 'config'
    nugetConfigPath: './nuget.config'

- task: VSBuild@1
  displayName: 'Build'
  inputs:
    solution: '$(solution)'
    msbuildArgs: '/p:DeployOnBuild=true /p:WebPublishMethod=Package /p:PackageAsSingleFile=true /p:SkipInvalidConfigurations=true /p:PackageLocation="$(build.artifactStagingDirectory)"'
    platform: '$(buildPlatform)'
    configuration: '$(buildConfiguration)'

解决方案:'**/*.sln' 以某种方式覆盖了 parameters.json 文件中配置的解决方案值。不能 100% 确定为什么......但是一旦环境变量被删除,NUKE 开始按预期工作。