Publish .net framework nuget package

I can find plenty of documentation about publishing a Nuget dotnet core package to the Github Package Registry and it works great. I cannot find any information about how to publish a .Net Framework Nuget package?

Hi,

For .net framework you should use msbuild CLI instead dotnet CLI. This is example for action with msbuild:

name: dotNet Framework Build

on: [push]

jobs:
  build:

    runs-on: windows-latest

    steps:
      - uses: actions/checkout@master
      - uses: nuget/setup-nuget@v1.0.2
        with:
          nuget-api-key: ${{ secrets.NuGetAPIKey }}
          nuget-version: 'latest'
      - name: Setup MSBuild.exe
        uses: warrenbuckley/Setup-MSBuild@v1
        env:
          working-directory: [ProjectFolder]
      - run: msbuild -t:restore
        working-directory: [ProjectFolder]
      - run: msbuild -t:build
        working-directory: [ProjectFolder]
      - name: Nuget Add Source
        run: nuget sources Add -Name "github" -Source https://nuget.pkg.github.com/[user-or-group-name]/index.json -UserName [your-user-name] -Password ${{ secrets.GITHUB_TOKEN }}
      - name: Nuget SetAPIKey
        run: nuget setapikey ${{ secrets.GITHUB_TOKEN }} -Source "github"
      - name: Publish the package to GitHub packages
        working-directory: [ProjectFolder]
        run: nuget push bin\Debug\*.nupkg -source "github" -SkipDuplicate

In your csproj file you need to add following XML nodes in the first <PropertyGroup>

    <RepositoryUrl>[https://github.com/[user-or-group-name]/ProjectName]</RepositoryUrl>
    <RepositoryType>git</RepositoryType>
    <GeneratePackageOnBuild>true</GeneratePackageOnBuild>
    <PackageOutputPath>bin\debug\</PackageOutputPath>
    <Version>1.0.0</Version>
    <Authors>[your-name]</Authors>

Also you need to migrate from packages.config to PackageReference if you use packages.config.
Migrate from packages.config to PackageReference 

Also you need to install NuGet.Build.Tasks.Pack into your project, without this package msbuild -t:build will not create .nupkg file.

1 Like

That was helpful. 

How do you publish .NetFramework App to Azure App Service through Github Actions?

I was able to do for .NetCore. 

Can you suggest?

The github action steps worked for us in this case. Thank you!

What didn’t work was, we don’t have those XML options in a .net framework project. Only .net core and .net standard csproj files have those elements.

Instead, for my .net framework project I had a .nuspec file in the same directory as my .csproj, So i added the repo information there like so to get it to work:

<package>
  <metadata>
    <repository type="git" url="https://github.com/myusername/my-repo-name" />
  </metadata>
</package>

Also, using any random username and password will also work with the above setup. The apikey will be used to authenticate and the username and password is pretty much ignored as far as I can tell. But not supplying any username or password will cause a failure. So we just put random strings for those values since we don’t want actual user info hardcoded in the yml.