Difference between revisions of "Modding Tutorials/Setting up a solution"

From RimWorld Wiki
Jump to navigation Jump to search
m (→‎Sharpdevelop: Warning on use)
Line 52: Line 52:
  
 
===Sharpdevelop===
 
===Sharpdevelop===
Sharpdevelop (or #develop) does NOT CURRENTLY allow for C# 6.0+ syntax without plugins and does NOT ALLOW for C# 7.0+ syntax at all. For your average project this does not matter, however some existing projects are already built entirely upon C# 6.0+ syntax which can not be compiled anymore in Sharpdevelop. Visual Studio does not have these issues and should be your go-to for compiling large projects such as Combat Extended.
+
'''Caution:''' Sharpdevelop (or #develop) does NOT CURRENTLY allow for C# 6.0+ syntax without plugins and does NOT ALLOW for C# 7.0+ syntax at all. For your average project this does not matter, however some existing projects are already built entirely upon C# 6.0+ syntax which can not be compiled anymore in Sharpdevelop. Visual Studio does not have these issues and should be your go-to for compiling large projects such as Combat Extended.
  
 
# Create a new class library project in your [[Modding Tutorials/Recommended software#IDE.27s|IDE of choice]];
 
# Create a new class library project in your [[Modding Tutorials/Recommended software#IDE.27s|IDE of choice]];

Revision as of 21:18, 4 June 2018

Modding Tutorials

This page was originally created by Alistaire.

In this tutorial you will learn how to set up a solution, along with instructions on setting the output directory and files for more convenient building right into the Assemblies folder.

Requirements

Setting up a solution

Setting up can be different for different IDE's. Feel free to add complete instructions for your IDE of choice.

Visual Studio Community 2017

NOTE: Visual Studio 2017 is a rather heavy application (2-3 GB for basic functionality) but has a bit more functionality. Only Install if your computer can handle it! The tutorial is similar for Visual Studio 2015.


Option 1 (Manual Method):

  1. Create a new class library project
    1. Once loaded, go to File -> New -> Project...
    2. Go to Templates -> Visual C# -> Class Library (Be sure to select the *.NET Framework* version, not *.NET Standard*)
      Installing the .NET framework
    3. Enter your name and solution name in the lower pane.
    4. Choose a location, preferably:
      (RimWorldInstallFolder)/Mods/(YourModName)/Source
    5. Optional: Untick "Create directory for solution"
  2. In your project, set target framework and various other porperties
    1. In your Solution Explorer, right click your project -> Properties
    2. Once in your properties, select Application -> Set Target Framework to .NET Framework 3.5 (No client profile)
    3. Optional: Change your Assembly and Namespace names to anything of your choice
    4. Go to Build -> Advanced... and set "Debugging information" to none
    5. Leave Advanced..., and set the Output Path to "..\..\Assemblies\" (The Assemblies folder in your mod folder)
  3. Add references to RimWorld code
    1. Expand your project. Then right click "References" -> Add Reference...
    2. Click Browse...
    3. Navigate towards
      RimWorld******/RimWorld******_Data/Managed
      and select files:
      Assembly-CSharp.dll
      UnityEngine.dll
    4. Click "Add"
    5. Right click on both Assembly-CSharp.dll and UnityEngine.dll and set Copy Local to False (Properties pane).

Option 2 (Automatic Method):

  1. Open Visual Studio
  2. Once loaded, go to File -> New -> From Cookiecutter...
  3. Search for rimworld
  4. Double-click cookiecutter-rimworld-mod-development
  5. Change the Template Options:
    1. Create To => Your/Rimworld/Mod/Directory
    2. mod_name
    3. namespace_name (don't change if unsure)
    4. author => your steam username
    5. target_version => current RW version (can leave blank for most up-to-date)
    6. in_game_description (not required, can change later in About-Release.xml)
    7. url (can leave blank for link to your Steam Workshop profile)
  6. Click "Create and Open Folder"

Sharpdevelop

Caution: Sharpdevelop (or #develop) does NOT CURRENTLY allow for C# 6.0+ syntax without plugins and does NOT ALLOW for C# 7.0+ syntax at all. For your average project this does not matter, however some existing projects are already built entirely upon C# 6.0+ syntax which can not be compiled anymore in Sharpdevelop. Visual Studio does not have these issues and should be your go-to for compiling large projects such as Combat Extended.

  1. Create a new class library project in your IDE of choice;
    1. Go to File -> New -> Solution;
    2. Go to C# or .NET -> Library or Class Library (NOT portable);
    3. Enter a project name (solution name automatically updated);
    4. Choose a location, preferably:
      (RimWorldInstallFolder)/Mods/(YourModName)/Source
    5. Optional: Untick "Create a directory for solution"/"Create a project within the solution directory",
  2. In your project, add references to Assembly-CSharp.dll and UnityEngine.dll:
    1. In your IDE project file browser, right-click the "References" folder and "Add reference";
    2. Choose the ".NET Assembly Browser" tab and "Browse...";
    3. Navigate towards
      RimWorld******/RimWorld******_Data/Managed
      and select files:
      Assembly-CSharp.dll
      UnityEngine.dll
    4. Click "Open" then "OK";
    5. In the References folder, right-click Assembly-CSharp -> Properties and change "Local copy" to False. Do the same for UnityEngine,
  3. In your project properties, change the target framework to .NET 3.5:
    1. In your IDE project file browser, right-click "(YourSolutionName)";
    2. Choose Properties;
    3. Go to the "Compiling" tab, "Output", "Target framework", "Change" and choose ".NET Framework 3.5",
  4. In your project properties, change the build events so only a single file is built:
    1. Go to the "Compiling" tab, "Output", "Debug info" and choose "No debug information";
    2. Right-click your .cs files -> Properties and change "Copy to output" (If you haven't resized the properties bar, this will be truncated to "Copy to out") to Never,
  5. In your project properties, fix the output location to put the DLL in the Assemblies folder:
    1. Go to the "Compiling" tab, "Output", "Output path" and change the output path to "..\..\Assemblies\".

Xamarin

The setup is similar as the one above. A few special points to address:

  1. Mono 4.X isn't backward compatible so you may need to install an older 3.X version of Mono in order to compile against .NET3.5 dlls.
  2. Make sure you uncheck "Use MSBuild build engine (recommended for this project type)" under project > options > build > general


macOS

There is no best practice for modding on a Mac since Xamarin is not backwards compatible with .Net3.5. That said, there is a very practical way around this by virtualizing Visual Studio and ILSpy on macOS with VirtualBox. This approach allows the use of macOS or Windows development tools, but relies on Visual Studio for compilation.

  1. Mac Modding HowTo
  2. Follow the above steps for Visual Studio

See also