-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Developing with Visual Studio Code
- This guide does not cover Visual Studio, but Visual Studio Code.
- Visual Studio Code takes less space to store than Visual Studio.
- Visual Studio Code runs on Windows, Mac, and Linux.
- If you inexperienced in modding, have space on your computer and are on Windows, it is highly recommended to get Visual Studio instead.
- This guide is not meant to learn C# fundamentals
- Download Visual Studio Code.
- Install Visual Studio Code by running the downloaded installer. Allow the program to run and accept license agreements as you would normally do. The default options should be suitable.
- Install the .NET 8 SDK by downloading the installer, running it, and following the instructions. Download the installer for the latest SDK release labeled "x64" corresponding to your operating system. Don't download the .NET 6.0 or .NET 7.0 versions, those will not work. (Visual Guide)
- Launch Visual Studio Code.
- Install the C# Dev Kit extension.
- You should see something similar to the following: Welcome Page
- Click the Extensions button: Button Location
- Type
C#
into the search bar, click the "C# Dev Kit" extension, then click the install button: Install C# Extension Steps - Optional. If you are an experienced user, IntelliCode for C# Dev Kit will be a helpful extension. Install that as well if interested. However, if you are inexperienced, this will just cause confusion and is not recommended: Extension Details
- Wait for the installation to complete. The output window will show other extensions being downloaded and installed as it is packaged with C# Dev Kit: Extensions Installed
Follow the instructions in Basic tModLoader Modding Guide
- It is very important that you installed the extensions mentioned above and .NET 8 SDK listed in Prerequisites.
- Open Visual Studio Code
- Click
Open Folder
. If you don't see it, clickFile->Open Folder
. Navigate to%UserProfile%\Documents\My Games\Terraria\ModLoader\Mod Sources\TutorialMod
if you're on Windows, or Navigate to~\Library\Application Support\Terraria\ModLoader\Mod Sources\TutorialMod
if you're on Mac, and clickSelect Folder
: Example - You should now see various files available to edit. Open
TutorialMod.cs
and you should be able to start writing code. - You can create new folders and
.cs
files by right clicking in empty space in the Explorer pane: New File
- Building your mod is easy. Just open
Terminal->New Terminal
from the Menu Bar: Location - Once the terminal is open, simply just type
dotnet msbuild
to build your mod.
This feature is disabled by default. You will need to open settings and enable it.
- Press
Ctrl + ,
on your keyboard to open settings, then click on the icon on the top right: Location - Inside the curly braces, add these lines:
"csharp.experimental.debug.hotReload": true,
"csharp.debug.hotReloadOnSave": true
- Press
Ctrl + S
to save. Hot Reloading should be enabled.
-
If you get an error relating to "project.assets.json not found. Run a NuGet package restore to generate this file.", then go to
Terminal-> NewTerminal
, run thedotnet restore
command in the terminal that appears. Now you can run the build again withdotnet msbuild
. -
If you get an error relating to "System.IO.IOException: The process cannot access the file TutorialMod.tmod because it is being used by another process.", you need to disable the mod in tModLoader and reload mods so that the file can be edited. Closing tModLoader completely is also an option when building.
Please read the Why Use an IDE page. Most of the features apply to Visual Studio Code. If you aren't seeing errors being underlined or fixes being suggested, you might have skipped installing the C# Dev Kit Extension.
Debugging can be achieved by using VS Code's Run and Debug feature.
- Click
Run and Debug
(or pressCtrl + Shift + D
): Location - While having a
.cs
related to the mod opened in the main editor, clickRun and Debug
button: Big Button - tModLoader should start while enabling your current state of your mod. You can add breakpoints from here and hot reload when necessary and if enabled: Debug Console
- To add breakpoints, simply click the red dot left of the line number as so: Red Circle Breakpoint
Assuming you followed every step in Prerequisites, the most common reason for this error is failing to open your mod's code correctly. Please follow the Open your Mod Source section. Failure to open your mod this way will make using Visual Studio Code counterproductive.