Search code examples
nugetgithub-actionsdotnet-cli

Error pushing snupkg to nuget.org, unable to configure V3 endpoint


I have a fairly straightforward .NET Framework project (see GitHub repo) that I want to publish to NuGet via GitHub Actions.

I'm using the dotnet CLI for each step (version 7.0.x, currently 7.0.202):

  1. dotnet restore --locked-mode
  2. dotnet build EngageSoftware.Dnn.Logging.sln --no-restore --configuration ${{ matrix.configuration }} -p:VersionSuffix=${{ env.VERSION_SUFFIX }}
  3. dotnet pack EngageSoftware.Dnn.Logging.sln --no-build --configuration ${{ matrix.configuration }} -p:VersionSuffix=${{ env.VERSION_SUFFIX }} --output dist/
  4. 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 }}

That last dotnet nuget push step successfully pushes the nupkg package file, but then fails to push the snupkg file, with the following output:

Run dotnet nuget push dist/ --source https://api.nuget.org/v3/index.json --symbol-source https://api.nuget.org/v3/index.json --api-key ***  
Pushing EngageSoftware.Dnn.Logging.0.1.0-alpha-18.nupkg to 'https://www.nuget.org/api/v2/package'...
  PUT https://www.nuget.org/api/v2/package/
  Created https://www.nuget.org/api/v2/package/ 393ms
Your package was pushed.
Pushing EngageSoftware.Dnn.Logging.0.1.0-alpha-18.snupkg to 'https://www.nuget.org/api/v2/package'...
  PUT https://www.nuget.org/api/v2/package/
  BadRequest https://www.nuget.org/api/v2/package/ 136ms
error: Response status code does not indicate success: 400 (Snupkg upload failed. Please use latest NuGet clients (v 4.9.0 or above) and a V3 endpoint to push Symbol packages. For details, refer https://docs.microsoft.com/nuget/create-packages/symbol-packages-snupkg).

The error indicates that it needs to use the V3 endpoint, even though I'm passing the V3 endpoint via command line arguments, and have it set as the defaultPushSource in nuget.config (it first failed b/c there wasn't a default push source, then I added defaultPushSource and it started working as it does presently, and added the explicit source command line arguments, which did not change anything).

The full nuget.config file:

<?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>

The full GitHub actions YAML file:

{
    "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/[email protected]"
                },
                {
                    "name": "Setup .NET SDK",
                    "uses": "actions/[email protected]",
                    "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/[email protected]",
                    "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 }}"
                }
            ]
        }
    }
}

The full csproj file:

<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`](https://docs.dnncommunity.org/api/DotNetNuke.Instrumentation.LoggerSource.html),
          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>

Solution

  • Try publishing packages one by one with specifying a particular package path instead a folder