# 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](https://681332907-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FZ9tiJ3xbT7zyJ4FlZiMM%2Fuploads%2Fgit-blob-cd1bc1942c553134f6fd8e4133e2090680612cec%2Fcs-create-a-new-dll-project.png?alt=media)

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

![Project name and location](https://681332907-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FZ9tiJ3xbT7zyJ4FlZiMM%2Fuploads%2Fgit-blob-84d71ffaccc37c0bb374fa7a417b0d418547c646%2Fcs-project-name-and-location.png?alt=media)

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

![Project created](https://681332907-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FZ9tiJ3xbT7zyJ4FlZiMM%2Fuploads%2Fgit-blob-b37ae4f36d19dc61b822b022aab82720e8169c18%2Fcs-project-created.png?alt=media)

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

![Copy wrapper](https://681332907-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FZ9tiJ3xbT7zyJ4FlZiMM%2Fuploads%2Fgit-blob-deb12735486b153dd21d5256dbb867f7508b99cb%2Fcs-copy-wrapper.png?alt=media)

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](https://681332907-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FZ9tiJ3xbT7zyJ4FlZiMM%2Fuploads%2Fgit-blob-2190efe4eaff87720372d64ef9f19d0ee63ae83d%2Fcs-add-wrapper.png?alt=media)

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

![Add reference to wrapper](https://681332907-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FZ9tiJ3xbT7zyJ4FlZiMM%2Fuploads%2Fgit-blob-b9821485f9020b430e76d7d8db010f25027a1e70%2Fcs-add-reference-to-tacview-wrapper.png?alt=media)

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](https://681332907-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FZ9tiJ3xbT7zyJ4FlZiMM%2Fuploads%2Fgit-blob-3bcf75064007993ae83087cbd6551a0eb29e3d57%2Fcs-configure-x64.png?alt=media)

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](https://681332907-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FZ9tiJ3xbT7zyJ4FlZiMM%2Fuploads%2Fgit-blob-d813c8b0242f1f09012eb2749b6e635f95017284%2Fcs-copy-hello-world.png?alt=media)

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](https://681332907-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FZ9tiJ3xbT7zyJ4FlZiMM%2Fuploads%2Fgit-blob-4384225a1b13dd1d4eb0e302c15288503e44a824%2Fcs-copy-dll-export.png?alt=media)

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](https://681332907-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FZ9tiJ3xbT7zyJ4FlZiMM%2Fuploads%2Fgit-blob-ef9b6926f8970072ec2bafc407b93dc4c9e17123%2Fcs-run-dll-export.png?alt=media)

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

![Apply DLL Export](https://681332907-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FZ9tiJ3xbT7zyJ4FlZiMM%2Fuploads%2Fgit-blob-0669784915acf0a284eb6957961dc8cdb73eb3d6%2Fcs-apply-dll-export.png?alt=media)

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](https://681332907-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FZ9tiJ3xbT7zyJ4FlZiMM%2Fuploads%2Fgit-blob-584281592cf397c2f971fe641a4d5728c7e9f3f7%2Fcs-output-path.png?alt=media)

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

![Set External Program](https://681332907-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FZ9tiJ3xbT7zyJ4FlZiMM%2Fuploads%2Fgit-blob-ae20477cd0a2ebbe2f92bc3ccba6508637e8a60b%2Fcs-set-external-program.png?alt=media)

### 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.
