##[错误]错误:进程“C:\hostedtoolcache\windows\dotnet\dotnet.exe”失败,退出代码为 1

问题描述 投票:0回答:1

我正在尝试构建一个使用 Azure DevOps CI/CD 管道在 7 上构建的 .NET 项目。我收到此错误。

 In Build Part getting this errors ##[error]Error: The process 'C:\hostedtoolcache\windows\dotnet\dotnet.exe' failed with exit code 1.
##[error] The Dotnet command failed with a non-zero exit code on the following projects: [ 'D:\\a\\1\\s\\src\\Integrations.Services.Configuration.API'

当我将 system.debug 设置为 true 时,我发现存在版本错误。它试图在 .NET 5.x 上构建,而该项目需要在 7.x 上构建。因此,我再次在 Microsoft 托管代理的 .NET Core 安装中将 PerformMultilookup 添加为 true。现在它正在安装 7.x 版本,但仍在尝试使用 5.x 版本构建它。再次,在微软的文章中,我发现需要使用global.json,所以我再次启用它,但是项目中没有global.json。那么,如果 global.json 没有面临构建问题,那么构建这个项目是否需要 global.json ?如果是,那么我需要要求我的开发人员写这个并会尝试,但在此之前,任何没有 global.json 的建议都将帮助我节省时间,有什么办法请帮忙吗?在这里我添加调试日志供您参考。

##[debug]pattern: 'src/Integrations.Services.Configuration.API'
##[debug]findPath: 'D:\a\1\s\src\Integrations.Services.Configuration.API'
##[debug]statOnly: 'true'
##[debug]found 1 paths
##[debug]applying include pattern
##[debug]adjustedPattern: 'D:\a\1\s\src/Integrations.Services.Configuration.API'
##[debug]1 matches
##[debug]1 final results
##[debug]which 'C:\hostedtoolcache\windows\dotnet\dotnet.exe'
##[debug]found: 'C:\hostedtoolcache\windows\dotnet\dotnet.exe'
##[debug]C:\hostedtoolcache\windows\dotnet\dotnet.exe arg: build
##[debug]C:\hostedtoolcache\windows\dotnet\dotnet.exe arg: D:\a\1\s\src\Integrations.Services.Configuration.API
##[debug]C:\hostedtoolcache\windows\dotnet\dotnet.exe arg: -dl:CentralLogger,"D:\a\_tasks\DotNetCoreCLI_5541a522-603c-47ad-91fc-a4b1d163081b\2.235.0\dotnet-build-helpers\Microsoft.TeamFoundation.DistributedTask.MSBuild.Logger.dll"*ForwardingLogger,"D:\a\_tasks\DotNetCoreCLI_5541a522-603c-47ad-91fc-a4b1d163081b\2.235.0\dotnet-build-helpers\Microsoft.TeamFoundation.DistributedTask.MSBuild.Logger.dll"
##[debug]C:\hostedtoolcache\windows\dotnet\dotnet.exe arg: --project $ (BuildConfiguration)
##[debug]exec tool: C:\hostedtoolcache\windows\dotnet\dotnet.exe
##[debug]arguments:
##[debug]   build
##[debug]   D:\a\1\s\src\Integrations.Services.Configuration.API
##[debug]   -dl:CentralLogger,"D:\a\_tasks\DotNetCoreCLI_5541a522-603c-47ad-91fc-a4b1d163081b\2.235.0\dotnet-build-helpers\Microsoft.TeamFoundation.DistributedTask.MSBuild.Logger.dll"*ForwardingLogger,"D:\a\_tasks\DotNetCoreCLI_5541a522-603c-47ad-91fc-a4b1d163081b\2.235.0\dotnet-build-helpers\Microsoft.TeamFoundation.DistributedTask.MSBuild.Logger.dll"
##[debug]   --project
##[debug]   $
##[debug]   (BuildConfiguration)
C:\hostedtoolcache\windows\dotnet\dotnet.exe build D:\a\1\s\src\Integrations.Services.Configuration.API "-dl:CentralLogger,\"D:\a\_tasks\DotNetCoreCLI_5541a522-603c-47ad-91fc-a4b1d163081b\2.235.0\dotnet-build-helpers\Microsoft.TeamFoundation.DistributedTask.MSBuild.Logger.dll\"*ForwardingLogger,\"D:\a\_tasks\DotNetCoreCLI_5541a522-603c-47ad-91fc-a4b1d163081b\2.235.0\dotnet-build-helpers\Microsoft.TeamFoundation.DistributedTask.MSBuild.Logger.dll\"" --project $ (BuildConfiguration)
MSBuild version 17.7.4+3ebbd7c49 for .NET
MSBUILD : error MSB1001: Unknown switch.
    Full command line: 'C:\hostedtoolcache\windows\dotnet\sdk\7.0.405\MSBuild.dll -maxcpucount -verbosity:m -restore -consoleloggerparameters:Summary D:\a\1\s\src\Integrations.Services.Configuration.API -dl:CentralLogger,"D:\a\_tasks\DotNetCoreCLI_5541a522-603c-47ad-91fc-a4b1d163081b\2.235.0\dotnet-build-helpers\Microsoft.TeamFoundation.DistributedTask.MSBuild.Logger.dll"*ForwardingLogger,"D:\a\_tasks\DotNetCoreCLI_5541a522-603c-47ad-91fc-a4b1d163081b\2.235.0\dotnet-build-helpers\Microsoft.TeamFoundation.DistributedTask.MSBuild.Logger.dll" --project $ (BuildConfiguration) -distributedlogger:Microsoft.DotNet.Tools.MSBuild.MSBuildLogger,C:\hostedtoolcache\windows\dotnet\sdk\7.0.405\dotnet.dll*Microsoft.DotNet.Tools.MSBuild.MSBuildForwardingLogger,C:\hostedtoolcache\windows\dotnet\sdk\7.0.405\dotnet.dll'
  Switches appended by response files:
Switch: --project

For switch syntax, type "MSBuild -help"
##[debug]Exit code 1 received from tool 'C:\hostedtoolcache\windows\dotnet\dotnet.exe'
##[debug]STDIO streams have closed for tool 'C:\hostedtoolcache\windows\dotnet\dotnet.exe'
##[error]Error: The process 'C:\hostedtoolcache\windows\dotnet\dotnet.exe' failed with exit code 1
##[debug]Processed: ##vso[task.issue type=error;]Error: The process 'C:\hostedtoolcache\windows\dotnet\dotnet.exe' failed with exit code 1
##[warning].NET 5 has some compatibility issues with older Nuget versions(<=5.7), so if you are using an older Nuget version(and not dotnet cli) to restore, then the dotnet cli commands (e.g. dotnet build) which rely on such restored packages might fail. To mitigate such error, you can either: (1) - Use dotnet cli to restore, (2) - Use Nuget version 5.8 to restore, (3) - Use global.json using an older sdk version(<=3) to build
##[debug]Processed: ##vso[task.issue type=warning;].NET 5 has some compatibility issues with older Nuget versions(<=5.7), so if you are using an older Nuget version(and not dotnet cli) to restore, then the dotnet cli commands (e.g. dotnet build) which rely on such restored packages might fail. To mitigate such error, you can either: (1) - Use dotnet cli to restore, (2) - Use Nuget version 5.8 to restore, (3) - Use global.json using an older sdk version(<=3) to build
Info: Azure Pipelines hosted agents have been updated and now contain .Net 5.x SDK/Runtime along with the older .Net Core version which are currently lts. Unless you have locked down a SDK version for your project(s), 5.x SDK might be picked up which might have breaking behavior as compared to previous versions. You can learn more about the breaking changes here: https://docs.microsoft.com/en-us/dotnet/core/tools/ and https://docs.microsoft.com/en-us/dotnet/core/compatibility/ . 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
##[debug]task result: Failed
##[error]Dotnet command failed with non-zero exit code on the following projects : [ 'D:\\a\\1\\s\\src\\Integrations.Services.Configuration.API' ]
##[debug]Processed: ##vso[task.issue type=error;]Dotnet command failed with non-zero exit code on the following projects : [ 'D:\\a\\1\\s\\src\\Integrations.Services.Configuration.API' ]
##[debug]Processed: ##vso[task.complete result=Failed;]Dotnet command failed with non-zero exit code on the following projects : [ 'D:\\a\\1\\s\\src\\Integrations.Services.Configuration.API' ]
Finishing: Build
.net azure-devops continuous-integration azure-pipelines cicd
1个回答
0
投票

根据您分享的调试日志,似乎您的参数存在一些问题。

--project $ (BuildConfiguration)

下面是我的 yaml 文件,运行良好。你可以参考一下。

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

steps:
- task: NuGetToolInstaller@1

- task: NuGetCommand@2
  inputs:
    restoreSolution: '$(solution)'

- task: VSBuild@1
  inputs:
    solution: '$(solution)'
    msbuildArgs: '/p:DeployOnBuild=true /p:WebPublishMethod=Package /p:PackageAsSingleFile=true /p:SkipInvalidConfigurations=true /p:PackageLocation="$(build.artifactStagingDirectory)"'
    platform: '$(buildPlatform)'
    configuration: '$(buildConfiguration)'
© www.soinside.com 2019 - 2024. All rights reserved.