TACOBOT

The Official Blog for Visual Studio
Tools for Apache Cordova

By our developers, for developers.

Using Msbuild with VS Cordova Projects

Microsoft Visual Studio Tools for Apache Cordova Update 5 adds the ability to easily build from command-line using msbuild. Building from command-line is useful for automating builds, creating a CI build, or for those who prefer CLI commands over an IDE.

Building the .sln file using msbuild will use the last build configuration from Visual Studio. In order to build different configurations and platforms using msbuild a few command-line parameters need to be used. Here is an overview of the parameters to use.

Every build requires that a platform be specified. For example:

msbuild /p:Platform="Windows-x64"

The allowed values are:

  • Android
  • iOS
  • Windows Phone (Universal)
  • Windows Phone 8
  • Windows-AnyCPU
  • Windows-ARM
  • Windows-x64
  • Windows-x86

Just like other msbuild commands, the configuration can be set to Debug or Release by specifying it as a parameter:

msbuild /p:Platform="Windows Phone (Universal)" /p:Configuration=Debug

Here is a quick overview of building for each platform:

Android

The type of build will change based on the target of the build. Targeting “Device” or “AndroidEmulator” will do a normal Android build:

msbuild /p:Platform="Android" /p:DebuggerFlavor="Device"

Running a build with the target using “RippleNexus7” will run the build that Visual Studio uses in order to launch the app using Ripple:

msbuild /p:Platform="Android" /p:DebuggerFlavor="RippleNexus7"

iOS

Building for iOS requires a remote build server to be configured. The following is an example of how to build for a device with secure mode turned off:

msbuild /p:Platform="iOS" /p:DebuggerFlavor=iOSRemoteDevice /p:iOSRemoteBuildServer="http://<machine name>:<port>/cordova"

The build can also target emulators by specifying a DebuggerFlavor of “iOSEmulatoriPhone6”.

To use remotebuild in secure mode, iOSCertificateName must also be specified. The certificate name will usually be the machine name of the remote build server followed by “.RB”, so “<machine name>.RB”. If secure build has been configured in Visual Studio, the certificate name can be looked up in the registry from this value:

HKEY_CURRENT_USER\SOFTWARE\Microsoft\VisualStudio\14.0\ApplicationPrivateSettings\Microsoft\VisualStudio\MultiDeviceHybridApps\Common\Options\MultiDeviceDevelopmentOptionsPage\CertificateName

Then pass the certificate name as an msbuild parameter:

msbuild /p:Platform="iOS" /p:DebuggerFlavor=iOSRemoteDevice /p:iOSRemoteBuildServer="http://<machine name>:<port>/cordova" /p:iOSCertificateName="<certificate name>"

If the certificate was configured using taco-cli, the certificate name can be found in:

%appdata%/taco_home/TacoSettings.json

Windows Phone (Universal)

Windows Phone (Universal) is for targeting Windows Phone 8.1 and Windows 10 Mobile apps. Cordova uses the same “windows” platform as apps that target Windows.

The main DebuggerFlavor options for Windows Phone (Universal) are:

  • WindowsMobileEmulator - builds for x86 so that it can be used in an emulator
  • PhoneDevice81 - builds for ARM so that it can be deployed to a device

msbuild /p:Platform="Windows Phone (Universal)" /p:DebuggerFlavor="PhoneDevice81"

Windows-AnyCPU, Windows-ARM, Windows-x64, Windows-x86

The Windows platforms of Windows-AnyCPU, Windows-ARM, Windows-x64, and Windows-x86 can be used to build Windows apps targeting Windows 8.1 or Windows 10. Use the different platforms to target different CPU architectures.

The DebuggerFlavor will not affect the build. The default value is “LocalMachine” and does not need to be changed.

msbuild /p:Platform="Windows-x86"

Windows Phone 8

Windows Phone 8 is for targeting only Windows Phone 8.0 Silverlight apps.

The DebuggerFlavor will not affect the build. The default value is “PhoneDevice” and does not need to be changed.

msbuild /p:Platform="Windows Phone 8"

Todd Moscinski
Senior Software Engineer @ Visual Studio
e: toddmosc@microsoft.com