• Docs »
• Using C# with VS2015

# Using C# with VS2015¶

## Creating a new project¶

To create a new project, choose from the File menu, File ‣ New ‣ Project.... This will bring up a dialog like New VS2015 Project. There are several settings we want to choose here:

1. Under Templates, open the Visual C# node and choose Windows.
2. In the center section, choose Console Application.
3. In the upper-middle section, choose .NET Framework 4.5 from the pull-down menu. (This option is not available in VS2015 Express)
4. Type a name for your project, like OESample1.
5. Click OK

Create New VS2015 Project

## Adding references to the OpenEye assemblies¶

In order to link in the OpenEye libraries, we need to add a reference to all of the OpenEye assemblies we will be using.

In the Solution Explorer, right-click on the References node inside the OESample1 project, and choose Add Reference....

In this dialog, we want to:

• Click Browse on the left side
• Click the Browse... button in the lower right.
• Browse to the “Libs” directory under where you unzipped the OpenEye .NET libs.
• Select “OpenEye.OEChem.dll” and hit Add

The dialog will look like Add Reference if successful.

Additional toolkits can be chosen as you add more functionality to your program. For this example, we are only using OEChem.

## Changing the build target¶

By default, a new C# project is set up to target “AnyCPU”, but since we are linking to native code, we need to change the build target to either “x86” or “x64”, depending on which version of the OpenEye toolkits you are using.

For this example, we are using the x86 version.

In the menu bar, you will see a pull-down menu that controls the Solution Configuration.

We need to create an “x86” configuration to replace the “AnyCPU” configuration.

Click on the drop down and choose “Configuration Manager...”

Launching the Configuration Manager

You should see a dialog like The Configuration Manager.

The Configuration Manager

In the upper right corner of the Configuration Manager Dialog, click on the “Active solution platform:” pulldown and choose <New...>.

Creating new solution platform

In the top pull-down, choose “x86” and leave the bottom pull-down (“Copy settings from”), set to “AnyCPU”. Click “OK.” See Creating new solution platform.

This should leave you with the Configuration Manager window looking something like x86 platform created

x86 platform created

Click Close. Now it is time to add some code to our program.

## Adding code to the project¶

In the project browser, double-click “Program.cs” to open it in the editor, if it is not already open.

At the top of the file, we will add using statements for OEChem:

using OpenEye.OEChem;


and then inside the “Main”, we add this code:

OEGraphMol mol = new OEGraphMol();
OEChem.OESmilesToMol(mol, "c1ccccc1CCCBr");
Console.WriteLine("mol has {0} atoms", mol.NumAtoms());


When you are finished, your sample should look something like Editing in VS2013.

Editing in VS2015

To test our example, we can run it from within VS2015 by hitting <Ctrl-F5>. If you don’t have any syntax errors, you should see a Console window appear with output that looks like Running the Example.

Running the example in VS2015

## Deploying the program to another machine¶

Once you have a program to a state where you want to run it elsewhere or share with someone else, you should first build in Release mode.

Go back to the pull-down menu in the toolbar and change Debug to Release.

The choose Build ‣ Build Solution.

The process of building not only compiles your C# code into an executable, it also copies the referenced OpenEye assemblies (OpenEye.OEChem.dll in this case) into the output directory. Additionally, all the DLLs that the OpenEye assembly depends on will also be copied into the Release binary directory.

If you navigate to the output directory for your project in the File Explorer, you should see a list of files like:

This directory contains everything needed to run the binary on a new machine except for the MSVC C++ DLLs. These should be installed via the installers from Microsoft: https://www.microsoft.com/en-us/download/details.aspx?id=48145