Xamarim msbuild to use a specific Java version - xamarin

We are trying to use a specific Java version on a TFS build pipeline. The build is being done using msbuild. The build server have two Java versions installed (i.e. 8 and 11). The PATH variable point to java 8, but in the msbuild we want to use Java 11 for the Android part.
It is asked to not change the PATH variable because other applications require Java 8, so wanted to know if there is any provision to pass the JDKPath directly to the msbuild using any command-line parameters.

When you use Xamarin msbuild to build Android project, you can define the JDK version in the Xamarin task.
Here is an example:
- task: XamarinAndroid#1
displayName: 'Build Xamarin.Android project project path'
inputs:
projectFile: 'project path'
target: test
jdkVersionOption: 1.11
Or you can also define the jdk path in the Xamarin task.
- task: XamarinAndroid#1
displayName: 'Build Xamarin.Android project project path'
inputs:
projectFile: 'project path'
target: test
jdkOption: Path
jdkDirectory: 'JDK path'
For more detailed info, you can refer to this doc: Xamarin.Android task

Related

Azure Pipelines VisualStudioBuild task ignoring AssemblyInfo.cs

This is being built in an on-prem build agent running version 2.200.2. I've tried using VS 2017-2022 (15.0, 16.0, 17.0).
When I build my code locally, it properly parses the AssemblyInfo.cs files and applies the versioning so that when I check the details in Windows properties, it lists the version set in AssemblyFileVersion (I'm also setting AssemblyVersion and AssemblyInformationalVersion for good measure). For some reason, however, when I run the following tasks, all generated dlls and exes come out with a version of 0.0.0.0 instead of what is listed in the AssemblyInfo.cs. $(RVersion) is defaulted to 1.0.23.0 and I've validated that the AssemblyInfo.cs files are properly being updated. The value currently listed in the AssemblyInfo is 1.0.13.0, so even if it wasn't being set, it's still being ignored. Any help in figuring out why the files are being generated with 0.0.0.0 would be appreciated.
- task: Assembly-Info-NetFramework#3
inputs:
Path: '$(Build.SourcesDirectory)'
FileNames: |
**\AssemblyInfo.cs
InsertAttributes: true
VersionNumber: '$(RVersion)'
FileVersionNumber: '$(RVersion)'
InformationalVersion: '$(RVersion)'
Configuration: $(buildConfiguration)
- task: VSBuild#1 displayName: 'Build .NET Solution'
inputs:
solution: '$(solution)'
vsVersion: '17.0'
configuration: 'Release'
platform: $(buildPlatform)
msbuildArgs: '/p:SkipInvalidConfigurations=true /p:OutDir=$(Build.BinariesDirectory)'
clean: true

Azure Devops - SSDT DB build error - writing model.xml

I get the following build error for my SSDT project in Azure DevOps:
System.IO.DirectoryNotFoundException: Could not find a part of the path 'd:\a\1\s\SSDTPROJECTNAME\SSDTPROJECTNAMEobj\Release\Model.xml'.
Earlier in the build it attempts to write the Model.xml file to an invalid path:
SqlBuild:
Creating a model to represent the project...
Loading project references...
Loading project files...
Building the project model and resolving object interdependencies...
Validating the project model...
Writing model to SSDTPROJECTNAMEobj\Release\Model.xml...
For some reason it fails to concatenate my project folder name with obj\Release\Model.xml. But when I build locally it writes the model.xml to a valid location. For the project folder I'm using a variable called $(projectDir) set to my project folder name.
I'm using VSBuild#1 with the windows-latest vmImage.
Here's my task:
- task: VSBuild#1
displayName: "Build DB project"
inputs:
solution: "$(projectDir)\SSDTPROJECTNAME.sqlproj"
msbuildArgs: '/p:DeployOnBuild=true /p:WebPublishMethod=Package /p:PackageAsSingleFile=true /p:DeleteExistingFiles=True /p:PackageLocation="$(Build.ArtifactStagingDirectory)\\"'
configuration: "$(BuildConfiguration)"
clean: true
The 'projectDir' variable is preserved key word for VS Build. If you change to a different variable should fix the problem.
https://learn.microsoft.com/en-us/cpp/build/reference/common-macros-for-build-commands-and-properties?view=vs-2019

Can't build Xamarin Android project in Azure Pipelines

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.

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

Azure Devops Pipelines - connect "VS Build" step to "Archive Files" step

I'm trying to get into using Azure Devops Pipelines, and my first pet project is a simple .NET command line app I'm trying to get to be built.
I picked the "VS Build .NET Desktop" task template, and the build per se works fine - the bits are compiled without trouble
YAML:
- task: VSBuild#1
inputs:
solution: '$(solution)'
platform: '$(buildPlatform)'
configuration: '$(buildConfiguration)'
Log:
##[section]Starting: VSBuild
==============================================================================
Task : Visual Studio build
Description : Build with MSBuild and set the Visual Studio version property
Version : 1.151.2
Author : Microsoft Corporation
Help : https://learn.microsoft.com/azure/devops/pipelines/tasks/build/visual-studio-build
==============================================================================
##[command]"C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\MSBuild\Current\Bin\msbuild.exe" "d:\a\1\s\AzureDevopsTaskCreator.sln"
...(lots of lines omitted)
CopyFilesToOutputDirectory:
Copying file from "d:\a\1\s\obj\Release\AZTaskCreator.exe" to "d:\a\1\s\bin\Release\AZTaskCreator.exe".
AZTaskCreator -> d:\a\1\s\bin\Release\AZTaskCreator.exe
Copying file from "d:\a\1\s\obj\Release\AZTaskCreator.pdb" to "d:\a\1\s\bin\Release\AZTaskCreator.pdb".
But now I wanted to somehow publish the output from this build so I could download it (or deploy it somewhere). But I've been struggling with getting these things hooked up.
So I tried to first zip the build output into an archive (which could then be published):
YAML
- task: ArchiveFiles#2
inputs:
rootFolderOrFile: '$(Build.BinariesDirectory)'
includeRootFolder: true
archiveType: 'zip'
archiveFile: '$(Build.ArtifactStagingDirectory)/AZCreateTasks$(Build.BuildId).zip'
replaceExistingArchive: true
verbose: true
Log:
##[section]Starting: ArchiveFiles
##[command]d:\a\_tasks\ArchiveFiles_d8b84976-e99a-4b86-b885-4849694435b0\2.151.2\7zip\7z.exe a -tzip -bb3 d:\a\1\a\AZCreateTasks8.zip #d:\a\_temp\yat6561e8redmiomp7bbuik9
My problem is: HOW can I tell the "Archive Files" step to use the output directory of the previous build? I was assuming that the default $(Build.BinariesDirectory) would do that - but obviously, it doesn't:
Output from VS Build goes to the d:\a\1\s\bin\Release\ directory
Archive files step zips up files in d:\a\_temp\yat6561e8redmiomp7bbuik9 directory
How can I "connect" these two steps so that the "Archive Files" step actually respects and uses the output directory of the VS Build step??
I'm having a terribly hard time finding any useful documentation on what kind of "system pre-defined" magic variables are in play here, and how to influence these .....
According to the log, the build output is in d:\a\1\s\... the s folder it the sources directory, to access this folder there is pre-defined varaible: Build.SourcesDirectory.
So instead of using $(Build.BinariesDirectory) use the above variable:
rootFolderOrFile: '$(Build.SourcesDirectory)'
But now you will get a zip with the sources files including the dll's, so consider to append the path until the folder/s you want.
For example:
rootFolderOrFile: '$(Build.SourcesDirectory)/obj/Release'

Resources