Xbox Live

This page explains how to configure your project to work with Xbox Live.

1. Before you start

Tip

For this tutorial, you might find it useful to create a new project to test the process, then apply the knowledge to your existing projects.

  • Make sure you can run the project from UWP. To do this, in Visual Studio, select the platform you want (UWP-64, UWP-32, or UWP-ARM) from the Solution Platform drop-down list, and run the project.

  • Download the Xbox Live SDK.

    To write this page, we used XboxLiveSDK-1612-20170114-002. The sample is loosely based on the Achievements sample in the Xbox Live SDK.

  • Change your Xbox Live environment. In the SDK folder, under Tools, run:

  1. SwitchSandbox.cmd XDKS.1

XDKS.1 is the sandbox used for the Microsoft samples.

Warning

This blocks regular Xbox accounts and only permits developer accounts. To switch back, run:

  1. SwitchSandbox.cmd RETAIL
  • Make sure you can run the Achievements sample with your developer account.

2. Add the Xbox Live SDK to your solution

  • In Visual Studio, open your game solution.

  • Open the Package Manager Console (Tools > NuGet Package Manager > Package Manager Console).

  • In the Default project field, select your UWP project (eg MyGame.UWP).

MyGame.UWP

  • In the console, type:
  1. PM > Install-Package Microsoft.Xbox.Live.SDK.WinRT.UWP

Visual Studio adds the NuGet package to your project.

  • Make sure the package appears in the References list.

Package in list

3. Configure the UWP project

  • Delete MyGame.UWP.TemporaryKey.pfx.

  • Add xboxservices.config to your project.

    You can get this file from any Xbox Live SDK sample (eg the Achievements sample) for test purposes. When you want to publish the game, change the TitleId and Service config Id with the ones provided for your project. For details, see the Xbox Live documentation.

  • In the xboxservices.config properties, under Build Action, select Content, and under Copy to Output Directory, select Always.

Properties

  • Edit Package.appxmanifest with details relevant to your project.

    Again, you can use the manifest file from any Xbox Live SDK sample (eg the Achievements sample) for test purposes. If you associate your game with a store app, use the generated manifest file. For details, see the Xbox Live documentation.

  • Make sure the capability InternetClientServer is enabled.

4. Add user account scripts to your game

You need to enable Xbox Live capability in your game project without exposing the Xbox Live SDK. As MyGame.UWP already references MyGame.Game, we can't reference it. Instead, we can create an interface and implement it from the UWP project side.

Note

There are several ways to do this. This page explains one method.

  • Add two interfaces to your game, IAccountManager and IConnectedAccount.

  • On your UWP project (eg MyGame.UWP), implement the interfaces public class XboxAccount : IConnectedAccount and public class XboxLiveAccountManager : IAccountManager.

  • Add the account factory to your game so you can access it later from a game script. In the MyGameMainPage.xaml.cs, add the following line:

  1. Game.Services.AddService(typeof(IAccountManager), new XboxLiveAccountManager());

References

The final script should look like this at minimum:

  1. public class LoginScript : AsyncScript
  2. {
  3. private IConnectedAccount account;
  4. public override async Task Execute()
  5. {
  6. var accountMgr = Services.GetServiceAs<IAccountManager>();
  7. account = accountMgr?.CreateConnectedAccount();
  8. if (account == null)
  9. return;
  10. var result = account.LoginAsync();
  11. // TODO Add your code here!
  12. }
  13. }

Now you can expose the xbox_live_user functionality and other classes in your game.

Property Grid

Sample project

Sample project

See also