Tutorial: How to get tModLoader working with Visual Studio Code. (Outdated, see note)

Which editor do you use to make Terraria Mods?


  • Total voters
    18

BlueStag

Terrarian
How to get tModLoader working with Visual Studio Code.

Hello! I make Terraria mods. Most people who make them use Visual Studio, but can we look at Visual Studio Code, the underrated "IDE" for C#? Let's look at how we can use Visual Studio Code to make tModLoader mods. However, I will not discuss debugging, because I don't debug much.

Note 02 August 2021: I figured out that OmniSharp has support for .NET Framework, and that requires administrator privilages to install. This tutorial is sort of outdated, but if you don't have administrator rights, read on.



There are two ways of doing this, the first one being:

The boring way -_-

This is something you should do as a last resort. Just open up a folder and edit the files without any extensions. That's it. How do you live without Intellisense?

1620462769059.png

There are no extensions being used here. This means that you are missing out on many features. To name a few:
  • Intellisense
  • Compiler error highlighting
  • Semantic highlighting (structs get a brighter shade of green with this)
What a bad life to live! Let's get all these features!

The good way

First things first, you'll need the .NET 5.0 SDK or .NET Core 3.1 SDK. Do not install .NET Framework as VSCode does not fully support it.
.NET 5.0 (Current) / .NET Core 3.1 (LTS)
To make sure it is installed, run the following commands:
Bash:
dotnet new console -o HelloWorld
cd HelloWorld
dotnet run
You should have something like this:

When running dotnet run, you should see Hello World!

If, for some reason, dotnet is "not recognized as the name of a cmdlet, function, script file, or operable program", check if it is on path:

C:\dotnet is on path.

Note: I installed .NET 5 on C:\dotnet. Your installation would probably be somewhere in C:\Program Files or C:\Program Files (x86)

Now open up your mod folder in Visual Studio Code. Nothing seems to have changed at the moment... that is because you need the C# extension:

C# (ms-dotnettools.csharp) by Microsoft

Feel free to install other C# extensions. Here are some that I have:
  • Better Comments - aaron-bond.better-comments​
  • C# Colors - logerfo.csharp-colors​
  • C# Sort Usings - jongrant.csharpsortusings​
  • MSBuild project tools - tintoy.msbuild-project-tools​
  • vscode-solution-explorer - fernandoescolar.vscode-solution-explorer​
Now, you should see Omnisharp installing in your output window. However, once Omnisharp has finished installing and started itself, you'll see that it throws an error:

The reference assemblies for .NETFramework,Version=v4.5 were not found.

There is a very simple fix for this, which requires you to edit the .csproj file.
<TargetFramework>net45</TargetFramework><PlatformTarget>x86</PlatformTarget>

The target framework and the platform target is what is causing this error.
To fix this, you need to replace the target framework with either net5.0 or netcoreapp3.1 and change the platform target to whatever platform your .NET Core SDK is for. In this case, it's x64 for me.

Now restart Omnisharp by typing in the command pallete Omnisharp: Restart Omnisharp. The error is gone and you've got all that you missed out on before:
  • Intellisense
    • 1620464249018.png
  • Compiler Error Highlighting
    • 1620464322783.png
  • Semantic Highlighting
    • 1620464521522.png
If you see this message:
1620464197457.png

Click Restore. You are now ready to go!
As for those who are worried that this will not compile because of a different target, do not worry because the compiler always uses .NET Framework.


If you would like to show your support for Visual Studio Code in Terraria modding, put this in your signature:



Code:
[URL=https://forums.terraria.org/index.php?threads/tutorial-how-to-get-tmodloader-working-with-visual-studio-code.105299/][IMG]https://forums.terraria.org/index.php?attachments/1620464834083-png.320623/[/IMG][/URL]
 

Attachments

  • 1620464834083.png
    1620464834083.png
    12.4 KB · Views: 3,451
Last edited:
I followed the link to .NET 5 and .NET 6 comes up. Is it fine to get 6, or do I need to choose 5 for modding to work?

Also, I'm installing VS 2022 and that has the option to install .NET 5 and 6. I guess I'll do that instead? I read someone say that people were having problems with 2022, but that modding with 1.4 will need 2022. I'm confused already.
 
Last edited:
I followed the link to .NET 5 and .NET 6 comes up. Is it fine to get 6, or do I need to choose 5 for modding to work?

Also, I'm installing VS 2022 and that has the option to install .NET 5 and 6. I guess I'll do that instead? I read someone say that people were having problems with 2022, but that modding with 1.4 will need 2022. I'm confused already.
Well for TModLoader 1.4.4 it's required to have .NET 6 to mod so I guess that will be fine
 
Back
Top Bottom