| uid | Uno.GetStarted.vscode |
|---|
This guide will walk you through the set-up process for building WebAssembly and Gtk+ apps with Uno under Windows, Linux, or macOS.
See these sections for information about using Uno Platform with:
- Visual Studio Code
- .NET SDK
- .NET 7.0 SDK (version 7.0 (SDK 7.0.102) or later)
Use
dotnet --versionfrom the terminal to get the version installed. - The Uno Platform Visual Studio Code Extension
- For Windows, install the GTK+ 3 runtime (See this uno-check issue)
[!includegetting-help]
In the terminal, type the following to create a new project:
dotnet new unoapp -o MyApp -mobile=false --skia-wpf=false --skia-linux-fb=false --vscode
MyAppis the name you want to give to your project.
This will create a solution that only contains the WebAssembly and Skia+GTK platforms support.
-
Open the project using Visual Studio Code. In the terminal type
code ./MyApp
For this command to work you need to previously have configured Visual Studio Code to be launched from the terminal.
-
Visual Studio Code will ask to restore the NuGet packages.
-
Once the project has been loaded, in the status bar at the bottom left of VS Code,
MyApp.slnis selected by default. SelectMyApp.Wasm.csprojorMyApp.Skia.Gtk.csprojinstead.
-
In
MainPage.xaml, replace the Grid's content with the following:<StackPanel> <TextBlock x:Name="txt" Text="Hello, world!" Margin="20" FontSize="30" /> <Button Content="click" Click="{x:Bind OnClick}" /> </StackPanel>
-
In your
MainPage.xaml.cs, add the following method:private void OnClick() { var dt = DateTime.Now.ToString(); txt.Text = dt; }
- In the debugger section of the Code activity bar, select
Debug (Chrome, WebAssembly) - Press
F5to start the debugging session - Place a breakpoint inside the
OnClickmethod - Click the button in the app, and the breakpoint will hit
- In the debugger section of the Code activity bar, select
Skia.GTK (Debug) - Press
F5to start the debugging session - Place a breakpoint inside the
OnClickmethod - Click the button in the app, and the breakpoint will hit
Note that C# Hot Reload is not available when running with the debugger. In order to use C# Hot Reload, run the app using the following:
- On Windows, type the following:
$env:DOTNET_MODIFIABLE_ASSEMBLIES="debug" dotnet run - On Linux or macOS:
export DOTNET_MODIFIABLE_ASSEMBLIES=debug dotnet run
- In the MyApp folder, create a new file named
Page2.xaml - Type
pagethen press thetabkey to add the page markup - Adjust the name and namespaces as needed
- In the MyApp folder, create a new file named
Page2.xaml.cs - Type
pagethen press thetabkey to add the page code behind C# - Adjust the name and namespaces as needed
- In the MyApp folder, create a new file named
UserControl1.xaml - Type
usercontrolthen press thetabkey to add the page markup - Adjust the name and namespaces as needed
- In the MyApp folder, create a new file named
UserControl1.xaml.cs - Type
usercontrolthen press thetabkey to add the page code behind C# - Adjust the name and namespaces as needed
- In the MyApp folder, create a new file named
ResourceDictionary1.xaml - Type
resourcedictthen press thetabkey to add the page markup
rdcreates a newRowDefinitioncdcreates a newColumnDefinitiontagcreates a new XAML tagsetcreates a newStylesetterctagcreates a newTextBlockclose XAML tag
An existing application needs additional changes to be debugged properly.
- At the root of the workspace, create a folder named
.vscode - Inside this folder, create a file named
launch.jsonand copy the contents of this file. - Replace all instances of
UnoQuickStartwith your application's name inlaunch.json. - Inside this folder, create a file named
tasks.jsonand copy the contents of this file.
- C# Debugging is not supported when running in a remote Linux Container, Code Spaces or GitPod.
- C# Hot Reload for WebAssembly only supports modifying method bodies. Any other modification is rejected by the compiler.
- C# Hot Reload for Skia supports modifying method bodies, adding properties, adding methods, adding classes. A more accurate list is provided here in Microsoft's documentation.
If you're not sure whether your environment is correctly configured for Uno Platform development, running the uno-check command-line tool should be your first step.
The Uno Platform extension provides multiple output windows to troubleshoot its activities:
- Uno Platform, which indicates general messages about the extension
- Uno Platform - Hot Reload, which provides activity messages about the Hot Reload feature
- Uno Platform - XAML, which provides activity messages about the XAML Code Completion feature
If the extension is not behaving properly, try using the Developer: Reload Window (or Ctrl+R) command in the palette.
[!includegetting-help]