---
title: Installing C# SDK
slug: v4-5/csharp/installation
docTags: 
createdAt: 2023-08-03T04:50:58.447Z
---

You can integrate the Ditto SDK into C# projects to develop for a wide range of platforms.

:::hint{type="info"}
For a complete overview of the platforms, transports, and devices the C# SDK supports, see [Compatibility with C#](docId\:ZOxGwK1yhgubSsU0ne56e).
:::

To install the C# SDK:

::::WorkflowBlock
:::WorkflowBlockItem
Confirm that you meet the minimum requirements. ([Prerequisites](docId\:BS5-iHTG2AaehN9Ltw3SR))
:::

:::WorkflowBlockItem
Prepare your environment for Ditto. ([Setting Up Your Environment](docId\:BS5-iHTG2AaehN9Ltw3SR))
:::

:::WorkflowBlockItem
Set up your app permissions. ([Setting Up Permissions](./#setting-up-permissions))
:::

:::WorkflowBlockItem
Add Ditto to your app. ([Integrating Ditto](docId\:BS5-iHTG2AaehN9Ltw3SR))
:::
::::

# 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 the NuGet package manager, .NET CLI, or adding a reference to your `.csproj` XML file:

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

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

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

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

# Permissions Configurations

If developing for Android or iOS targets through frameworks like *Xamarin.Forms* and Multi-Platform App UI (*MAUI*), once you've integrated the Ditto dependency in your environment, configure your permissions as appropriate.

Xamarin is a Microsoft-developed framework for building cross-platform apps using C#. Building upon Xamarin's foundation, MAUI offers additional features and various cross‑platform development improvements. For more information, see Microsoft for the official [Xamarin documentation](https://learn.microsoft.com/en-us/xamarin/).&#x20;

## Setting Up Permissions

Due to both Android and iOS limiting access to some device functionality for end‑user control and privacy by default, for Ditto to function optimally and use all the network transports — Bluetooth Low Energy (LE), Local Area Network, and so on — configure your app to automatically request all necessary permissions from end users at runtime by doing the following. &#x20;

:::::::Tabs
::::::Tab{title="Android OS"}
:::hint{type="info"}
For more information on permissions requirements for Android OS, see the official Android documentation > [Bluetooth permissions](https://developer.android.com/develop/connectivity/bluetooth/bt-permissions) and [Request permission to access nearby Wi-Fi](https://developer.android.com/develop/connectivity/wifi/wifi-permissions).&#x20;
:::

:::::WorkflowBlock
::::WorkflowBlockItem
Add the following permissions to your project's AndroidManifest.xml file:

:::hint{type="info"}
The `tools:targetAPI` attribute ensures you avoid errors in older OS versions that do not recognize the permission.

The `android:maxSdkVersion` attribute ensures you avoid asking for more permissions than Ditto needs by preventing permission requests on devices running a newer OS version.

To opt out of this behavior, see step 2.
:::

:::CodeblockTabs
AndroidManifest.xml

```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" />
```
:::
::::

::::WorkflowBlockItem
If you want to request permissions on all OS versions, regardless of API (`tools:targetAPI`) and SDK levels (`tools:targetAPI`), add the following to override the location permission option:

:::CodeblockTabs
AndroidManifest.xml Location Permission Override Option

```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" />
```
:::

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


::::
:::::
::::::

:::::Tab{title="iOS"}
::::WorkflowBlock
:::WorkflowBlockItem
From your **Info.Plist** file, add the following key-value pairs, and then, if applicable, modify each `string` assigned to **Value**:

- Once implemented, the following `string` values display as a prompt to your end users explaining why the app requires certain permissions.

- If your end users prefer a language other than English, replace the `string` values with their language equivalents or use localized strings.

```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
Ensure uninterrupted syncing, by enabling Bluetooth Background Modes in your **Info.Plist** file.

Once enabled, you ensure your app continuously runs in the background, even when the end-user's device is locked.

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

##

# Integrating Ditto

Integrate Ditto with your app:

:::hint{type="info"}
For instructions on how to obtain your access credentials, see [Onboarding](docId\:hK2s3Ld8Sj-Ti5snxwkQ1). For an introduction to authentication in Ditto, see *Ditto Basics* > [Authentication and Initialization](docId\:tU7x-WQHlIyZeMgKOs0wV).
:::

```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}");
}
```

```csharp
var insertArgs = new Dictionary<string, object>();
insertArgs.Add("newCar", new { _id = "123", color = "blue" })

await ditto.Store.ExecuteAsync(
  "INSERT INTO cars DOCUMENTS (:newCar)",
  insertArgs);
```

