Using NuGet to add functionality to your app
NuGet and packages
Developers share libraries and resources by bundling their work into packages. You can pull a package into Visual Studio to provide extra functionality to projects. For example, to add support for JSON or add animation routines to XAML.
NuGet is the package manager for .NET, UWP, Windows Forms, and WPF projects. Browse the package catalog with NuGet to install, update, or delete packages from your project. NuGet is built into Visual Studio, so you don't have to leave the IDE.
Install a NuGet package
Let's use NuGet to install new XAML animation features from the Win2D package:
Select Project, and then select Manage NuGet Packages.
Select Browse, type Win2D in the search box, and then press Enter. A list of available packages displays.
Select Win2D.uwp from the list and select the Install button. The package begins installing.
With the package installed, we can call a feature directly in the XAML code to define our main page.
Note
If you get an error during installation, you might not have set the correct minimum version.
Select Project, and then select Hello World Properties. Change the Min version to Windows 10, version 1809 or later.
A Preview Changes window displays. Select OK.
A License Acceptance window displays. To agree to the license terms, select I Accept.
Double-click MainPage.xaml in the Solution Explorer to open it in design view.
Use the Arrows button to expand the editing view.
Replace all of the XAML code in MainPage.xaml with this code:
<Page x:Class="Hello_World.MainPage" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Background="{ThemeResource ApplicationPageBackgroundThemeBrush}" xmlns:canvas="using:Microsoft.Graphics.Canvas.UI.Xaml"> <Grid> <canvas:CanvasControl Draw="CanvasControl_Draw" ClearColor="CornflowerBlue"/> </Grid> </Page>
Replace all of the C# code in MainPage.xaml.cs with this code:
using Windows.UI; using Windows.UI.Xaml.Controls; using Microsoft.Graphics.Canvas.UI.Xaml; namespace Hello_World { public sealed partial class MainPage : Page { public MainPage() { this.InitializeComponent(); } void CanvasControl_Draw(CanvasControl sender, CanvasDrawEventArgs args) { args.DrawingSession.DrawEllipse(155, 115, 80, 30, Colors.White, 3); args.DrawingSession.DrawText("Hello world!", 100, 100, Colors.White); } } }
This XAML code includes a reference to the package we installed earlier.
Run your program to see the results.
You should see an ellipse circling the text "Hello World!" on a blue background.
Need help? See our troubleshooting guide or provide specific feedback by reporting an issue.