Search code examples
xamarinazure-devopsdevopspack

Is it possible to publish a Xamarin project to a private nuget package feed in VSTS (DevOps)


A Xamarain project was created and a Devops (VSTS) pipeline was created to build and publish the project to a private nuget feed. Everything builds great, but the step that would Pack the nuget package fails.

1) My first attempt was to use the "Macos-latest" to do an msbuild@1 on the solution. The Nuget installer uses a nuspec file to do the packing. An error show's up in the packing step

2) I then tried to do a VSBuild@1, followed by a DotNetCoreClI@2 without success.

3) I also attempted to split the 3 projects (iOS, Android, UWP) into 3 separated jobs but they failed in the packing step too.

4) I tried various techniques in packing, nuspec files, the csproj file without success.

My YAML file looks like this:

'
- task: NuGetToolInstaller@1 
   displayName: 'Install nuget.exe 4.4.1'
   inputs:      
     versionSpec: 4.4.1'

- task: NuGetCommand@2
  displayName: "restore the ble solution"
  inputs:
    command: 'restore'
    restoreSolution: '**/*.sln'
    feedsToUse: 'select'
    vstsFeed: '$(packageFeedName)'

- task: MSBuild@1
  displayName: 'Build BLE solution'
  inputs:
    solution: "**/*.sln"
    configuration: '$(buildConfiguration)'      
    msbuildArguments: '/p:OutputPath=$(outputDirectory) /p:JavaSdkDirectory="$(JAVA_HOME)/"'

- task: NuGetCommand@2
  displayName: "pack nuget"
  inputs:
    command: pack
    packagesToPack: './myproject.nuspec'
    packDestination: '$(Build.ArtifactStagingDirectory)'
    versioningScheme: byEnvVar
    versionEnvVar: 'nugetVersion'
    includeSymbols: true

'

It always comes down to the same pathing problem with I use a nuspec file.

Attempting to build package from 'BLE.nuspec'. 

[error]The nuget command failed with exit code(1) and error(Could not find a part of the path /Users/vsts/agent/2.155.1/work/1/s/Plugin.BLE/bin/Release/netstandard2.0.

System.IO.DirectoryNotFoundException: Could not find a part of the path /Users/vsts/agent/2.155.1/work/1/s/Plugin.BLE/bin/Release/netstandard2.0.

When I use a **/*.csproj for the pack, I get:

Build FAILED.
d:\a\1\s\Plugin.BLE.Android\Plugin.BLE.Android.csproj" (pack target) (1:2) ->d:\a\1\s\Plugin.BLE.Android\Plugin.BLE.Android.csproj(94,3): error MSB4019: The imported project "C:\Program Files\dotnet\sdk\2.2.105\Xamarin\Android\Xamarin.Android.CSharp.targets" was not found. 
Confirm that the path in the <Import> declaration is correct, and that the file exists on disk.

Solution

  • So, my problem wasn't in my nuspec file; the real problem comes down to using the vmImage : "macos-latest", which is required if you want to build an iOS project (iOS won't build under the agents 2019, or 2017, and you must use MSBuild (not VSBuild)

    The macos-latest image has several issues (which I'll refer to as the iOS agent)

    1. The nuspec package for System.Threading.Task.Extensions (STTE) isn't included when you bring in another nuget package that has a dependency on it. If the package is in the 'Standard .net 2.0 project", then the STTE package must be included in the standard project and the ios project; this only occurs in the ios agent.

    2. The variable I used for the solution path $(solution) did not expand to myproj.sln; the logged showed the path as /$($solution) and the project did not build, no warning or errors that zero projects were built; the problem did not occur in any other agent type that I tested.

    3. The ios agent's Xamarin sdk is woefully out of date and has to be set.

    yaml required:

    variables:
      mono: 5_18_1
      xamarinSDK: 12_8_0_2
    
    
    - task: Bash@3
        displayName: "Set xamarinSDK to version $(mono)"
        inputs:
          targetType: 'inline'
          script: /bin/bash -c "sudo $AGENT_HOMEDIRECTORY/scripts/select-xamarin-sdk.sh $(mono)"
    

    The technique used to figure this out was to split a Xamarin project into 4 separate projects and publish them as separate projects:

    • .Net Standard 2.0
    • UWP
    • Android
    • iOS

    Every project but the iOS one worked using a VSBuild and the 2019 agent; it was then a process of elimination on the ios agent.