Debugging Uno.UI samples
To debug the SamplesApp in the Uno.UI solution, which includes an extensive set of samples and test cases for the controls supported by Uno.UI, as well as non-UI features:
- Clone the repo, and ensure using a short target path, e.g. D:\uno etc.
This is due to limitations in the legacy .NET versions used by Xamarin projects. This issue has been addressed in .NET 5, and will come to the rest of the projects in the future.
- Open the solution filter in Visual Studio for the target platform you wish to run on, as detailed here.
SamplesApp.[TargetPlatform]as the selected Startup Project.
- Launch the samples app from Visual Studio.
See this article for more information on working with the SamplesApp and authoring new samples.
Debugging Uno in another application
It's also easy to debug Uno.UI code in an application outside the Uno.UI solution. The Uno.UI build process has an opt-in mechanism to overwrite the contents of the NuGet cache, causing the application to use your local build of Uno.
This is useful if you're debugging a problem that can't easily be reproduced outside the context of the app where it was discovered.
It can even speed up your development loop when working on a new feature or fixing a bug with a standalone repro, because a small 'Hello World' app builds considerably faster than the full SamplesApp.
First, you'll need to install, in the app you want to debug with, a published Uno package version which is close to your branch's code, preferably a
-dev.xxx version. Make sure update all
Uno.UI.* packages to the same version.
Then, here are the steps to use a local build of Uno.UI in another application:
- Configure Uno.UI to build for the target platform you wish to debug, as detailed here.
- By default the Uno.UI solution on the master branch is building using the UWP API set. If you want to build against the WinUI 3 API set, you can checkout the
generated/master/winui-autoconvertbranch. See this section for details on this branch.
- Close any instances of Visual Studio with the Uno.UI solution opened.
- Open the solution containing the application you wish to debug to ensure the package is restored & cached.
- Note the NuGet version of Uno.UI (or Uno.UI.WebAssembly/Uno.UI.Skia) being used by the application (eg
- Make a copy of
src/crosstargeting_override.props.sampleand name it as
src/crosstargeting_override.props, uncomment the line
- Replace the version number with the version being used by the application you wish to debug.
- Open the appropriate Uno.UI solution filter and build the Uno.UI project (or Uno.UI.WebAssembly/Uno.UI.Skia projects for WebAssembly or Skia).
To debug Uno.UI code in the application, follow these steps (using
FrameworkElement.MeasureOverride() as an example):
FrameworkElement.csin the Uno.UI solution.
- Right-click on the
FrameworkElement.cstab header in Visual Studio and choose 'Copy Full Path'.
- Switch to the Visual Studio instance where your application is open.
- In your application solution, choose File->Open->File... or simply
Ctrl+O, paste the path to
FrameworkElement.csinto the file open dialog, and open
FrameworkElement.csin the application solution.
- Put a breakpoint in the
- Launch the application.
- You should hit the breakpoint, opening the
FrameworkElement.csfile, and be able to see local variable values, etc.
- To revert to the original Uno.UI version from NuGet, simply navigate to the NuGet cache folder (
%USERPROFILE%\.nuget\packages) and delete the
Uno.UIfolder within it. You may need to close Visual Studio first. The original version will be automatically restored the next time the application builds.
Tips about the NuGet version override process
Be aware that setting
UnoNugetOverrideVersionwill overwrite your local NuGet cache for the nominated Uno.UI version. Any applications that you build locally will use your local build if they depend on that Uno.UI version.
Uno.UI.Skiaare the only projects overriding the nuget cache. If you make modifications to Uno.UWP, building the Uno.UI project is still needed.
Building for Android requires the API level to match the version you specified in
UnoTargetFrameworkOverride. A common issues is that the app being debugged uses Android10.0 and
Uno.UIis built using Android11.0. You can change the API level in the debugged project's build properties.
The nuget override process only works on already installed versions. The best way to ensure that the override is successful is to build the debugged application once before overriding the Uno.UI version the app uses.
Make sure to close the application that uses the overridden nuget package, to avoid locked files issues on Windows.
It may happen that the package cache for the version you're debugging is corrupted, and the override is not working as intended.
If this is the case:
- In your debugged app, select another package version you've never debugged with
- Make sure to build the app once to populate the nuget cache
- Rebuild the Uno.UI project (or Uno.UI.WebAssembly/Uno.UI.Skia) to replace the binaries with your debug ones
- Rebuild your app and debug your again
- Make sure that you're debugging the right flavor of Uno (Uno.UI vs. Uno.WinUI). You can debug the WinUI flavor using this conversion tool.
Microsoft Source Link support
Uno.UI supports SourceLink and it now possible to step into Uno.UI without downloading the repository.
Make sure Enable source link support check box is checked in Tools / Options / Debugging / General properties page.