Visual Studio Setup - THDigi/SE-ModScript-Examples GitHub Wiki
Moved to SE wiki: https://spaceengineers.wiki.gg/wiki/Modding/Tutorials/Setup_Visual_Studio
Old content
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.
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.
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.
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.
Leave Target Framework to what it is, we'll override it later anyway.
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.
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)
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).
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.
Go back to the quick intro guide to see what to do next in regards to scripting.