Movatterモバイル変換


[0]ホーム

URL:


Skip to main content

This browser is no longer supported.

Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.

Download Microsoft EdgeMore info about Internet Explorer and Microsoft Edge
Table of contentsExit editor mode

Get Started with MAUI and Xamarin

Feedback

In this article

Important

Visual Studio App Center was retired on March 31, 2025, except for the Analytics and Diagnostics features, which will continue to be supported until June 30, 2026.Learn more.

The App Center SDK uses a modular architecture so you can use any or all of the services.

Let's get started with setting up App Center .NET SDK in your app to use App Center Analytics and App Center Crashes. To add App Center Distribute to your app, have a look at thedocumentation for App Center Distribute.

1. Prerequisites

Before you begin, make sure that the following prerequisites are met:

  • Your project is set up in Visual Studio or Visual Studio for Mac.
  • You're targeting devices running iOS 11.0 or later or Android 5.0 (API level 21) or later.
  • You're not using any other SDK that provides Crash Reporting functionality.

Supported platforms:

  • MAUI iOS
  • MAUI Android
  • MAUI Windows
  • .NET 6.0 macOS
  • Xamarin.Android
  • Xamarin.iOS
  • Xamarin.Mac
  • Xamarin.Forms (iOS, macOS Android, UWP and Windows Desktop applications)

1.1 MAUI

Note

Currently there is noMAUI platform on the App Center portal. Please useXamarin for iOS and Android andUWP for Windows.

1.2 About Xamarin.Android

Create an app on the App Center portal with theAndroid as the OS andXamarin as the platform.

1.3 About Xamarin.iOS

Create an app on the App Center portal withiOS as the OS andXamarin as the platform.

1.4 About Xamarin.Mac

Create an app on the App Center portal withmacOS as the OS andXamarin as the platform.

Warning

There is a known issue that prevents an app from being uploaded to the App Store.Follow the progress ongithub.

1.5 About Xamarin.Forms (iOS, macOS, Android, UWP and Windows Desktop)

Create 5 apps on the App Center – one for each OS.

You need to selectXamarin as the platform for Android, iOS and macOS applications (UWP and Desktop applications doesn't have a Xamarin option).

For theWindows Desktop andmacOS applications you have to configure your project for compatibility with theXamarin.Forms platform.

2. Create your app in the App Center Portal to obtain the App Secret

If you've already created your app in the App Center portal, you can skip this step.

  1. Head over toappcenter.ms.
  2. Sign up or log in and hit the blue button on the top right corner of the portal that saysAdd new and selectAdd new app from the dropdown menu.
  3. Enter a name and an optional description for your app.
  4. Select the appropriate OS and platform depending on your project as described above.
  5. Hit the button at the bottom right that saysAdd new app.

Once you've created an app, you can obtain itsApp Secret on theSettings page on the App Center Portal. At the top right hand corner of theSettings page, click on thetriple vertical dots and selectCopy app secret to get your App Secret.

3. Add the App Center SDK to your solution

The App Center SDK can be integrated using Visual Studio or the Package Manager Console.

Note

App Center SDK usesstrong-named assemblies for compatibility with applications that use strong-named sign.

Visual Studio for Mac

  • Open Visual Studio.
  • ClickFile >Open and choose your solution.
  • In the solution navigator, right-click thePackages section, and chooseAdd NuGet packages....
  • Search forApp Center, and selectApp Center Analytics andApp Center Crashes.
  • ClickAdd Packages.

Visual Studio for Windows

  • Open Visual Studio.
  • ClickFile >Open and choose your solution.
  • In the solution navigator, right-clickReferences and chooseManage NuGet Packages.
  • Search forApp Center, and installMicrosoft.AppCenter.Analytics andMicrosoft.AppCenter.Crashes packages.

Package Manager Console

  • Open the console inVisual Studio. To do this, chooseTools >NuGet Package Manager >Package Manager Console.
  • If you're working inVisual Studio for Mac, make sure you've installedNuGet Package Management Extensions. For this, chooseVisual Studio >Extensions, search forNuGet and install, if necessary.
  • Type the following command in the console:
Install-Package Microsoft.AppCenter.AnalyticsInstall-Package Microsoft.AppCenter.Crashes

Now that you've integrated the SDK in your application, it's time to start the SDK and make use of the App Center services.

Note

If you use the App Center SDK in a portable project (such asXamarin.Forms), you must install the packages in each of the projects: the portable, Android, and iOS ones. To do that, you should open each sub-project and follow the corresponding steps described inVisual Studio for Mac orVisual Studio for Windows sections.

4. Start the SDK

To use App Center, you must opt in to the module(s) that you want to use. By default, no modules are started and you must explicitly call each of them when starting the SDK.

4.1 Add the using statements

Add the appropriate namespaces in the following files:

  • MAUI andXamarin.Forms -App.xaml.cs
  • Xamarin.iOS andXamarin.Mac -AppDelegate.cs
  • Xamarin.Android -MainActivity.cs
using Microsoft.AppCenter;using Microsoft.AppCenter.Analytics;using Microsoft.AppCenter.Crashes;

4.2 Add theStart() method

4.2.1 MAUI and Xamarin.Forms

You need to create different applications for each platform on the App Center portal. For each app you will have a different app secret. Open the project'sApp.xaml.cs file and add the following line in the constructor (or in theOnStart() method for Xamarin.Forms).

AppCenter.Start("ios={Your App Secret};macos={Your App Secret};android={Your App Secret};uwp={Your App Secret};windowsdesktop={Your App Secret}", typeof(Analytics), typeof(Crashes));

If you need to start App Center services separately, you should:

  1. Configure or start it with the App Secret.
  2. If the code can be called multiple times, check if the App Center is already configured.
  3. Start the required service(s) without the App Secret.
AppCenter.Configure("ios={Your App Secret};macos={Your App Secret};android={Your App Secret};uwp={Your App Secret};windowsdesktop={Your App Secret}");if (AppCenter.Configured){    AppCenter.Start(typeof(Analytics));    AppCenter.Start(typeof(Crashes));}

4.2.2 Xamarin.Android

Note

In case you're using the HockeyApp SDK for Android, make sure to initialize the HockeyApp SDKAFTER the App Center SDK.

Open the project'sMainActivity.cs file and add theStart() call inside theOnCreate() method

AppCenter.Start("{Your App Secret}", typeof(Analytics), typeof(Crashes));

Note

If your application has background services or multiple entry points like a broadcast receiver, exported activities or content providers, it's recommended to startAppCenter in theApplication.OnCreate callback instead.

4.2.3 Xamarin.iOS and Xamarin.Mac

Note

It isn't possible to have more than one active crash reporting SDK in your app. Disable the other SDKs' crash reporting functionality to make sure App Center can catch the crashes.

Open the project'sAppDelegate.cs file and add theStart() call inside theFinishedLaunching() method

AppCenter.Start("{Your App Secret}", typeof(Analytics), typeof(Crashes));

Note

If using Crashes, you must call this method in the UI/main thread and avoid starting background tasks until theStart method returns.The reason is that any null reference exception caught from another thread while Crashes is initializing may trigger a native crash and ignore the catch clause.Once theAppCenter.Start method returns, it's safe to try/catch null reference exceptions again.You can read more about the cause of this timing issue in theSignals and third-party crash reporters article.

Warning

It's not recommended to embed your App Secret in source code.

Important

The curly braces show where to place the actual app secrets, don't put curly braces in theStart call.

Note

For an iOS application, it isn't possible to have more than one active crash reporting SDK in your app. Disable the other SDKs' crash reporting functionality to make sure App Center can catch the crashes.

4.3 Replace the placeholder with your App Secret

Make sure to replace{Your App Secret} text with the actual value for your application. The App Secret can be found on theGetting Started page orSettings page on the App Center portal.

The Getting Started page contains the above code sample with your App Secret in it, you can copy-paste the whole sample.

The example above shows how to use theStart() method and include both App Center Analytics and App Center Crashes.

If you don't want to use one of the two services, remove the corresponding parameter from the method call above.

Unless you explicitly specify each module as parameters in the start method, you can't use that App Center service. In addition, theStart() API can be used only once in the lifecycle of your app – all other calls will log a warning to the console and only the modules included in the first call will be available.

For example - If you want to onboard to App Center Analytics, you should modify theStart() call as follows:

4.3.1 MAUI and Xamarin.Forms

AppCenter.Start("ios={Your App Secret};macos={Your App Secret};android={Your App Secret};uwp={Your App Secret};windowsdesktop={Your App Secret}", typeof(Analytics));

4.3.2 Xamarin Native

AppCenter.Start("{Your App Secret}", typeof(Analytics));

Great, you're all set to visualize Analytics and Crashes data on the portal that the SDK collects automatically.

Look at the documentation forApp Center Analytics andApp Center Crashes to learn how to customize and use more advanced functionalities of both services.

To learn how to get started with in-app updates, read the documentation ofApp Center Distribute.

Note

Using the portable APIs from Xamarin Forms, you'll see APIs from all modules, however not all those APIs are supported on theUWP andWindows Desktop platforms and are doing nothing when running on yourUWP andWindows Desktop applications. In particular UWP and Windows Desktop doesn't support the following module:Distribute. Any method with a return type would return eithernull (for objects),0 (for numbers), orfalse (for booleans) on UWP and Windows Desktop application.

5. Backup rules (Android only)

Note

Apps that target Android 6.0 (API level 23) or higher have Auto Backup automatically enabled. 

Note

If you already have a custom file with backup rules, switch to the third step.

If you use auto-backup to avoid getting incorrect information about devices, follow the next steps:

5.1. For Android 11 (API level 30) or lower.

  1. Createappcenter_backup_rule.xml file in theResources/xml folder.
  1. Open the project’sAndroidManifest.xml file. Add theandroid:fullBackupContent attribute to the<application> element. It should point to theappcenter_backup_rule.xml resource file.
android:fullBackupContent="@xml/appcenter_backup_rule"
  1. Add the following backup rules to theappcenter_backup_rule.xml file:
<full-backup-content xmlns:tools="http://schemas.android.com/tools">      <exclude domain="sharedpref" path="AppCenter.xml"/>      <exclude domain="database" path="com.microsoft.appcenter.persistence"/>      <exclude domain="database" path="com.microsoft.appcenter.persistence-journal"/>      <exclude domain="file" path="error" tools:ignore="FullBackupContent"/>      <exclude domain="file" path="appcenter" tools:ignore="FullBackupContent"/>  </full-backup-content>

5.2. For Android 12 (API level 31) or higher.

  1. Createappcenter_backup_rule.xml file in theResources/xml folder.
  1. Open the project’sAndroidManifest.xml file. Add theandroid:dataExtractionRules attribute to the<application> element. It should point to theappcenter_backup_rule.xml resource file.
android:dataExtractionRules="@xml/appcenter_backup_rule"
  1. Add the following backup rules to theappcenter_backup_rule.xml file:
<data-extraction-rules xmlns:tools="http://schemas.android.com/tools">    <cloud-backup>        <exclude domain="sharedpref" path="AppCenter.xml"/>        <exclude domain="database" path="com.microsoft.appcenter.persistence"/>        <exclude domain="database" path="com.microsoft.appcenter.persistence-journal"/>        <exclude domain="file" path="error" tools:ignore="FullBackupContent"/>        <exclude domain="file" path="appcenter" tools:ignore="FullBackupContent"/>    </cloud-backup>    <device-transfer>        <exclude domain="sharedpref" path="AppCenter.xml"/>        <exclude domain="database" path="com.microsoft.appcenter.persistence"/>        <exclude domain="database" path="com.microsoft.appcenter.persistence-journal"/>        <exclude domain="file" path="error" tools:ignore="FullBackupContent"/>        <exclude domain="file" path="appcenter" tools:ignore="FullBackupContent"/>    </device-transfer></data-extraction-rules>

Feedback

Was this page helpful?

YesNoNo

Need help with this topic?

Want to try using Ask Learn to clarify or guide you through this topic?

Suggest a fix?

  • Last updated on

In this article

Was this page helpful?

YesNo
NoNeed help with this topic?

Want to try using Ask Learn to clarify or guide you through this topic?

Suggest a fix?