Setup Visual Studio

From Space Engineers Wiki
Jump to navigation Jump to search

Visual Studio (not to be mistaken for Visual Studio Code, very different programs) is an IDE that greatly helps programmers to write code, especially in unknown APIs such as Space Engineers'.

This guide is for Visual Studio, 2022 community edition in particular but it should be similar for newer or even older versions.

This guide can also be used for other IDEs that support .csproj and nuget packages.


Download 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.

Install

Run the downloaded file and it should ask you a few things.

  • In Workloads pick .NET desktop development.
  • In Individual Components tab above, ensure .NET framework 4.8 targeting pack is enabled.

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

Create solution/project

Create a "Class Library" project

The .NET or .NET standard one:

centered

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.

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.

In the 3rd window just continue

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

Set platform to x64

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

centered

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

centered

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.

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.

centered

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 .csproj which has references hardcoded:

Older .csproj

NOTE: You need to Find-and-replace (Ctrl H) all the paths from <HintPath> to point to your SE install folder.

<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="*" />
  </ItemGroup>

  <ItemGroup>
    <Reference Include="ProtoBuf.Net.Core">
      <HintPath>C:\Program Files (x86)\Steam\steamapps\common\SpaceEngineers\Bin64\ProtoBuf.Net.Core.dll</HintPath>
      <Private>false</Private>
    </Reference>
    <Reference Include="Sandbox.Common">
      <HintPath>C:\Program Files (x86)\Steam\steamapps\common\SpaceEngineers\Bin64\Sandbox.Common.dll</HintPath>
      <Private>false</Private>
    </Reference>
    <Reference Include="Sandbox.Game">
      <HintPath>C:\Program Files (x86)\Steam\steamapps\common\SpaceEngineers\Bin64\Sandbox.Game.dll</HintPath>
      <Private>false</Private>
    </Reference>
    <Reference Include="Sandbox.Graphics">
      <HintPath>C:\Program Files (x86)\Steam\steamapps\common\SpaceEngineers\Bin64\Sandbox.Graphics.dll</HintPath>
      <Private>false</Private>
    </Reference>
    <Reference Include="SpaceEngineers.Game">
      <HintPath>C:\Program Files (x86)\Steam\steamapps\common\SpaceEngineers\Bin64\SpaceEngineers.Game.dll</HintPath>
      <Private>false</Private>
    </Reference>
    <Reference Include="SpaceEngineers.ObjectBuilders">
      <HintPath>C:\Program Files (x86)\Steam\steamapps\common\SpaceEngineers\Bin64\SpaceEngineers.ObjectBuilders.dll</HintPath>
      <Private>false</Private>
    </Reference>
    <Reference Include="VRage">
      <HintPath>C:\Program Files (x86)\Steam\steamapps\common\SpaceEngineers\Bin64\VRage.dll</HintPath>
      <Private>false</Private>
    </Reference>
    <Reference Include="VRage.Game">
      <HintPath>C:\Program Files (x86)\Steam\steamapps\common\SpaceEngineers\Bin64\VRage.Game.dll</HintPath>
      <Private>false</Private>
    </Reference>
    <Reference Include="VRage.Input">
      <HintPath>C:\Program Files (x86)\Steam\steamapps\common\SpaceEngineers\Bin64\VRage.Input.dll</HintPath>
      <Private>false</Private>
    </Reference>
    <Reference Include="VRage.Library">
      <HintPath>C:\Program Files (x86)\Steam\steamapps\common\SpaceEngineers\Bin64\VRage.Library.dll</HintPath>
      <Private>false</Private>
    </Reference>
    <Reference Include="VRage.Math">
      <HintPath>C:\Program Files (x86)\Steam\steamapps\common\SpaceEngineers\Bin64\VRage.Math.dll</HintPath>
      <Private>false</Private>
    </Reference>
    <Reference Include="VRage.Render">
      <HintPath>C:\Program Files (x86)\Steam\steamapps\common\SpaceEngineers\Bin64\VRage.Render.dll</HintPath>
      <Private>false</Private>
    </Reference>
    <Reference Include="System.Collections.Immutable">
      <HintPath>C:\Program Files (x86)\Steam\steamapps\common\SpaceEngineers\Bin64\System.Collections.Immutable.dll</HintPath>
      <Private>false</Private>
    </Reference>
  </ItemGroup>

</Project>

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).


(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.

Where to from here