Modding Tutorials/Plague Gun (old)/Csharp Assembly Setup

From RimWorld Wiki
Jump to navigation Jump to search

This tutorial was originally written by Jecrell. Thread.

Setting up the C# Assembly[edit]

  1. Open your compiler of choice for C#.
    • I use Visual Studio Community edition, a free Windows-based compiler for C# code.
    • This part of the tutorial will assume you will use the same.
  2. Make a new Visual C# Class Library .NET Framework project. Name it PlagueGun. Make its directory RimWorld>Mods>PlagueGun>Source
    • File => New => Project => Class Library (.NET Framework).
    • Don't get this confused with "Class Library (.NET Standard)"!
  3. Go into the project properties.
    • Project => PlagueGun Properties.
  4. In the Application tab, Make sure the assembly names and namespace match your XML assembly name.
    • Earlier we used Plague.ThingDef_PlagueBullet. Plague should be our assembly namespace and assembly name.
  5. In that same window, change the Target Framework version to .NET Framework 4.7.2
    • Forgetting to do this will cause lots of errors.
    • Select Yes when it asks you if you're sure to change the framework.
  6. Go to the Build tab in the project properties.
  7. Change the output path to be RimWorld\Mods\PlagueGun\Assemblies
    • All .dll files will go into this directory when we "build" our code library.
  8. In that same window, click the Advanced... button.
  9. Change Debugging information to none.
    • This prevents a simple error that occurs when RimWorld doesn't know what to do with the debug .pdb files.
  10. In Solution Explorer. Go into Properties and edit AssemblyInfo.cs. Change the name of your assembly and assembly file version number as you like.
    • This doesn't have to all be the same as your namespace, but it doesn't hurt to be consistent.
  11. In the main option bar at the top of the visual studio (File, Edit, View...), click Project, and click Add Reference.
  12. Click Browse and go to RimWorld\RimWorldWin_Data\Managed
  13. Add references to Assembly-CSharp.dll and UnityEngine.dll
  14. In the Solution Explorer (typically on the right side of the application), look at the references drop down list.
  15. Select Assembly-CSharp. Check the Properties section (usually under Solution Explorer). Make sure the properties section has Copy Local set to FALSE.
  16. Do this (Copy Local to FALSE) for UnityEngine as well.
    • By doing this, we prevent the project from causing one million hash conflicts by copying the entire game's code twice!
  17. Go into the References; Delete the yellow triangle references, and click the Build button and Build Solution.
    • If there are errors, be sure to delete unused References and delete lines for #using that aren't in use like #using System.Threading.Tasks

Now the workspace setup is complete and we can add C# code to RimWorld.

Editors note: Exact folder names might differ between installs. The naming scheme differs slightly between the DRM-free and Steam version of the mod.

See also[edit]

  1. Required Items
  2. XML Stage
  3. Connecting XML and C#
  4. C# Assembly Setup <- You are here.
  5. C# Coding
  6. Localisation

More in-depth[edit]