我使用Autorest为Azure Function生成 Client Sdk 。
之后,应该打包 Client Sdk 并将其推送到我们的 nuGet 提要。
这些步骤都将通过Azure DevOpsyaml
的管道完成。
这在过去几个月里非常有效。但最近 Autorest 已停止照常工作。
不幸的是,autorest 会生成一个需要beta nuGet 包的项目文件。
<PackageReference Include="Microsoft.Azure.AutoRest.CSharp" Version="3.0.0-beta.20210205.2" />
当然,nuGet pack 无法打包具有 beta 或预发布依赖项的项目。
- 有人对自动休息有同样的问题吗?
- 我可以配置 autorest,而不是使用 beta 包吗?
生成的项目文件如下所示:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<Nullable>annotations</Nullable>
</PropertyGroup>
<PropertyGroup>
<LangVersion>8.0</LangVersion>
<IncludeGeneratorSharedCode>true</IncludeGeneratorSharedCode>
<RestoreAdditionalProjectSources>https://azuresdkartifacts.blob.core.windows.net/azure-sdk-tools/index.json</RestoreAdditionalProjectSources>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Azure.AutoRest.CSharp" Version="3.0.0-beta.20210205.2" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Azure.Core" Version="1.6.0" />
</ItemGroup>
</Project>
生成、打包和推送 Client Sdk 的管道如下所示:
steps:
- powershell: 'npm install -g autorest@latest'
displayName: "Install AutoRest"
- task: AzurePowerShell@4
displayName: "Download Swagger"
inputs:
azureSubscription: ${{parameters.subscription}}
scriptType: 'InlineScript'
azurePowerShellVersion: 'LatestVersion'
inline: |
$context = New-AzApiManagementContext -ResourceGroupName "${{parameters.apimResourceGroup}}" -ServiceName "${{parameters.apim}}"
Export-AzApiManagementApi -Context $context -ApiId "$(appName)-development" -SpecificationFormat OpenApi -SaveAs "$(Build.ArtifactStagingDirectory)\definition-$(version).yaml"
- powershell: 'autorest --verbose --v3 --csharp --add-credentials --input-file="$(Build.ArtifactStagingDirectory)\definition-$(version).yaml" --output-folder="$(Build.Repository.LocalPath)\Api\src\ClientSdk" --namespace="ClientSdk" --override-client-name="Client"'
displayName: 'Run AutoRest'
- task: DotNetCoreCLI@2
displayName: "Pack Projects"
inputs:
command: "pack"
arguments: "--configuration $(buildConfiguration) --include-symbols"
packagesToPack: "**/ClientSdk.csproj"
versioningScheme: "off"
verbosityPack: "Normal"
- task: DotNetCoreCLI@2
inputs:
command: 'push'
packagesToPush: '$(Pipeline.Workspace)/**/*.nupkg;!$(Pipeline.Workspace)/**/*.symbols.nupkg'
nuGetFeedType: 'internal'
publishVstsFeed: ${{parameters.nugetfeed}}
nuGet 包任务失败并出现此错误
1>C:\Program Files\dotnet\sdk\5.0.102\Sdks\NuGet.Build.Tasks.Pack\build\NuGet.Build.Tasks.Pack.targets(207,5): error NU5104: A stable release of a package should not have a prerelease dependency. Either modify the version spec of dependency "Microsoft.Azure.AutoRest.CSharp [3.0.0-beta.20210205.2, )" or update the version field in the nuspec.