Visual Studio Setup - THDigi/SE-ModScript-Examples GitHub Wiki

If you landed here without first seeing Quick Intro to SE Modding then I highly recommend first reading that, there's important information on the scripting section.


First, get the tool from: visualstudio.microsoft.com.

The community edition is free, which requires a (also free) Microsoft account login to continue to work after 30 days, tiny price to pay for the huge amount of help this tool provides.

NOTE: "Visual Studio Code" is a completely different tool, this guide is for Visual Studio, 2022 community edition in particular but it should be similar for newer or even older versions.

Installation

Workloads: .NET desktop development

In Individual Components tab above, have .NET framework 4.8 targeting pack.

Everything else is up to you. You can even uncheck all optional things for .NET desktop development to save some space.

Creating solution/project

  1. Create a "Class Library" project

The .NET or .NET standard one:

You might've noticed we're not making a .NET Framework project, that's because we also want the newer .NET SDK .csproj format which is nicer to use in some ways, but it also makes it way easier to use the MDK2 mod analyzer.

  1. In the 2nd window it's up to you

A few things to be aware of:

  • VS will create a folder as the project name in the Location.
  • You can simply create the project elsewhere then move the contents to your mod or somewhere else too.
  • Compiling could generate some .cs files in the obj folder (current .csproj provided does not do this) which will trigger the game's whitelist, preventing your mod from compiling. To avoid this you should not have the project in Data\Scripts\, you can have it in mod's root folder or somewhere else entirely if you want to set up some post-build copying or something.
  1. In the 3rd window just continue

Leave Target Framework to what it is, we'll override it later anyway.

  1. Set platform to x64

At the top it says [Debug] [Any CPU], from [Any CPU] drop down you can go to Configuration manager:

Then Active Solution Platform's drop down pick <New...>, select x64 and then just click Ok.

Ensure project's platform is also using that newly made x64.

You can also delete the AnyCPU one by going to <Edit...> from both dropdowns.

  1. Edit .csproj file

This simplifies a lot of manual configuration with one swoop.

Once project is created and loaded, double-click the project to open the .csproj file for editing.

Then replace its contents with:

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <TargetFramework>net48</TargetFramework>
    <Platforms>x64</Platforms>
    <LangVersion>6</LangVersion>
    <GenerateAssemblyInfo>false</GenerateAssemblyInfo>
    <GenerateNeutralResourcesLanguageAttribute>false</GenerateNeutralResourcesLanguageAttribute>
    <GenerateTargetFrameworkAttribute>false</GenerateTargetFrameworkAttribute> 
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="Mal.Mdk2.ModAnalyzers" Version="*" />
    <PackageReference Include="Mal.Mdk2.References" Version="*" />
  </ItemGroup>

</Project>

And save the file.

If you have issues with Mal.Mdk2.References, first please contact Malware about it and in the meantime you can use the older guide which has references directly in the .csproj: Visual Studio Setup (old)

  1. Reload solution

It might ask by itself or might not, but better safe and just reload the solution: File -> Close solution, then pick the solution again in the window that pops up (or File -> Start window if it doesn't pop up).

  1. (Optional) Test whitelist checker

If you want to test the whitelist checker, type System.Threading.Thread t; in a class and see if it complains.


And now you can pretty much start programming your mod! You'll need some template classes to get started so follow the link below.

You can also make this project a template so you can speed up future projects creations, in Project -> Export Template.

Next steps

Go back to the quick intro guide to see what to do next in regards to scripting.

⚠️ **GitHub.com Fallback** ⚠️