如何解决Autorest 生成需要 beta 包的 Client Sdk
我使用 Autorest 为 Azure 函数生成客户端 SDK。
之后,客户端 Sdk 应该被打包并推送到我们的 nuGet 提要。
这些步骤都将通过用于 Azure DevOps 的 yaml
管道完成。
这在过去几个月中非常有效。但最近 Autorest 已停止照常工作。
不幸的是,autorest 会生成一个需要 beta nuGet 包的项目文件。
<PackageReference Include="Microsoft.Azure.AutoRest.CSharp" Version="3.0.0-beta.20210205.2" />
当然,nuGet pack 无法打包具有测试版或预发布依赖项的项目。
- 有人对 autorest 有同样的问题吗?
- 我可以配置 autorest,而不是使用测试包吗?
生成的项目文件如下所示:
<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 的 Pipeline 如下所示:
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 pack 任务因此错误而失败
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.
解决方法
在发布包中使用预发布包是不稳定且危险的。这个错误是为了防止这种情况发生。您可以使用以下几个选项:
将您的软件包标记为预发布
假设您的项目仍在开发中,并且需要利用这个仍在开发中的最新依赖项,只需将您的包也标记为开发中即可。来自Microsoft docs:
如果你的项目使用PackageReference:包含语义版本 .csproj 文件的 PackageVersion 元素中的后缀:
<PropertyGroup>
<PackageVersion>1.0.1-alpha</PackageVersion>
</PropertyGroup>
如果你的项目有一个packages.config文件:包括语义 .nuspec 文件的版本元素中的版本后缀:
<version>1.0.1-alpha</version>
使用最新的稳定版本
回退到使用发布包的依赖项的最新版本。这通常更安全,因为开发中的依赖项可能会引入未知的严重问题。如果项目开发人员认为他们的项目可安全用于生产,他们就会将其标记为安全。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。