关于如何解决下面这个管道错误以构建和部署 Web API 有什么建议吗?
它在
Generate OpenAPI definition for ${{ parameters.DocumentName }}
步骤失败,错误意味着它不知道任何项目?
.yaml 文件:
parameters:
- name: ApiFileName
displayName: 'API Definition file name'
default: 'swagger.json'
type: string
- name: DocumentName
displayName: 'Name of the openapi document to extract'
type: string
steps:
- task: ExtractFiles@1
displayName: 'Extract Artifact'
inputs:
archiveFilePatterns: '$(Build.ArtifactStagingDirectory)/*.zip'
destinationFolder: $(System.DefaultWorkingDirectory)\unzipped_artifact\
- task: UseDotNet@2
displayName: 'Force Net 6.0 usage'
inputs:
version: '6.x'
- task: DotNetCoreCLI@2
displayName: 'Tool Manifest'
inputs:
command: 'custom'
custom: 'new'
arguments: 'tool-manifest'
- task: PowerShell@2
displayName: 'Setup CLI tool and variables'
inputs:
targetType: 'inline'
script: |
mkdir $(System.DefaultWorkingDirectory)\openapi_specs\
$version = (Get-Item $(System.DefaultWorkingDirectory)\unzipped_artifact\Swashbuckle.AspNetCore.Swagger.dll).VersionInfo.FileVersionRaw
$versionstring = "{0}.{1}.{2}" -f $version.Major,$version.Minor,$version.Build
$exeName = (Get-ChildItem -Path $(System.DefaultWorkingDirectory)\unzipped_artifact\ -Filter *.exe |Select BaseName).BaseName + ".dll"
Write-Host "##vso[task.setvariable variable=SwaggerToolVersion;]$versionstring"
Write-Host "##vso[task.setvariable variable=ApiStartupName;]$exeName"
Write-Host "Setting tool version to found Swashbuckle.AspNetCore.Swagger version '$versionstring' and API startup DLL to '$exeName'"
- task: DotNetCoreCLI@2
displayName: 'Install Swagger CLI'
inputs:
command: 'custom'
custom: 'tool'
arguments: 'install Swashbuckle.AspNetCore.Cli --version $(SwaggerToolVersion)'
- task: DotNetCoreCLI@2
displayName: 'Generate OpenAPI definition for ${{ parameters.DocumentName }}'
inputs:
command: 'custom'
custom: 'swagger'
arguments: 'tofile --output $(System.DefaultWorkingDirectory)\openapi_specs\${{ parameters.ApiFileName }} $(System.DefaultWorkingDirectory)\unzipped_artifact\$(ApiStartupName) ${{ parameters.DocumentName }}'
- task: CopyFiles@2
displayName: 'Copy API Definition to: $(Build.ArtifactStagingDirectory)'
inputs:
SourceFolder: '$(System.DefaultWorkingDirectory)/openapi_specs/'
Contents: '*.json'
TargetFolder: '$(Build.ArtifactStagingDirectory)'
flattenFolders: true
- template: /Pack&Publish/PackageAPIDefForOctopus.yaml
parameters:
APIDefinitionPath: '$(System.DefaultWorkingDirectory)/openapi_specs/'
错误:
C:\hostedtoolcache\windows\dotnet\dotnet.exe swagger tofile --output D:\a\1\s\openapi_specs\swagger.json D:\a\1\s\unzipped_artifact\Returns.API.dll Returns API
Usage: dotnet swagger tofile [options] [startupassembly] [swaggerdoc]
startupassembly:
relative path to the application's startup assembly
swaggerdoc:
name of the swagger doc you want to retrieve, as configured in your startup class
options:
--output: relative path where the Swagger will be output, defaults to stdout
--host: a specific host to include in the Swagger output
--basepath: a specific basePath to include in the Swagger output
--serializeasv2: output Swagger in the V2 format rather than V3
--yaml: exports swagger in a yaml format
##[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
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 : [ '' ]
##[debug]Processed: ##vso[task.issue type=error;]Dotnet command failed with non-zero exit code on the following projects : [ '' ]
##[debug]Processed: ##vso[task.complete result=Failed;]Dotnet command failed with non-zero exit code on the following projects : [ '' ]
如文档中所述,命令的最后一部分是
swaggerdoc
。
swagger tofile --output [output] [startupassembly] [swaggerdoc]
[output] 是 Swagger JSON 将输出到的相对路径
[startupassemble] 是应用程序启动的相对路径 组装
[swaggerdoc] 是您要检索的 swagger 文档的名称, 按照您的启动类中的配置
它应该与您的
config.SwaggerDoc
中定义的相同,例如v1
或 v1.1
。
services.AddSwaggerGen(c =>
{
c.SwaggerDoc("v1", new OpenApiInfo { Title = "My API - V1", Version = "v1" });
c.SwaggerDoc("v2", new OpenApiInfo { Title = "My API - V2", Version = "v2" });
})
请参阅此处了解更多详情。