推送snupkg至NuGet.org失败:V3端点配置异常排查
问题描述
我有一个目标框架为net472的.NET Framework项目,通过GitHub Actions使用dotnet CLI 7.0.202执行以下步骤发布到NuGet:
dotnet restore --locked-modedotnet build EngageSoftware.Dnn.Logging.sln --no-restore --configuration ${{ matrix.configuration }} -p:VersionSuffix=${{ env.VERSION_SUFFIX }}dotnet pack EngageSoftware.Dnn.Logging.sln --no-build --configuration ${{ matrix.configuration }} -p:VersionSuffix=${{ env.VERSION_SUFFIX }} --output dist/dotnet nuget push dist/ --source https://api.nuget.org/v3/index.json --symbol-source https://api.nuget.org/v3/index.json --api-key ${{ secrets.NUGET_PUSH_KEY }}
其中nupkg包推送成功,但snupkg符号包推送失败,错误提示需要使用V3端点,尽管我已经通过命令行参数和nuget.config都指定了V3端点。
配置文件
nuget.config
<?xml version="1.0" encoding="utf-8"?> <configuration> <solution> <add key="disableSourceControlIntegration" value="true" /> </solution> <config> <add key="defaultPushSource" value="https://api.nuget.org/v3/index.json" /> </config> <activePackageSource> <add key="All" value="(Aggregate source)" /> </activePackageSource> <packageSources> <add key="nuget.org" value="https://api.nuget.org/v3/index.json" /> </packageSources> <packageSourceMapping> <packageSource key="nuget.org"> <package pattern="*" /> </packageSource> </packageSourceMapping> </configuration>
GitHub Actions 工作流
name: "CI (Build and Package)" on: workflow_dispatch: null push: branches: ["main"] pull_request: branches: ["main"] release: types: ["created"] defaults: run: shell: pwsh jobs: build: strategy: matrix: configuration: ["Release"] runs-on: windows-latest env: NUGET_PACKAGES: "${{ github.workspace }}/.nuget/packages" steps: - name: "Checkout" uses: actions/checkout@v3.4.0 - name: "Setup .NET SDK" uses: actions/setup-dotnet@v3.0.3 with: dotnet-version: "7.0.x" - uses: actions/cache@v3 with: path: "${{ env.NUGET_PACKAGES }}" key: "${{ runner.os }}-nuget-${{ hashFiles('**/packages.lock.json') }}" restore-keys: "${{ runner.os }}-nuget-" - name: "Restore NuGet packages" run: dotnet restore --locked-mode - name: "Set version suffix to alpha-${{ github.run_number }}" if: github.event_name != 'release' || github.event.action != 'created' run: 'VERSION_SUFFIX=alpha-${{ github.run_number }}' >> $env:GITHUB_ENV - name: "Build" run: dotnet build EngageSoftware.Dnn.Logging.sln --no-restore --configuration ${{ matrix.configuration }} -p:VersionSuffix=${{ env.VERSION_SUFFIX }} - name: "Package" run: dotnet pack EngageSoftware.Dnn.Logging.sln --no-build --configuration ${{ matrix.configuration }} -p:VersionSuffix=${{ env.VERSION_SUFFIX }} --output dist/ - name: "Upload build artifacts" uses: actions/upload-artifact@v3.1.2 with: path: dist/ - name: "Push packages to NuGet" run: dotnet nuget push dist/ --source https://api.nuget.org/v3/index.json --symbol-source https://api.nuget.org/v3/index.json --api-key ${{ secrets.NUGET_PUSH_KEY }}
csproj 文件
<Project Sdk="Microsoft.NET.Sdk"> <PropertyGroup> <TargetFramework>net472</TargetFramework> <Company>Engage</Company> <Authors>Brian Dukes</Authors> <Copyright>Copyright (c) Engage Software (engagesoftware.com)</Copyright> <PackageProjectUrl>https://github.com/EngageSoftware/EngageSoftware.Dnn.Logging</PackageProjectUrl> <PackageIcon>icon.png</PackageIcon> <PackageReadmeFile>README.md</PackageReadmeFile> <PackageTags>dnn-platform logging</PackageTags> <PackageLicenseExpression>MIT</PackageLicenseExpression> <Description><![CDATA[ Reference this project in order to enable dependency injection support for `ILogger<T>` in your DNN Platform site. This implementation wraps DNN's `LoggerSource`, which ties into DNN's custom Log4Net implementation by default. ]]></Description> <VersionPrefix>0.1.0</VersionPrefix> <GenerateDocumentationFile>true</GenerateDocumentationFile> <PublishRepositoryUrl>true</PublishRepositoryUrl> <GeneratePackageOnBuild>false</GeneratePackageOnBuild> <EmbedUntrackedSources>true</EmbedUntrackedSources> <AllowedOutputExtensionsInPackageBuildOutputFolder>$(AllowedOutputExtensionsInPackageBuildOutputFolder);.pdb</AllowedOutputExtensionsInPackageBuildOutputFolder> <IncludeSymbols>true</IncludeSymbols> <SymbolPackageFormat>snupkg</SymbolPackageFormat> <EnableNETAnalyzers>true</EnableNETAnalyzers> <AnalysisMode>AllEnabledByDefault</AnalysisMode> <AnalysisLevel>latest</AnalysisLevel> <ImplicitUsings>enable</ImplicitUsings> <Nullable>enable</Nullable> <LangVersion>latest</LangVersion> </PropertyGroup> <PropertyGroup Condition="'$(GITHUB_ACTIONS)' == 'true'"> <ContinuousIntegrationBuild>true</ContinuousIntegrationBuild> </PropertyGroup> <ItemGroup> <Using Include="System"/> <Using Include="System.Collections.Generic"/> <Using Include="System.Globalization"/> <Using Include="System.IO"/> <Using Include="System.Linq"/> <Using Include="System.Threading"/> <Using Include="System.Threading.Tasks"/> <Using Include="DotNetNuke.DependencyInjection"/> <Using Include="DotNetNuke.Instrumentation"/> <Using Include="JetBrains.Annotations"/> <Using Include="Microsoft.Extensions.DependencyInjection"/> <Using Include="Microsoft.Extensions.DependencyInjection.Extensions"/> <Using Include="Microsoft.Extensions.Logging"/> <Using Remove="System.Net.Http"/> </ItemGroup> <ItemGroup> <AdditionalFiles Include="..\stylecop.json" Link="stylecop.json"/> <None Include="..\icon.png" Pack="true" PackagePath="\"/> <None Include="..\README.md" Pack="true" PackagePath="\"/> </ItemGroup> <ItemGroup> <PackageReference Include="DotNetNuke.DependencyInjection" Version="9.4.0" PrivateAssets="All" ExcludeAssets="runtime"/> <PackageReference Include="DotNetNuke.Instrumentation" Version="9.4.0" PrivateAssets="All" ExcludeAssets="runtime"/> <PackageReference Include="Microsoft.Extensions.Logging" Version="7.0.0"/> <PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.1.1" PrivateAssets="All"/> <PackageReference Include="JetBrains.Annotations" Version="2022.3.1" PrivateAssets="all" ExcludeAssets="runtime"/> <PackageReference Include="StyleCop.Analyzers" Version="1.2.0-beta.435" PrivateAssets="all"> <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> </PackageReference> </ItemGroup> </Project>
解决方案
针对snupkg推送失败的问题,可以尝试以下几种方案:
方案1:分开推送主包与符号包
将原有的批量推送命令拆分为两个独立命令,分别处理nupkg和snupkg:
# 推送主包 dotnet nuget push dist\*.nupkg --source https://api.nuget.org/v3/index.json --api-key ${{ secrets.NUGET_PUSH_KEY }} # 推送符号包 dotnet nuget push dist\*.snupkg --source https://api.nuget.org/v3/index.json --api-key ${{ secrets.NUGET_PUSH_KEY }}
这种方式可以避免dotnet CLI在批量推送时对符号包的源参数处理异常。
方案2:使用nuget.exe替代dotnet nuget push
对于.NET Framework项目,nuget.exe在符号包推送场景下兼容性更稳定。在GitHub Actions中添加nuget.exe安装步骤后执行推送:
- name: Setup NuGet.exe uses: nuget/setup-nuget@v2 with: nuget-version: 'latest' - name: Push packages to NuGet run: nuget push dist\*.nupkg -Source https://api.nuget.org/v3/index.json -SymbolSource https://api.nuget.org/v3/index.json -ApiKey ${{ secrets.NUGET_PUSH_KEY }} -SkipDuplicate
方案3:升级dotnet SDK版本
你当前使用的7.0.202版本可能存在符号推送的已知问题,尝试升级到最新的7.0.x稳定版本(如7.0.400+),修改GitHub Actions中的SDK配置:
- name: "Setup .NET SDK" uses: actions/setup-dotnet@v3.0.3 with: dotnet-version: "7.0.400"
方案4:简化nuget.config配置
移除nuget.config中的<activePackageSource>节点,避免与packageSourceMapping配置冲突:
<?xml version="1.0" encoding="utf-8"?> <configuration> <solution> <add key="disableSourceControlIntegration" value="true" /> </solution> <config> <add key="defaultPushSource" value="https://api.nuget.org/v3/index.json" /> </config> <packageSources> <add key="nuget.org" value="https://api.nuget.org/v3/index.json" /> </packageSources> <packageSourceMapping> <packageSource key="nuget.org"> <package pattern="*" /> </packageSource> </packageSourceMapping> </configuration>
内容的提问来源于stack exchange,提问作者Brian Dukes
相关产品推荐
相关产品推荐

