> For the complete documentation index, see [llms.txt](https://raia-software-inc.gitbook.io/tacview/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://raia-software-inc.gitbook.io/tacview/sdk/create-a-new-cs-add-on.md).

# Create a New C# Add-on in Visual Studio

You can create C# add-ons for Tacview using [Visual Studio](https://visualstudio.microsoft.com/vs/community/). In this tutorial we are using Visual Studio Community 2022.

Download and run the [latest version of Tacview](http://tacview.net/download).

In Visual Studio, create a new `Class Library (.NET framework)` project:

![Create a new DLL Project](/files/u2i0xaBDUgnW8wivMiud)

Enter your project name, solution name, and location. Make sure you are targeting `.NET Framework 4.7.2`.

![Project name and location](/files/SH8LFEVrA5J6TPmNgBFG)

Click `Create`. A blank project will be created for you.

![Project created](/files/zy6z9Nl9gcp65RrsqLZw)

From `C:\Program Files (x86)\Tacview\SDK\cs\`, copy the folder `Tacview.Wrapper` into the folder of your new add-on:

![Copy wrapper](/files/uioVEavWzq6tnB3nx0MC)

Right-click on the solution to `Add` -> `Existing Project`. Find the `Tacview.Wrapper` in your add-on folder and add the project at `project` -> `Windows` -> `Tacview.Wrapper.vcxproj`

![Add wrapper](/files/J0ovKB3P4gC0jxB2oaY3)

Right-click on your project and add a reference to the wrapper.

![Add reference to wrapper](/files/2r3s3xbLm2o9sA67GJ77)

Make sure everything is configured to build as 64-bit target `x64`. Do not build for `Any CPU`.

The following is an example of a build configuration that should work if debugging in `x64`.

![Configure x64](/files/jkafvGONad4lDbsKJD1h)

Copy the source code of the class `DLL Interface` from `C:\Program Files (x86)\Tacview\SDK\cs\HelloWorld\HelloWorld.DllInterface.cs` to your add-on.

![Copy Hello World](/files/GlyNKziparWok2t5HhZY)

Obtain the most recent version of `DllExport.bat` from [this GitHub repository](https://github.com/3F/DllExport) and place it in your add-on folder.

![Copy DLL Export](/files/tkIHnr4GMR7o04FT5G23)

Close the solution, then run `DllExport.bat` in your add-on folder

You will be prompted to browse to the location of the solution of your add-on.

![Run DLL Export](/files/opfAVKivlRzjnowhsVhv)

Make sure `x64` is selected, tick the Installed checkbox next to your Add-on and Apply.

![Apply DLL Export](/files/xL4VnPYadRSZp9P6YTJH)

Reload your project.

Right-click on your Project and select Properties to set the Output Path equal to `C:\ProgramData\Tacview\AddOns\YourAddOn\`, so that Tacview can automatically find and load your `DLL`:

![Set Output Path](/files/YgsDXFltRZLuGqwrwY24)

To debug your add-on, specify Tacview as the external program to start:

![Set External Program](/files/CeYbQ2MEUkESo0zYtADh)

### Troubleshooting

**Microsoft Visual C++ Redistributable for Visual Studio 2015, 2017 and 2019**

In the case that this error message appears in the Tacview Debug Log:

```
Make sure the latest version of Microsoft Visual C++ Redistributable for Visual Studio .. has been installed on this system
```

Make sure that you are not attempting to run a `Debug` version of this addon if you are not a developer. `Debug` builds require additional `DLL`s and tools.

First, use the [link provided](https://learn.microsoft.com/en-us/cpp/windows/latest-supported-vc-redist?view=msvc-170) to download the latest version of Microsoft Visual C++ Redistributable for Visual Studio, even if you are sure that you have already downloaded everything your need. Close and re-launch Tacview.

If the error is still occurring it could be caused by the `DLL` having been compiled in `Debug` mode and now being run on a computer that is not set up for debugging. If you are the developer, be sure you are compiling the `DLL` in `Release` mode. If you are not the developer, please contact the developer.

**When I debug or throw exceptions in a .NET add-on, Tacview crashes.**

Make sure you are running at least Tacview 1.9.3, in which this issue is resolved. This issue occurs only on newer systems because it has to do with a security enhancement introduced in latest versions of Windows in combination with latest Intel and AMD processors.
