Difference between revisions of "Modding Tutorials/Setting up a solution"
Line 82: | Line 82: | ||
− | ===Rider (good for | + | ===Rider (good for Mac)=== |
JetBrains Rider is a great cross-platform C# IDE, but it isn't cheap. It's $140 for the first year, including perpetual access to that version (access to future updates gets cheaper, but it's still over $100/year). However, the Early Access versions are a bit unstable but free. They also offer free student licenses. | JetBrains Rider is a great cross-platform C# IDE, but it isn't cheap. It's $140 for the first year, including perpetual access to that version (access to future updates gets cheaper, but it's still over $100/year). However, the Early Access versions are a bit unstable but free. They also offer free student licenses. | ||
Revision as of 23:47, 7 July 2018
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
- The manual option in this tutorial requires you to have set up a Source and Assemblies folder (the Visual Studio automatic option sets this up for you).
- You will want to have an IDE installed: Recommended IDE's.
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):
- Create a new class library project
- Once loaded, go to File -> New -> Project...
- Go to Templates -> Visual C# -> Class Library (Be sure to select the *.NET Framework* version, not *.NET Standard*)
- Enter your name and solution name in the lower pane.
- Choose a location, preferably:
(RimWorldInstallFolder)/Mods/(YourModName)/Source
- Optional: Untick "Create directory for solution"
- In your project, set target framework and various other porperties
- In your Solution Explorer, right click your project -> Properties
- Once in your properties, select Application -> Set Target Framework to .NET Framework 3.5 (No client profile)
- Optional: Change your Assembly and Namespace names to anything of your choice
- Go to Build -> Advanced... and set "Debugging information" to none
- Leave Advanced..., and set the Output Path to "..\..\Assemblies\" (The Assemblies folder in your mod folder)
- Add references to RimWorld code
- Expand your project. Then right click "References" -> Add Reference...
- Click Browse...
- Navigate towards
RimWorld******/RimWorld******_Data/Managed
and select files:Assembly-CSharp.dll UnityEngine.dll
- Click "Add"
- Right click on both Assembly-CSharp.dll and UnityEngine.dll and set Copy Local to False (Properties pane).
Option 2 (Automatic Method):
- Open Visual Studio
- Once loaded, go to File -> New -> From Cookiecutter...
- Search for rimworld
- Double-click cookiecutter-rimworld-mod-development
- Change the Template Options:
- Create To => Your/Rimworld/Mod/Directory
- mod_name
- namespace_name (don't change if unsure)
- author => your steam username
- target_version => current RW version (can leave blank for most up-to-date)
- in_game_description (not required, can change later in About-Release.xml)
- url (can leave blank for link to your Steam Workshop profile)
- 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.
- Create a new class library project in your IDE of choice;
- Go to File -> New -> Solution;
- Go to C# or .NET -> Library or Class Library (NOT portable);
- Enter a project name (solution name automatically updated);
- Choose a location, preferably:
(RimWorldInstallFolder)/Mods/(YourModName)/Source
- Optional: Untick "Create a directory for solution"/"Create a project within the solution directory",
- In your project, add references to Assembly-CSharp.dll and UnityEngine.dll:
- In your IDE project file browser, right-click the "References" folder and "Add reference";
- Choose the ".NET Assembly Browser" tab and "Browse...";
- Navigate towards
RimWorld******/RimWorld******_Data/Managed
and select files:Assembly-CSharp.dll UnityEngine.dll
- Click "Open" then "OK";
- In the References folder, right-click Assembly-CSharp -> Properties and change "Local copy" to False. Do the same for UnityEngine,
- In your project properties, change the target framework to .NET 3.5:
- In your IDE project file browser, right-click "(YourSolutionName)";
- Choose Properties;
- Go to the "Compiling" tab, "Output", "Target framework", "Change" and choose ".NET Framework 3.5",
- In your project properties, change the build events so only a single file is built:
- Go to the "Compiling" tab, "Output", "Debug info" and choose "No debug information";
- 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,
- In your project properties, fix the output location to put the DLL in the Assemblies folder:
- Go to the "Compiling" tab, "Output", "Output path" and change the output path to "..\..\Assemblies\".
- 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:
- 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.
- Make sure you uncheck "Use MSBuild build engine (recommended for this project type)" under project > options > build > general
Rider (good for Mac)
JetBrains Rider is a great cross-platform C# IDE, but it isn't cheap. It's $140 for the first year, including perpetual access to that version (access to future updates gets cheaper, but it's still over $100/year). However, the Early Access versions are a bit unstable but free. They also offer free student licenses.
- Open Rider and click New Solution in the welcome dialog.
- Click Class Library under .NET on the left. The option may a second to show up.
- Under Solution Name (and Project Name), enter the name of your mod.
- Set the Solution Directory to [your mod folder]/Source.
- Optionally check "put solution and project in the same directory." This is probably a good idea.
- Change Framework to .Net Framework 3.5.
- Click Create.
- In the left side bar, expand your solution, right click your project (mod name with "C#" icon) and click Properties.
- In the Properties window, select Configurations > Debug on the left and uncheck Debug Symbols.
- For both configurations, change the Output Path to ../../Assemblies.
- Click OK.
- Expand your project, right click References and click Add Reference.
- Click Add From.
- Browse to the folder with the RimWorld DLLs (Mac: /Users/[username]/Library/Application Support/Steam/steamapps/common/RimWorld/RimWorldMac.app/Contents/Resources/Data/Managed).
- Select both Assembly-CSharp.dll and UnityEngine.dll and click OK.
- Expand Assemblies under References. For both of the assemblies that you just added:
- Right click the assembly and click Properties.
- Uncheck "Copy Local" (you may need to scroll down) and click OK.
You're done! Note that Rider has a built-in decompiler—to view the source of a RimWorld class or method, just right-click its name and click Go To > Definition.
See also
- Writing custom code continues on setting up your solution.