blob: 7e815fe11dac312d8d94d38ec90764d19d3916f3 [file] [log] [blame]
---
title: .NET Application Development Walkthrough
---
This section describes how to set up a .NET native client development environment using C# and CMake.
## <a id="prerequisites_dotnet"></a>Prerequisites
This walkthrough assumes that certain components are in place:
- The **<%=vars.product_name%> Native Client libraries**. Install the Native Client as described in
[Getting Started with the Native Library](getting-started-nc-client.html). Follow the ease-of-use
recommendations by installing the Native Client in `C:\Program Files\nativeclient`.
- The **CMake** tool suite. Download and install CMake, following the instructions on [cmake.org] (https://cmake.org).
- **Geode**: Install and configure Geode. See the [_Geode User's Guide_](http://geode.apache.org/docs/) for instructions and system requirements.
- **Visual Studio 2015** or higher and **.NET 4.5.2**.
To develop a Native Client application using .NET and CMake:
- Create a project directory structure
- Populate the project directories with C# source code
- Configure the CMake build environment
- Run CMake to configure your application
- Build and run your application using Visual Studio
## <a id="setting_up_dirs_dotnet"></a>Setting up Directories and Sources
1. Create a project directory structure. In this example, the project is called MyProject. The
directory structure provides a place for your application source files and a `cmake` modules
directory for project-specific CMake files:
```
MyProject\
cmake\
Find<%=vars.product_name%>Native.cmake
CMakeLists.txt
Program.cs
```
1. Change directory to MyProject and create your application sources. In this example, we have one
source file, `Program.cs`.
## <a id="configuring_cmake_dotnet"></a>Configuring CMake
1. Copy the `Find<%=vars.product_name%>Native.cmake` script from one of the Native Client examples to the `cmake` subdirectory.
1. Create CMakeLists.txt. Copy the file from an example, if you like, as a starting point. The CMakeLists.txt file
should contain the following CMake instructions:
- CMake minimum version
```
cmake_minimum_required(VERSION 3.10)
```
- Your project name and language
```
project(MyProject LANGUAGES CSharp)
```
- Path to the CMake modules directory where the `Find<%=vars.product_name%>Native.cmake` script is located and an instruction
telling CMake to use it:
```
set(CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake)
find_package(<%=vars.product_name%>Native REQUIRED COMPONENTS dotnet)
```
- The compilation target and the source(s) to be compiled
```
add_executable(MyProject Program.cs)
target_link_libraries(MyProject
PUBLIC
<%=vars.product_name%>Native::dotnet)
set_target_properties(MyProject PROPERTIES
VS_DOTNET_TARGET_FRAMEWORK_VERSION "v4.5.2"
VS_DOTNET_REFERENCES "System;${<%=vars.product_name%>Native_DOTNET_LIBRARY}")
```
Combined, the above elements comprise the following CMakeLists.txt:
```
# CMakeLists.txt for .NET Native Client App
cmake_minimum_required(VERSION 3.10)
project(MyProject LANGUAGES CSharp)
set(CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake)
find_package(<%=vars.product_name%>Native REQUIRED COMPONENTS dotnet)
add_executable(MyProject Program.cs)
target_link_libraries(MyProject
PUBLIC
<%=vars.product_name%>Native::dotnet)
set_target_properties(MyProject PROPERTIES
VS_DOTNET_TARGET_FRAMEWORK_VERSION "v4.5.2"
VS_DOTNET_REFERENCES "System;${<%=vars.product_name%>Native_DOTNET_LIBRARY}")
```
## <a id="building_the_app_dotnet"></a>Configuring the App
1. Create a build directory and set it as your current directory:
```
$ mkdir build
$ cd build
```
1. Run CMake to configure the build:
```
$ cmake ..
```
This creates a Visual Studio solution for your .NET application. For example, `MyProject.sln`.
## <a id="building_and_running_dotnet"></a>Building and Running the App
Open the solution file in Visual Studio and build the project.