我使用Autorest为Azure Function生成客户端Sdk。
之后,客户端 Sdk 应该被打包并推送到我们的 nuGet feed。
这些步骤将全部通过 Azure DevOps 的 yaml
管道完成。
这在过去几个月里效果非常好。但最近 Autorest 已停止正常工作。
不幸的是,autorest 生成了一个需要 beta nuGet 包的项目文件。
<PackageReference Include="Microsoft.Azure.AutoRest.CSharp" Version="3.0.0-beta.20210205.2" />
当然,nuGet pack 无法打包具有测试版或预发布依赖项的项目。
- 有人对自动休息有同样的问题吗?
- 我可以配置自动休息而不使用 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 的 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 包任务失败并出现此错误
1>C:\Program Files\dotnet\sdk\5.0.102\Sdks\NuGet.Build.Tasks.Pack\build\NuGet.Build.Tasks.Pack.targets(207,5):错误NU5104:软件包的稳定版本不应具有预发布依赖性。修改依赖项“Microsoft.Azure.AutoRest.CSharp [3.0.0-beta.20210205.2, )”的版本规范或更新 nuspec 中的版本字段。
最佳答案
在发布包中使用预发布包是不稳定且危险的。这个错误是为了防止这种情况发生。您可以采用以下几种选择:
将您的软件包标记为预发布
假设您的项目仍在开发中,并且需要利用仍在开发中的最新依赖项,只需将您的包标记为正在开发中即可。来自 Microsoft docs :
If your project uses PackageReference: include the semantic version suffix in the .csproj file's PackageVersion element:
<PropertyGroup> <PackageVersion>1.0.1-alpha</PackageVersion> </PropertyGroup>
If your project has a packages.config file: include the semantic version suffix in the .nuspec file's version element:
<version>1.0.1-alpha</version>
使用最后一个稳定版本
回退到使用发布包的依赖项的最新版本。这通常更安全,因为开发中的依赖关系可能会引入未知的严重问题。如果项目开发人员相信他们的项目对于生产使用是安全的,他们就会这样标记。
关于azure - Autorest生成需要beta包的Client Sdk,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66127390/