What commands are behind the Visual Studio Pack command?

439 Views Asked by At

I'm trying to configure a GitHub workflow that builds my multi-target NuGet package (to be used with Xamarin.Forms) and pushes this package to GitHub and Nuget. I discussed the issue here, and it all seems to boil down to the following:

I cannot use dotnet pack in my workflow, it results in the following error:

C:\Users\user\.nuget\packages\msbuild.sdk.extras\2.1.2\Build\Workarounds.targets(27,5): error : If you are building projects that require targets from full MSBuild or MSBuildFrameworkToolsPath, you need to use desktop msbuild ('msbuild.exe') instead of 'dotnet build' or 'dotnet msbuild' [C:\path\to.csproj]

When I use MSBuild (either manually on my computer, or through the workflow), only the UWP declarations are available, and for all target platforms (Android, iOS, UWP).

When I right-click the class library project and click the Pack command, the resulting package works as expected. All platforms can call the platform-specific declarations.

Question:

Simple, what commands are behind the [Right-click csproj-file] → Pack? I want to try and run these commands manually to figure out what's going on...

Information:

  • msbuild version on my pc: 16.7.0.37604 (located at C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\MSBuild\Current\Bin)
  • msbuild version on GitHub CI: 16.7.0+b89cb5fde
  • dotnet version on GitHub CI: 3.1.301
1

There are 1 best solutions below

0
On BEST ANSWER

Apparently there is a bug in the MSBuild CLI.

When using the following command:

msbuild /t:Pack /p:Configuration=Debug Library/Company.Xamarin.Alert/Company.Xamarin.Alert.csproj

The produced nupkg can be installed in each project of a Xamarin.Forms application, and platform-specific code can be called.

However, when running the same command with the p:OutputPath parameter specified:

msbuild /t:Pack /p:Configuration=Debug /p:OutputPath=../.. Library/Company.Xamarin.Alert/Company.Xamarin.Alert.csproj

The resulting nupkg only contains the definitions for UWP.

I've filed a bug for this here.

My final workflow looks like this:

name: .NET Core

on:
  push:
    branches: [ master ]
  pull_request:
    branches: [ master ]

jobs:
  build:

    runs-on: windows-latest

    steps:
    - name: Checkout
      uses: actions/checkout@v2
    
    - name: Setup .NET Core
      uses: actions/[email protected]
      with:
        dotnet-version: 3.1.301
        # Authenticates packages to push to GPR
        source-url: https://nuget.pkg.github.com/${{ github.repository_owner }}/index.json
      env:
        NUGET_AUTH_TOKEN: '%NUGET_AUTH_TOKEN%'
    
    - name: Setup MSBuild
      uses: microsoft/[email protected]
    
    - name: Install dependencies
      run: msbuild /t:Restore
      env:
        NUGET_AUTH_TOKEN: ${{ github.token }}
    
    - name: Build
      run: msbuild /t:Pack /p:Configuration=Debug Library/MintPlayer.MVVM/MintPlayer.MVVM.csproj
    
    - name: PushNuget
      run: dotnet nuget push "**/*.nupkg" --source https://api.nuget.org/v3/index.json --api-key ${{ secrets.PUBLISH_TO_NUGET_ORG }} --skip-duplicate
    
    - name: PushGithub
      run: nuget.exe push "**/*.nupkg" -NoSymbols -SkipDuplicate
      env:
        NUGET_AUTH_TOKEN: ${{ github.token }}