Zlepper.RimWorld.ModSdk 0.0.9

<Sdk Name="Zlepper.RimWorld.ModSdk" Version="0.0.9" />                
For projects that support Sdk, copy this XML node into the project file to reference the package.

RimWorld ModSdk

This is a dotnet sdk that allows you to create mods for RimWorld with less messing with configurations.

Features

  • Provides support for C# 11 (At least the features .NetFramework can support).
  • Allows multiple RimWorld versions to be supported at the same time.
  • Automatically references RimWorld assemblies.
  • Easily reference other Steam mods for your mod.
    • Harmony and HugsLib have special support, to make them even easier to reference.
    • Other local mods for development can are automatically referenced in an msbuild <ProjectReference> is created.
  • Automatically copies the mod to the RimWorld mods folder.
  • Support for Rider + Visual Studio run buttons without additional configuration.
    • Debugging is not yet magically supported and does require additional manual configuration.
  • Implicit usings for RimWorld, Verse, System, System.Collections.Generic and System.Linq.
  • Fully automatically generated About.xml file.
  • The PublishedFileId.txt is automatically copied back into the project when the mod is build if the mod has been published to Steam.
  • Intellisense in Def files, both for Def classes defined by dependencies and custom classes directly in your mod.

Installation

A word of warning: I develop on Windows and have only tested this on Windows. Thanks to @amevarashi this should also be working on Linux now. If you are using Mac and want to help getting this working on Mac, please let me know and make either an issue or a PR.

  1. Make sure you have at least a DotNet 7 SDK installed: https://dotnet.microsoft.com/en-us/download
  2. Open your IDE and create a new project, the specific project type does not matter, but I recommend a class library.
  3. Open the .csproj file and replace the content with the following:
<Project Sdk="Zlepper.RimWorld.ModSdk/0.0.9">

    <PropertyGroup>
        <RimWorldModName>Your mod name</RimWorldModName>
        <RimWorldPackageId>Your.Mod.PackageId</RimWorldPackageId>
        <Authors>Your Name</Authors>
        <Description>
          This is a good description.
          
          It can even be multiline.
        </Description>
    </PropertyGroup>

</Project>
  1. Create a new class and add the following code:
namespace MyName.MyFancyMod;

[StaticConstructorOnStartup]
public static class MyMod
{
    static MyMod()
    {
        Log.Message("Hello World from MyMod!");
    }
}
  1. If you get compile errors at this point, the SDK might not be able to locate your RimWorld installation, please see the "Optional configuration" section and try setting <RimWorldPath> to the path to your RimWorld installation.
  2. Run the project and wait for RimWorld to load.
  3. Go into mod settings and enable your mod.
  4. Check the RimWorld dev tools for a message from your mod.
  5. Now, go and implement your mod! (Tip: Read the Tips and Tricks section)

Tip and tricks

  • You don't need maintain your own structure for your mod, you can just add files to your project and they will be copied to the mod folder for your current RimWorld version. For example: Add a Defs folder with a ThingDefs folder inside and add a MyThingDef.xml file to it. It will be copied to the mod folder.
    • This also works for all the other "standard" folders RimWorld has: About, Defs, Languages, Textures, Sounds and Patches. The "Assemblies" folder is generated automatically your assemblies when you build your project.
  • You can start Rimworld with a specific settings, mod list and saves by using the StartArguments property. For example, you can have a separate settings and mod lists for each solution by adding this to the PropertyGroup
    <StartArguments>"-savedatafolder=$(SolutionDir)/savedatafolder"</StartArguments>
    

Configuration

The SDK contains several settings that can be configured in the .csproj file. Some of these are required to be set, while others are optional.

Required configuration:

<PropertyGroup>
  
  <RimWorldModName>My Mod Name</RimWorldModName>
  
  <RimWorldPackageId>My.Mod</RimWorldPackageId>
  
  
  
  <Authors>My Name</Authors>

  

  <Description>
    This is a good description.

    It can even be multiline.
  </Description>
</PropertyGroup>

Optional configuration:

This shows the default values each parameter have, so if you are happy with those values, no need to tweak them.

<PropertyGroup>
  
  <Nullable>enable</Nullable>
  
  
  
  <LangVersion>10</LangVersion>
  
  
  <IncludeHugsLib>false</IncludeHugsLib>
  
  
  <IncludeHarmony>false</IncludeHarmony>
  
  
  <OutputFolder>../Mods</OutputFolder>
  
  
  <RimWorldImplicitUsings>enable</RimWorldImplicitUsings>
  
  
  
  <RimWorldPath>C:\Program Files (x86)\Steam\steamapps\common\RimWorld</RimWorldPath>
  
  
  
  <RimWorldVersion>(infered based on your installation)</RimWorldVersion>
  
  
  <RimWorldModUrl></RimWorldModUrl>
  
</PropertyGroup>

Adding a reference to another mod

The sdk makes it very easy to reference and use other mods in your mod. For example, if you want to reference the VanillaExpanded framework, you can do this:

<ItemGroup>
  <RimWorldSteamModDependency Include="OskarPotocki.VanillaFactionsExpanded.Core" />
</ItemGroup>

This will add a reference to the mod in the About.xml file, and also add a reference to the mod's assembly in your project. You can then use the mod's API in your mod.

This does require that you actually subscribe to the mod in Steam, and it has been downloaded. If you don't have the mod installed, you will get a compile error.

Controlling mod loading order

The following project item tags are available to control mod loading order if you don't have an explicit dependency to the given mod:

<ItemGroup>
  <RimWorldLoadBefore Include="Some.Mod" />
  <RimWorldLoadAfter Include="Some.Mod" />
  <RimWorldIncompatibleWith Include="Some.Mod" />
</ItemGroup>

These tags works like their counterparts in the About.xml file, and will be added to the About.xml file when you build your project.

If you already reference the mod using <RimWorldSteamModDependency>, then you do not need to add <RimWorldLoadAfter>, that is done automatically.

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
0.0.9 176 11/2/2023
0.0.8 126 11/2/2023
0.0.7 206 4/9/2023
0.0.6 331 11/12/2022
0.0.5 394 10/15/2022
0.0.4 390 10/15/2022
0.0.3 398 9/16/2022
0.0.2 388 9/16/2022
0.0.1 408 9/16/2022