0
votes

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.
2

2 Answers

1
votes

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

The answer is yes. It depends on how many packages you want to generate.

If you want to create one nuget package for 3 projects (iOS, Android, UWP), you should use the .nuspec file.

The path problem is because you are not set the correct path in the .nuspec file. The .nuspec file should be set at the folder that's one level below where the .sln file is. The path to the dll is the relative path where the .nupsec file is stored.

So, the path should be like:

<files>
    <!-- Cross-platform reference assemblies -->
    <file src="XamarinDemo\bin\Release\XamarinDemo.dll" target="lib\netstandard2.0\XamarinDemo.dll" />
    <file src="XamarinDemo\bin\Release\XamarinDemo.xml" target="lib\netstandard2.0\XamarinDemo.xml" />

    <!-- iOS reference assemblies -->
    <file src="XamarinDemo.iOS\bin\Release\XamarinDemo.dll" target="lib\Xamarin.iOS10\XamarinDemo.dll" />
    <file src="XamarinDemo.iOS\bin\Release\XamarinDemo.xml" target="lib\Xamarin.iOS10\XamarinDemo.xml" />

    <!-- Android reference assemblies -->
    <file src="XamarinDemo.Android\bin\Release\XamarinDemo.dll" target="lib\MonoAndroid10\XamarinDemo.dll" />
    <file src="XamarinDemo.Android\bin\Release\XamarinDemo.xml" target="lib\MonoAndroid10\XamarinDemo.xml" />

    <!-- UWP reference assemblies -->
    <file src="XamarinDemo.UWP\bin\Release\XamarinDemo.dll" target="lib\UAP10\XamarinDemo.dll" />
    <file src="XamarinDemo.UWP\bin\Release\XamarinDemo.xml" target="lib\UAP10\XamarinDemo.xml" />
</files>

Check the document Create packages for Xamarin with Visual Studio 2015 for some details.

If you want to create three nuget package for each platform, you can use the a **/*.csproj for the pack.

The reason for your issue is that you need install the .NET core SDK before you build the project/solution:

- task: UseDotNet@2
  displayName: 'Use .Net Core sdk 2.2.105'
  inputs:
    version: 2.2.105

Hope this helps.

0
votes

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.