【问题标题】:Autorest generates Client Sdk that needs a beta packageAutorest 生成需要 beta 包的 Client Sdk
【发布时间】:2021-05-13 13:54:57
【问题描述】:

我使用 AutorestAzure 函数生成客户端 Sdk。

之后应该打包客户端 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 pack 任务失败并出现此错误

1&gt;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.

【问题讨论】:

    标签: azure .net-core nuget azure-functions autorest


    【解决方案1】:

    在发布包中使用预发布包是不稳定且危险的。这个错误是为了防止这种情况发生。您可以使用以下几个选项:

    将您的软件包标记为预发布

    假设您的项目仍在开发中,并且需要利用这个仍在开发中的最新依赖项,只需将您的包也标记为正在开发中。来自Microsoft docs

    如果您的项目使用 PackageReference:包括语义版本 .csproj 文件的 PackageVersion 元素中的后缀:

    <PropertyGroup>
        <PackageVersion>1.0.1-alpha</PackageVersion>
    </PropertyGroup>
    

    如果您的项目有 packages.config 文件:包括语义 .nu​​spec 文件的版本元素中的版本后缀:

    <version>1.0.1-alpha</version>
    

    使用最后一个稳定版本

    回退到使用发布包的依赖项的最后一个版本。这通常更安全,因为开发中的依赖项可能会引入未知的严重问题。如果项目开发人员认为他们的项目可以安全地用于生产,他们会将其标记为这样。

    【讨论】:

    • Autorest 是一个基于 OpenApi / Swagger 生成 Sdk 的工具。我不想使用 beta 或 pre-Release 包,但 autorest 会生成一个需要这个 beta 包的项目。
    • 您的问题表明它以前可以正常工作。因此,请使用以前未使用 beta 包的 Autorest 版本。作为一般规则,最好指定所有依赖项的特定版本,而不是默认的最新版本,这样就不会发生像这样的重大更改。
    • 添加特定版本有效:autorest --version=3.0.6336 ...
    猜你喜欢
    • 1970-01-01
    • 2018-10-29
    • 2019-10-17
    • 2018-02-24
    • 2011-01-16
    • 1970-01-01
    • 2021-11-25
    • 2016-08-13
    • 2015-04-03
    相关资源
    最近更新 更多