---
title: C#
slug: v4-8/install-guides/c-sharp
icon: {"faIcon":"fa-brands fa-uikit"}
docTags: 
createdAt: 2023-07-28T03:48:24.723Z
---

You can integrate the Ditto SDK into C# projects to develop for platforms, including mobile apps for iOS and Android, desktop apps, Linux-enabled server systems, and more.

To install the C# SDK:

::::WorkflowBlock
:::WorkflowBlockItem
Confirm that you meet the minimum requirements. ([Prerequisites](./#prerequisites))
:::

:::WorkflowBlockItem
Install the Ditto SDK. ([Installing Dependencies](./#installing-dependencies))
:::

:::WorkflowBlockItem
Set up your app permissions. ([Configuring Permissions](./#configuring-permissions))
:::

:::WorkflowBlockItem
Add Ditto to your app. ([Initializing Ditto](./#initializing-ditto))
:::
::::

# Prerequisites

Following are the minimum requirements that must be met before attempting to install Ditto:

- [.NET Standard 2.1](https://learn.microsoft.com/en-us/dotnet/standard/net-standard?tabs=net-standard-2-1#net-standard-versions)&#x20;
- [.NET Core 3](https://dotnet.microsoft.com/en-us/download/dotnet/3.0)&#x20;
- [.NET Framework 4.0](https://dotnet.microsoft.com/en-us/download/dotnet-framework/net40)

# Installing Dependencies

Using either a compatible package manager, the .NET CLI, or by adding a reference to the package: `CSProj.xml` file, install the Ditto SDK by doing any of the following:

:::hint{type="info"}
If using a package manager other than NuGet, the official package manager for .NET, the command syntax to install Ditto may differ from the following snippet. For more information, see the official Nuget documentation > [Ditto .NET Standard.](https://www.nuget.org/packages/Ditto/)
:::

:::::Tabs
::::Tab{title="NuGet Package Manager"}
:::BlockQuote
Install-Package Ditto -Version 4.7.2
:::
::::

::::Tab{title=".NET CLI"}
:::BlockQuote
dotnet add package Ditto --version 4.7.2
:::
::::

::::Tab{title="CSProj XML"}
:::BlockQuote
\<PackageReference Include="Ditto" Version="4.7.2" />
:::
::::
:::::

:::hint{type="info"}
For the official .NET standard for Ditto, see the official NuGet reference at Packages > [Ditto](https://www.nuget.org/packages/Ditto/).
:::

# Configuring Permissions

To set up your environment for your target platform:

:::::::Tabs
:::::Tab{title="iOS Target"}
For apps targeting iOS; for example, MAUI, once you've added the Ditto package dependency, configure permissions and ensure your app continues syncing while running in the background, including when the end-user device is locked, by enabling background modes.

::::WorkflowBlock
:::WorkflowBlockItem
Open the `Info.Plist` file for your project.
:::

:::WorkflowBlockItem
Add the following key-value pairs, and then, if desired, modify each string value:

```xml
<key>NSBluetoothAlwaysUsageDescription</key>
<string>Uses Bluetooth to connect and sync with nearby devices</string>
<key>NSLocalNetworkUsageDescription</key>
<string>Uses WiFi to connect and sync with nearby devices</string>
<key>NSBonjourServices</key>
<array>
<string>_http-alt._tcp.</string>
</array>
```
:::

:::WorkflowBlockItem
Enable Bluetooth Background Modes:

```xml
<key>UIBackgroundModes</key>
<array>
<string>bluetooth-central</string>
<string>bluetooth-peripheral</string>
</array>
```
:::
::::
:::::

::::::Tab{title="Android Target"}
For apps targeting Android, once you've added the Ditto package dependency, configure the necessary permissions:

:::::WorkflowBlock
:::WorkflowBlockItem
Open the `AndroidManifest.xml` file typically located in the `src/main/` directory of your project.
:::

::::WorkflowBlockItem
Add the necessary permissions to ensure your app has the permissions required by Ditto:

:::hint{type="info"}
For instructions on how to modify the following configuration for permissions requests; for example, prevent your app from requesting unnecessary permissions on newer OS versions or ensure compatibility with both older and newer OS versions, see [Customizing Permissions](docId:9Ce9On2Myv2Gc9tIyg0dt).
:::

```xml
<manifest
xmlns:tools="http://schemas.android.com/tools"
xmlns:android="http://schemas.android.com/apk/res/android">
<uses-permission android:name="android.permission.BLUETOOTH"
android:maxSdkVersion="30" />
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN"
android:maxSdkVersion="30" />
<uses-permission android:name="android.permission.BLUETOOTH_ADVERTISE"
tools:targetApi="s" />
<uses-permission android:name="android.permission.BLUETOOTH_CONNECT"
tools:targetApi="s" />
<uses-permission android:name="android.permission.BLUETOOTH_SCAN"
android:usesPermissionFlags="neverForLocation"
tools:targetApi="s" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"
android:maxSdkVersion="32" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"
android:maxSdkVersion="30" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.CHANGE_NETWORK_STATE" />
<uses-permission
android:name="android.permission.CHANGE_WIFI_MULTICAST_STATE" />
<uses-permission android:name="android.permission.CHANGE_WIFI_STATE" />
<uses-permission android:name="android.permission.NEARBY_WIFI_DEVICES"
android:usesPermissionFlags="neverForLocation"
tools:targetApi="tiramisu" />
```
::::
:::::

## Customizing Permissions

To modify the behavior of permission requests for the Android target:&#x20;

:::hint{type="info"}
Features related to runtime permissions management for Android is planned for future release.
:::

::::WorkflowBlock
:::WorkflowBlockItem
Add the following namespace attribute to the root `<manifest>` tag of your `AndroidManifest.xml` file:

```xml
xmlns:tools="http://schemas.android.com/tools"
```
:::

:::WorkflowBlockItem
To request permissions on all OS versions of Android:

```xml
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"
tools:remove="android:maxSdkVersion" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"
tools:remove="android:maxSdkVersion" />
```
:::

:::WorkflowBlockItem
To limit permissions request, use the following attributes as desired:

- [tools\:targetApi](docId:9Ce9On2Myv2Gc9tIyg0dt)
- [android\:maxSdkVersion](docId:9Ce9On2Myv2Gc9tIyg0dt)
:::
::::

### tools\:targetApi

The `tools:targetApi` attribute allows you to specify that a permission should only be requested on devices running a specified Android API level or *higher*.

By limiting permissions requests, you prevent errors that result from asking permissions on devices running older OS versions of Android.

### android\:maxSdkVersion

With the `android:maxSdkVersion` attribute, you can customize to only initiate a permission request on devices running a specified Android API level or lower.

Setting to a specified API level or lower helps avoids unnecessary permissions requests on devices running newer OS versions of Android.
::::::
:::::::

# Initializing Ditto

Once you’ve installed the Ditto SDK, set the debug level you want Ditto to log messages for, create a new Ditto identity, and set up Ditto exception handling for data sync operations:&#x20;

```csharp
try
{
    DittoLogger.SetMinimumLogLevel(DittoLogLevel.Debug);
    var ditto = new Ditto(DittoIdentity.OnlinePlayground("REPLACE_ME_WITH_YOUR_APP_ID", "REPLACE_ME_WITH_YOUR_PLAYGROUND_TOKEN", true), path);
    ditto.StartSync();
}
catch (DittoException ex)
{
    Console.WriteLine($"Ditto Error {ex.Message}");
}
```

# Next Steps

Learn how to build a task list app built on .NET Maui and integrated with Ditto by going to the [MAUI Task App](docId:6yvLrFHVxy3jsz88K2MFq) how-to tutorial.

