-
Notifications
You must be signed in to change notification settings - Fork 10
Creating an empty plugin: Visual Studio Code
This guide assumes you have completed the environment setup for Visual Studio Code, and you already have an Anvil server up and running.
If you have not yet installed Visual Studio Code, or the project templates, please walk through this tutorial first: https://github.com/nwn-dotnet/Anvil/wiki/Setting-up-your-development-environment
If you have not yet got a working server, please look at the Getting started guides in the Readme of the Anvil repository.
- Launch Visual Studio Code
2. Using the "File" dropdown, click "Open Folder"
3. Navigate to/create a new empty folder. This folder will store the files for your plugin project
- In this example, we will call the plugin
MyFirstPlugin
- Click
Select Folder
when you are happy with the location.
4. Using the "Terminal" dropdown, click "New Terminal"
At the bottom of the screen, you should see a new terminal that is pointing to the folder you selected in step 3.
5. In the terminal, run the following commands
dotnet new --install NWN.Templates
dotnet new anvilplugin
You should see the following terminal output
And in the explorer view, you should now see 2 files added to the project folder
6. Click on the file called ".csproj", and double check/change to the desired version of Anvil
7. Once you have chosen a version, run the following command in the terminal
dotnet restore
If you get the following output, the project has been created and is ready for development :)
If you get something like the following, make sure you have not made a typo in the version name
8. If you have not already, re-open your project folder using the "Open Folder" dialog
9. Open the terminal again, and run the following command
dotnet build
This will build the source files in your project, and produce a plugin binary.
You should see the following terminal output:
Once the build has succeeded, you should see a new directory called bin
containing the compiled plugin binaries.
10. Click "Reveal in File Explorer" on the bin folder to navigate to it.
When submitting plugins for review in the plugins forum, copying the plugin to a server, or sharing the plugin with other people, you will need to send the whole folder for the plugin to work.
11. Copy the "YourPluginName" folder to the Anvil Plugin directory. This directory should be inside your NWN home directory (modules/hak/etc), under `anvil/plugins`
- E.g. if your plugin is called
MyFirstPlugin
, the directory structure should look like the following
hak/
tlk/
modules/
anvil/
|----Plugins/
|----MyFirstPlugin/
|----MyFirstPlugin.deps.json
|----MyFirstPlugin.dll
|----MyFirstPlugin.pdb
12. Launch the server! If everything is done correctly, you should see the plugin loading as a message
I [2021/07/02 23:52:04.035] [Anvil.Internal.LoggerManager] Using Logger config: "/nwn/anvil/Plugins/FRC/nlog.config"
nwnxee-server_1 | I [2021/07/02 23:52:04.064] [Anvil.AnvilCore] Prelinking native methods.
nwnxee-server_1 | I [2021/07/02 23:52:04.199] [Anvil.AnvilCore] Prelinking complete.
nwnxee-server_1 | I [2021/07/02 23:52:04.199] [Anvil.AnvilCore] Loading NWN.Anvil 8193.23.0.0 (NWN.Core: 8193.23.4.0, NWN.Native: 8193.23.3.0).
nwnxee-server_1 | I [2021/07/02 23:52:04.199] [Anvil.AnvilCore] .NET runtime is ".NET 5.0.6", running on "Linux 5.4.72-microsoft-standard-WSL2 #1 SMP Wed Oct 28 23:40:43 UTC 2020", installed at "/usr/share/dotnet/shared/Microsoft.NETCore.App/5.0.6/"
nwnxee-server_1 | I [2021/07/02 23:52:04.199] [Anvil.AnvilCore] Server is running Neverwinter Nights 8193.23.
nwnxee-server_1 | I [2021/07/02 23:52:04.199] [NWN.Plugins.PluginLoader] Loading 1 DotNET plugin/s from: /nwn/anvil/Plugins
nwnxee-server_1 | I [2021/07/02 23:52:04.327] [NWN.Plugins.PluginLoader] Loading DotNET plugin (MyFirstPlugin) - /nwn/anvil/Plugins/MyFirstPlugin/MyFirstPlugin.dll
nwnxee-server_1 | I [2021/07/02 23:52:04.336] [NWN.Plugins.PluginLoader] Loaded DotNET plugin (MyFirstPlugin) - /nwn/anvil/Plugins/MyFirstPlugin/MyFirstPlugin.dll
You should now have a working environment for developing plugins, and can start looking into using the Anvil API to write your very first plugin!
Usage of the Anvil API is covered in general tutorials, which can be found HERE.