title | description | author | ms.author | ms.date | ms.topic | ms.localizationpriority | keywords |
---|---|---|---|---|---|---|---|
Using Visual Studio to deploy and debug |
Learn how to build, debug, and deploy apps for HoloLens and Windows Mixed Reality using Visual Studio. |
vtieto |
vinnietieto |
08/17/2022 |
article |
high |
Visual Studio, HoloLens, Mixed Reality, debug, deploy, Unity |
Whether you're using DirectX or Unity to develop your mixed reality app, Visual Studio is your go-to tool for debugging and deployment. In this section, you'll learn how to:
- Deploy applications to your HoloLens or Windows Mixed Reality immersive headset through Visual Studio.
- Use the HoloLens emulator that's built into Visual Studio.
- Debug mixed reality apps.
- See Install the Tools for installation instructions.
- Create a new mixed reality project in Unity or Visual Studio.
- Build your Unity project per our instructions
Start by enabling Developer Mode on your device so Visual Studio can connect to it.
- Turn on your HoloLens and put on the device.
- Use the start gesture to launch the main menu.
- Select the Settings tile to launch the app in your environment.
- Select the Update menu item.
- Select the For developers menu item.
- Enable Use developer features to deploy apps from Visual Studio to your HoloLens. If your device is running Windows Holographic version 21H1 or newer, also enable Device discovery.
- Optional: Scroll down and also enable Device Portal, which lets you connect to the Windows Device Portal on your HoloLens from a web browser.
If you're working with a Windows Mixed Reality headset connected to your PC, you must enable Developer Mode on the PC.
- Go to Settings.
- Select Update and Security.
- Select For developers.
- Enable Developer Mode, read the disclaimer for the setting you chose, and then select Yes to accept the change.
-
Open your project in Visual Studio
-
Click the Compilation Options drop down and then do one of the following:
- For Unity projects, choose either Release or Master
- For all other projects, choose Release
Here are definitions for the compilation options:
Configuration | Explanation |
---|---|
Debug | All optimizations off and the profiler is enabled. Used to debug scripts. |
Master | All optimizations are turned on and the profiler is disabled. Used to submit apps to the Store. |
Release | All optimizations are turned on and the profiler is enabled. Used to evaluate app performance. |
-
Select your build configuration based on your device.
To learn more about the build configurations, see the "Types of build configurations" table in the Unity documentation.
[!NOTE] For deployment to the HoloLens 2 device, choose the ARM64 or the ARM architecture.
If you don't see Device as a target option, you may need to change the startup project for the Visual Studio solution from the IL2CPP project to the UWP project. To do this, in the Solution Explorer, right-click your project, and then select Set as StartUp Project.
-
Click the deployment target drop-down and then do one of the following:
- If you're building and deploying via Wi-Fi, select Remote Machine.
- If you're building and deploying via USB, select Device.
To set your remote connection:
-
On the menu bar, select Project > Properties > Configuration Properties > Debugging.
[!NOTE] For a C# project, a dialog should automatically appear.
-
Click the Debugger to launch drop down and then select Remote Machine.
-
In the Machine Name field, enter the IP address of your device.
-
You can find the IP address on your HoloLens under Settings > Network & Internet > Advanced Options.
-
We recommend that you manually enter your IP address rather than depend on the "Auto Detected" feature.
-
-
Set the Authentication Mode to Universal (Unencrypted protocol).
-
Build, deploy, and debug your app based on your needs:
-
To build, deploy and start debugging, select Debug > Start debugging.
-
To build and deploy without debugging, select Build > Deploy Solution.
-
-
The first time you deploy an app to your HoloLens from your PC, you'll be prompted for a PIN. Follow the Pairing your device instructions below.
Note
If the errors listed below occur when you start debugging an installed UWP application on the HoloLens 2, try renaming your package or uninstalling your UWP application.
"Unable to start debugging"
"Operation not supported. Unknown error: 0x80070057"
- Make sure you've installed the HoloLens Emulator.
- Select an x86 build configuration for your app.
- Select HoloLens Emulator in the deployment target drop-down menu
- Select Debug > Start debugging to deploy your app and start debugging
- Make sure you've installed the HoloLens Emulator.
- Select an x86 or x64 build configuration for your app.
- Select HoloLens 2 Emulator in the deployment target drop-down menu
- Select Debug > Start debugging to deploy your app and start debugging
To use a Windows Mixed Reality immersive headset that connects to your PC or the Mixed Reality simulator:
- Select an x86 or x64 build configuration for your app
- Select Local Machine in the deployment target drop-down menu
- Build, deploy, and debug your app based on your needs
- Select Debug > Start debugging to deploy your app and start debugging
- Select Build > Deploy to build and deploy without debugging
The first time you deploy an app from Visual Studio to your HoloLens, you'll be prompted for a PIN. On the HoloLens, generate a PIN by launching the Settings app, go to Update > For Developers, and tap on Pair. When the PIN is displayed on your HoloLens, type it into Visual Studio. After pairing is complete, tap Done on your HoloLens to dismiss the dialog. This PC is now paired with the HoloLens and you can deploy apps automatically. Repeat these steps for every PC that's used to deploy apps to your HoloLens.
To unpair your HoloLens from all paired computers:
- Launch the Settings app, go to Update > For Developers, and tap on Clear.
The Visual Studio Graphics Diagnostics tools are helpful when writing and optimizing a Holographic app. See Visual Studio Graphics Diagnostics on MSDN for full details.
To Start the Graphics Debugger
- Follow the instructions above to target a device or emulator
- Go to Debug > Graphics > Start Diagnostics
- The first time you start diagnostics with a HoloLens, you may get an "access denied" error. Reboot your HoloLens to let the updated permissions take effect and try again.
The Visual Studio profiling tools allow you to analyze your app's performance and resource use. This includes tools to optimize CPU, memory, graphics, and network use. See Run diagnostic tools without debugging on MSDN for full details.
To Start the Profiling Tools with HoloLens
- Follow the instructions above to target a device or emulator
- Go to Debug > Start Diagnostic Tools Without Debugging...
- Select the tools you want to use
- Select Start
- The first time you start diagnostics without debugging with a HoloLens, you may get an "access denied" error. Reboot your HoloLens to let the updated permissions take effect and try again.
You can use Visual Studio to debug an installed Universal Windows app without deploying from a Visual Studio project. This is useful if you want to debug an installed app package or debug an app that's already running.
- Go to Debug -> Other Debug Targets -> Debug Installed App Package
- Select the Remote Machine target for HoloLens or Local Machine for immersive headsets.
- Enter your device’s IP address
- Choose the Universal Authentication Mode
- The window shows both running and inactive apps. Pick the one what you’d like to debug.
- Choose the type of code to debug (Managed, Native, Mixed)
- Select Attach or Start
If you're following the Unity development checkpoint journey we've laid out, you're in the midst of the deployment stage. From here, you can continue to the next topic:
[!div class="nextstepaction"] Deploying to HoloLens emulator
Or jump directly to adding advanced services:
[!div class="nextstepaction"] Advanced services
You can always go back to the Unity development checkpoints at any time.