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
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/setup-dotnet#v1.5.0
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/setup-msbuild#v1.0.1
- 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 }}
Related
I'm having trouble ignoring a specific project in my DevOps Pipeline. I have a WPF project in the same solution as my .Net MAUI project and I have a Pipeline for the WPF Solution that works but the .Net MAUI one fails on Nuget Restore because it's Using MAUI and a macOS-12 Image.
- task: DotNetCoreCLI#2
displayName: 'Nuget Restore'
inputs:
command: 'restore'
projects: '**/*.csproj
!**/Portal.Desktop.csproj' # This is supposed to ignore the WPF App
feedsToUse: 'config'
nugetConfigPath: 'nuget.config'
I get a pattern matching error though so apparently that's not right
The Error
Nuget Restore
View raw log
Starting: Nuget Restore
Task : .NET Core
Description : Build, test, package, or publish a dotnet application, or run a custom dotnet command
Version : 2.210.0
Author : Microsoft Corporation
Help : docs.microsoft.com/azure/devops/pipelines/tasks/build/dotnet-core-cli
##[error]No files matched the search pattern.
Finishing: Nuget Restore
I can reproduce the match error via using the below YAML:
trigger:
- none
pool:
vmImage: 'windows-latest'
steps:
- task: DotNetCoreCLI#2
displayName: 'Nuget Restore'
inputs:
command: 'restore'
projects: '
**/*.csproj
!**/TestResultsTests.csproj'
feedsToUse: 'select'
vstsFeed: '1f64a82f-77ad-4770-a098-772faae01ed1'
The error disappear after change my YAML to this:
trigger:
- none
pool:
vmImage: 'windows-latest'
steps:
- task: DotNetCoreCLI#2
displayName: 'Nuget Restore'
inputs:
command: 'restore'
projects: | #Here is where I change.
**/*.csproj
!**/TestResultsTests.csproj
feedsToUse: 'select'
vstsFeed: '1f64a82f-77ad-4770-a098-772faae01ed1'
So the issue should comes from your YAML definition.
This is my repository structure:
I am trying to use azure devops to setup automatic build for my xamarin android application.
I used the default Xamarin.Android build template
# Xamarin.Android
# Build a Xamarin.Android project.
# Add steps that test, sign, and distribute an app, save build artifacts, and more:
# https://learn.microsoft.com/azure/devops/pipelines/languages/xamarin
trigger:
- master
pool:
vmImage: 'windows-latest'
demands:
- MSBuild
- Xamarin.Android
- JDK
variables:
buildConfiguration: 'Release'
outputDirectory: '$(build.binariesDirectory)/$(buildConfiguration)'
steps:
- task: NuGetToolInstaller#1
- task: NuGetCommand#2
inputs:
restoreSolution: '**/*.sln'
- task: XamarinAndroid#1
inputs:
projectFile: '**/*droid*.csproj'
outputDirectory: '$(outputDirectory)'
configuration: '$(buildConfiguration)'
This gives me an error on build
2020-03-26T09:12:32.2752297Z Generating MSBuild file d:\a\1\s\XamarinFormsTry\XamarinFormsTry.Android\obj\XamarinFormsTry.Android.csproj.nuget.g.props.
2020-03-26T09:12:32.2752837Z Generating MSBuild file d:\a\1\s\XamarinFormsTry\XamarinFormsTry.Android\obj\XamarinFormsTry.Android.csproj.nuget.g.targets.
2020-03-26T09:12:32.2753312Z Writing assets file to disk. Path: d:\a\1\s\XamarinFormsTryStandard\obj\project.assets.json
2020-03-26T09:12:32.2753766Z Writing assets file to disk. Path: d:\a\1\s\XamarinFormsTry\XamarinFormsTry.Android\obj\project.assets.json
2020-03-26T09:12:32.2754231Z Writing cache file to disk. Path: d:\a\1\s\XamarinFormsTryStandard\obj\project.nuget.cache
2020-03-26T09:12:32.2754658Z Restore completed in 47.34 sec for d:\a\1\s\XamarinFormsTryStandard\XamarinFormsTry.csproj.
2020-03-26T09:12:32.2755110Z Writing cache file to disk. Path: d:\a\1\s\XamarinFormsTry\XamarinFormsTry.Android\obj\project.nuget.cache
2020-03-26T09:12:32.2755614Z Restore completed in 47.57 sec for d:\a\1\s\XamarinFormsTry\XamarinFormsTry.Android\XamarinFormsTry.Android.csproj.
2020-03-26T09:12:32.2755964Z
2020-03-26T09:12:32.2756107Z NuGet Config files used:
2020-03-26T09:12:32.2756322Z d:\a\1\Nuget\tempNuGet_19.config
2020-03-26T09:12:32.2756470Z
2020-03-26T09:12:32.2756630Z Feeds used:
2020-03-26T09:12:32.2756825Z https://api.nuget.org/v3/index.json
2020-03-26T09:12:32.2756980Z
2020-03-26T09:12:32.2757113Z Installed:
2020-03-26T09:12:32.2757302Z 1 package(s) to packages.config projects
2020-03-26T09:12:32.2757610Z 13 package(s) to d:\a\1\s\XamarinFormsTryStandard\XamarinFormsTry.csproj
2020-03-26T09:12:32.2758035Z 169 package(s) to d:\a\1\s\XamarinFormsTry\XamarinFormsTry.Android\XamarinFormsTry.Android.csproj
2020-03-26T09:12:32.2773237Z ##[section]Finishing: NuGetCommand
2020-03-26T09:12:32.2807591Z ##[section]Starting: XamarinAndroid
2020-03-26T09:12:32.2947509Z ==============================================================================
2020-03-26T09:12:32.2947864Z Task : Xamarin.Android
2020-03-26T09:12:32.2948151Z Description : Build an Android app with Xamarin
2020-03-26T09:12:32.2948500Z Version : 1.166.0
2020-03-26T09:12:32.2948736Z Author : Microsoft Corporation
2020-03-26T09:12:32.2949074Z Help : https://learn.microsoft.com/azure/devops/pipelines/tasks/build/xamarin-android
2020-03-26T09:12:32.2949464Z ==============================================================================
2020-03-26T09:12:34.4220559Z ##[command]"D:\a\_tasks\XamarinAndroid_27edd013-36fd-43aa-96a3-7d73e1e35285\1.166.0\ps_modules\MSBuildHelpers\vswhere.exe" -version [15.0,16.0) -latest -format json
2020-03-26T09:12:34.4661105Z ##[command]"D:\a\_tasks\XamarinAndroid_27edd013-36fd-43aa-96a3-7d73e1e35285\1.166.0\ps_modules\MSBuildHelpers\vswhere.exe" -version [15.0,16.0) -products Microsoft.VisualStudio.Product.BuildTools -latest -format json
2020-03-26T09:12:34.5348014Z ##[command]"D:\a\_tasks\XamarinAndroid_27edd013-36fd-43aa-96a3-7d73e1e35285\1.166.0\ps_modules\MSBuildHelpers\vswhere.exe" -version [16.0,17.0) -latest -format json
2020-03-26T09:12:34.7801263Z ##[warning]Unable to find MSBuild version '15.0' for architecture 'x86'. Falling back to version '16.0'.
2020-03-26T09:12:34.8662182Z ##[command]"C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\MSBuild\Current\Bin\msbuild.exe" "d:\a\1\s\MigrationBackup\b36c964d\XamarinFormsTry.Android\XamarinFormsTry.Android.csproj" /nologo /nr:false /dl:CentralLogger,"D:\a\_tasks\XamarinAndroid_27edd013-36fd-43aa-96a3-7d73e1e35285\1.166.0\ps_modules\MSBuildHelpers\Microsoft.TeamFoundation.DistributedTask.MSBuild.Logger.dll";"RootDetailId=b1e39c46-8802-47e2-b5ab-4bec5fda9203|SolutionDir=d:\a\1\s\MigrationBackup\b36c964d\XamarinFormsTry.Android"*ForwardingLogger,"D:\a\_tasks\XamarinAndroid_27edd013-36fd-43aa-96a3-7d73e1e35285\1.166.0\ps_modules\MSBuildHelpers\Microsoft.TeamFoundation.DistributedTask.MSBuild.Logger.dll" /p:configuration="Release" /p:_MSDeployUserAgent="VSTS_efe7950b-580b-467b-8a98-19b6043eee2e_build_1_0" /t:PackageForAndroid /p:OutputPath="d:\a\1\b/Release"
2020-03-26T09:12:34.9957257Z Build started 3/26/2020 9:12:34 AM.
2020-03-26T09:12:35.2054286Z Project "d:\a\1\s\MigrationBackup\b36c964d\XamarinFormsTry.Android\XamarinFormsTry.Android.csproj" on node 1 (PackageForAndroid target(s)).
2020-03-26T09:12:35.2062946Z _CleanIntermediateIfNuGetsChange:
2020-03-26T09:12:35.2066241Z Creating directory "obj\Release\90\stamp\".
2020-03-26T09:12:35.2070062Z Creating "obj\Release\90\stamp\_CleanIntermediateIfNuGetsChange.stamp" because "AlwaysCreate" was specified.
2020-03-26T09:12:35.8847743Z _ResolveSdks:
2020-03-26T09:12:35.8850229Z Found Java SDK version 1.8.0.
2020-03-26T09:12:36.3595388Z Found Java SDK version 1.8.0.
2020-03-26T09:12:36.8133556Z ##[error]C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\MSBuild\Xamarin\Android\Xamarin.Android.Common.targets(752,2): Error : AndroidManifest file does not exist
2020-03-26T09:12:36.8136850Z C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\MSBuild\Xamarin\Android\Xamarin.Android.Common.targets(752,2): error : AndroidManifest file does not exist [d:\a\1\s\MigrationBackup\b36c964d\XamarinFormsTry.Android\XamarinFormsTry.Android.csproj]
2020-03-26T09:12:36.8167951Z Done Building Project "d:\a\1\s\MigrationBackup\b36c964d\XamarinFormsTry.Android\XamarinFormsTry.Android.csproj" (PackageForAndroid target(s)) -- FAILED.
2020-03-26T09:12:36.8205677Z
2020-03-26T09:12:36.8208249Z Build FAILED.
2020-03-26T09:12:36.8258005Z
2020-03-26T09:12:36.8270145Z "d:\a\1\s\MigrationBackup\b36c964d\XamarinFormsTry.Android\XamarinFormsTry.Android.csproj" (PackageForAndroid target) (1) ->
2020-03-26T09:12:36.8274063Z (_ValidateAndroidPackageProperties target) ->
2020-03-26T09:12:36.8277799Z C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\MSBuild\Xamarin\Android\Xamarin.Android.Common.targets(752,2): error : AndroidManifest file does not exist [d:\a\1\s\MigrationBackup\b36c964d\XamarinFormsTry.Android\XamarinFormsTry.Android.csproj]
2020-03-26T09:12:36.8279308Z
2020-03-26T09:12:36.8281145Z 0 Warning(s)
2020-03-26T09:12:36.8284488Z 1 Error(s)
2020-03-26T09:12:36.8286684Z
2020-03-26T09:12:36.8290589Z Time Elapsed 00:00:01.83
2020-03-26T09:12:36.9547149Z ##[error]Process 'msbuild.exe' exited with code '1'.
2020-03-26T09:12:37.1765717Z ##[section]Finishing: XamarinAndroid
2020-03-26T09:12:44.6607030Z ##[section]Starting: Checkout XamarinFormsTry#master to s
C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\MSBuild\Xamarin\Android\Xamarin.Android.Common.targets(752,2): Error : AndroidManifest file does not exist
Process 'msbuild.exe' exited with code '1'.
I know that my project builds just fine as I can build it on my mac and pc using Visual studio for mac and Visual Studio 2019
and
I am also using https://appcenter.ms (Microsoft AppCenter) for analytics and that too provides a build on commit option. Even that builds just fine using a similar build agent process.
I have tried making a copy of AndroidManifest.xml and placing it in the root but that does not work either.
here is the configuration block from the .proj file for the Xamarin.Android project
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProductVersion>8.0.30703</ProductVersion>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>{C6CD5F2A-47C8-4A53-9729-91C88CEEB870}</ProjectGuid>
<ProjectTypeGuids>{EFBA0AD7-5A72-4C68-AF49-83D382785DCF};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>XamarinFormsTry.Droid</RootNamespace>
<AssemblyName>XamarinFormsTry.Android</AssemblyName>
<FileAlignment>512</FileAlignment>
<AndroidApplication>true</AndroidApplication>
<AndroidResgenFile>Resources\Resource.Designer.cs</AndroidResgenFile>
<GenerateSerializationAssemblies>Off</GenerateSerializationAssemblies>
<AndroidManifest>Properties\AndroidManifest.xml</AndroidManifest>
<TargetFrameworkVersion>v10.0</TargetFrameworkVersion>
<AndroidStoreUncompressedFileExtensions />
<MandroidI18n />
<JavaMaximumHeapSize />
<JavaOptions />
<NuGetPackageImportStamp>
</NuGetPackageImportStamp>
<AndroidKeyStore>false</AndroidKeyStore>
<AndroidSigningKeyStore>*******</AndroidSigningKeyStore>
<AndroidSigningStorePass />
<AndroidLinkMode>None</AndroidLinkMode>
<AndroidEnableMultiDex>true</AndroidEnableMultiDex>
</PropertyGroup>
It probably is something silly on my end, but I am unable to find help on google or figure it out myself.
So for anyone who has a xamarin.forms .net standard way kind of project and is running into a similar error here is what fixed it for me.
the original pipline
# Xamarin.Android
# Build a Xamarin.Android project.
# Add steps that test, sign, and distribute an app, save build artifacts, and more:
# https://learn.microsoft.com/azure/devops/pipelines/languages/xamarin
trigger:
- master
pool:
vmImage: 'windows-latest'
demands:
- MSBuild
- Xamarin.Android
- JDK
variables:
buildConfiguration: 'Release'
outputDirectory: '$(build.binariesDirectory)/$(buildConfiguration)'
steps:
- task: NuGetToolInstaller#1
- task: NuGetCommand#2
inputs:
restoreSolution: '**/*.sln'
- task: XamarinAndroid#1
inputs:
projectFile: '**/*droid*.csproj'
outputDirectory: '$(outputDirectory)'
configuration: '$(buildConfiguration)'
the fixed pipeline (yes the error was in the pipeline)
# Xamarin.Android
# Build a Xamarin.Android project.
# Add steps that test, sign, and distribute an app, save build artifacts, and more:
# https://learn.microsoft.com/azure/devops/pipelines/languages/xamarin
trigger:
- master
pool:
vmImage: 'windows-latest'
demands:
- MSBuild
- Xamarin.Android
- JDK
variables:
buildConfiguration: 'Release'
outputDirectory: '$(build.binariesDirectory)/$(buildConfiguration)'
steps:
- task: NuGetToolInstaller#1
- task: NuGetCommand#2
inputs:
restoreSolution: '**/*.sln'
- task: XamarinAndroid#1
inputs:
projectFile: 'XamarinFormsTry/XamarinFormsTry.Android/XamarinFormsTry.Android.csproj'
outputDirectory: '$(outputDirectory)'
configuration: '$(buildConfiguration)'
So its not that it didn't find the AndroidManifest file
it didnt find the right proj file.
changing the projectFile: '**/*droid*.csproj' to projectFile: 'XamarinFormsTry/XamarinFormsTry.Android/XamarinFormsTry.Android.csproj'
works. The right proj file is found and the proj builds successfully.
the error and the logs are a bit misleading in this case I guess
Had the same error for .NET MAUI and I figured out that the project ID was wrong in .csproj
I'm trying to create a basic build pipeline in Azure DevOps which builds a Visual Studio solution that includes .NET Core / .NET Standard projects and a Xamarin.Android project. The solution builds locally in VS 2019 with no issues, but always fails on the build agent with these build errors:
Error APT2260: resource style/Theme.AppCompat.Light.Dialog (aka com.companyname.obrien.connect.forms:style/Theme.AppCompat.Light.Dialog) not found.
Source\Obrien.Connect.Forms.Android\Resources\values\styles.xml(4,0): Error APT2260: style attribute 'attr/colorAccent (aka com.companyname.obrien.connect.forms:attr/colorAccent)' not found.
Error APT2260: resource style/Theme.AppCompat.Light.DarkActionBar (aka com.companyname.obrien.connect.forms:style/Theme.AppCompat.Light.DarkActionBar) not found.
Source\Obrien.Connect.Forms.Android\Resources\values\styles.xml(2,0): Error APT2260: style attribute 'attr/windowNoTitle (aka com.companyname.obrien.connect.forms:attr/windowNoTitle)' not found.
Source\Obrien.Connect.Forms.Android\Resources\values\styles.xml(2,0): Error APT2260: style attribute 'attr/windowActionBar (aka com.companyname.obrien.connect.forms:attr/windowActionBar)' not found.
Source\Obrien.Connect.Forms.Android\Resources\values\styles.xml(2,0): Error APT2260: style attribute 'attr/colorPrimary (aka com.companyname.obrien.connect.forms:attr/colorPrimary)' not found.
Source\Obrien.Connect.Forms.Android\Resources\values\styles.xml(2,0): Error APT2260: style attribute 'attr/colorPrimaryDark (aka com.companyname.obrien.connect.forms:attr/colorPrimaryDark)' not found.
Source\Obrien.Connect.Forms.Android\Resources\values\styles.xml(3,0): Error APT2260: style attribute 'attr/colorAccent (aka com.companyname.obrien.connect.forms:attr/colorAccent)' not found.
Source\Obrien.Connect.Forms.Android\Resources\values\styles.xml(4,0): Error APT2260: style attribute 'attr/windowActionModeOverlay (aka com.companyname.obrien.connect.forms:attr/windowActionModeOverlay)' not found.
C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\MSBuild\Xamarin\Android\Xamarin.Android.Aapt2.targets(155,3): Error APT2260: resource style/TextAppearance.AppCompat.Button (aka com.companyname.obrien.connect.forms:style/TextAppearance.AppCompat.Button) not foun
This is the YAML for the pipeline:
trigger:
- develop
- feature/*
pool:
vmImage: 'windows-2019'
variables:
- group: 'ci-build'
steps:
- task: NuGetToolInstaller#1
displayName: 'Install NuGet 5.4.0'
inputs:
versionSpec: '5.4.0'
- task: DotNetCoreCLI#2
displayName: 'Restore .NET Packages'
inputs:
command: restore
projects: '**/OBrien.Connect.Forms*/*.csproj'
verbosityRestore: minimal
- task: NuGetCommand#2
displayName: 'Restore Android Packages'
inputs:
command: 'restore'
restoreSolution: '**/OBrien.Connect.Forms.sln'
- task: VSBuild#1
displayName: 'Build Solution'
inputs:
solution: '**/$(solutionName)'
vsVersion: '16.0'
configuration: '$(buildConfiguration)'
I needed to use dotnet restore on the projects in the solution first, so that I could build them in the subsequent VSBuild task, that works fine. However, this doesn't restore any packages needed by the Xamarin.Android project as that is based on Mono and is ignored by the first restore.
That's why I added the second NuGet restore on the entire solution, but this never does anything - no errors, just this output:
##[section]Starting: Restore Android Packages
==============================================================================
Task : NuGet
Description : Restore, pack, or push NuGet packages, or run a NuGet command. Supports NuGet.org and authenticated feeds like Azure Artifacts and MyGet. Uses NuGet.exe and works with .NET Framework apps. For .NET Core and .NET Standard apps, use the .NET Core task.
Version : 2.161.1
Author : Microsoft Corporation
Help : https://learn.microsoft.com/azure/devops/pipelines/tasks/package/nuget
==============================================================================
SYSTEMVSSCONNECTION exists true
SYSTEMVSSCONNECTION exists true
[command]C:\windows\system32\chcp.com 65001
Active code page: 65001
Detected NuGet version 5.4.0.6315 / 5.4.0+d790b66be476cd901a56bd46ada037162097ee21.d790b66be476cd901a56bd46ada037162097ee21
SYSTEMVSSCONNECTION exists true
Saving NuGet.config to a temporary config file.
[command]C:\hostedtoolcache\windows\NuGet\5.4.0\x64\nuget.exe sources Add -NonInteractive -Name NuGetOrg -Source https://api.nuget.org/v3/index.json -ConfigFile D:\a\1\Nuget\tempNuGet_552.config
Package source with Name: NuGetOrg added successfully.
##[section]Finishing: Restore Android Packages
I've tried using the XamarinAndroid#1 build task instead of building the whole solution, but it has exactly the same build errors.
I found a good solution from a colleague who had exactly the same problem, which is to trigger the Restore target from the VSBuild task, instead of doing a NuGet restore / dotnet restore, here's the YAML:
- task: VSBuild#1
displayName: 'Restore Packages'
inputs:
solution: '**/$(solutionName)'
configuration: '$(buildConfiguration)'
vsVersion: '16.0'
msbuildArgs: '/t:Restore'
This works perfectly for building the entire solution.
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.
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.
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)
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.
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.
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.
I have a project that pulls from both public and private NuGet repositories. This works. But what doesn't seem to work is that the build on CI fails because of Microsoft.Bcl.Build, which should have gotten downloaded from the Nuget Restore Step
trigger:
- master
pool:
vmImage: 'windows-2019'
demands:
- msbuild
- visualstudio
- VSTest
- DotNetFramework
variables:
solution: '**/*.sln'
buildPlatform: 'Any CPU'
buildConfiguration: 'Release'
steps:
- task: NuGetToolInstaller#0
displayName: 'Use NuGet 4.4.1'
inputs:
versionSpec: 4.4.1
- task: NuGetCommand#2
displayName: 'NuGet restore'
inputs:
restoreSolution: '$(Parameters.solution)'
feedsToUse: config
nugetConfigPath: .nuget/NuGet.Config
- task: VSBuild#1
displayName: 'Run Build on solution.'
inputs:
solution: '$(solution)'
msbuildArgs: '/p:DeployOnBuild=true /p:WebPublishMethod=Package /p:PackageAsSingleFile=true /p:SkipInvalidConfigurations=true /p:PackageLocation="$(build.artifactStagingDirectory)" /p:BclBuildImported=Ignore'
platform: '$(buildPlatform)'
configuration: '$(buildConfiguration)'
logFileVerbosity: 'diagnostic'
In the sample above, I have tried both using and removing /p:BclBuildImported=Ignore'.
The library I am using has BCL ref in it, so I cannot remove that dependancy. And this code falls apart when I switch it to core.
Everything does work when I build it in Visual Studio 2019 Ent, and Pro, just refuses to build on MS DevOps, on the Hosted 2017 platform.
Tried fixes, and comment/discussion follow-up since initial post:
Multiple pools have been tried, all failing.
This does build in VS 2017 & 2019 on pro and enterprise on various desktops.
The error is This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is ..\packages\Microsoft.Bcl.Build.1.0.21\build\Microsoft.Bcl.Build.targets. even though all packages are being installed, and the Nuget download shows no errors or skips.
The following fixes have not worked:
How to bypass Microsoft.Bcl.Build warning
What does the Microsoft.Bcl.Build NuGet package do?
Have you tried MS DevOps, on the Hosted 2019 platform, instead of using a 2017 Host?
Hosted Windows 2019 with VS2019
I ended up removing all BCL dependencies and built a lot of workarounds. This was no minor change. Unfortunately, as this is 2 years ago, I don't have the details of what I did back then.