高级模组设置
阅读
2023-11-30更新
最新编辑:Lu_23333
阅读:
更新日期:2023-11-30
最新编辑:Lu_23333
This guide is for setting up your workspace in Visual Studio.
If you prefer using something else the steps should be similar but you'll have to figure out the exact steps on your own.
If you're new to modding it's recommended to just follow these steps and setup your workspace with VS.
Installation
If you haven't installed Visual Studio yet you should download it and install it.
You can download Visual Studio Community for free.
Create the project
The next step after installing VS is to create a solution and project for your mod.
- Start Visual Studio
- Click File ‣ New ‣ Project… or press
Ctrl+Shift+N
- Select the Class Library template for the C# language.
- Enter a name for your project (should be your mod name)
- Save the project in any location you like but you should avoid putting it in the mods folder.
Adding references
The next step is to add references to assemblies you wish to use. This is done so that you can use the code and that your code can be compiled.
- Right-click References within your project in the Solution Explorer and choose Add ‣ Reference…
- Click the Browse… button at the bottom of the dialog
- Navigate to
<%STEAM%>\SteamApps\common\Cities_Skylines\Cities_Data\Managed
- Select the assemblies you want to use (recommended: ICities, UnityEngine, UnityEngine.UI, ColossalManaged, Assembly-CSharp)
Automate
At this point you should be able to already create mods but there is one more important step to improve the workflow.
Right now when you compile your mod the DLL will be placed in your workspace folder where you created the project.
We can automatically copy this file to the mods folder when compilation has completed.
- Right-click your project in the solution explorer and choose Properties or press
ALT+ENTER
- Select Build events in the left panel
- Paste the command(s) below in the Post-build event and save.
CTRL+S
mkdir "%LOCALAPPDATA%\Colossal Order\Cities_Skylines\Addons\Mods\$(SolutionName)" del "%LOCALAPPDATA%\Colossal Order\Cities_Skylines\Addons\Mods\$(SolutionName)\$(TargetFileName)" xcopy /y "$(TargetPath)" "%LOCALAPPDATA%\Colossal Order\Cities_Skylines\Addons\Mods\$(SolutionName)"
Automatic reloading
To make the game reload your mod while running, change the last two lines in AssemblyInfo.cs
. (located under properties in your project)
[assembly: AssemblyVersion("1.0.*")] //[assembly: AssemblyFileVersion("1.0.0.0")]
By changing this the version of the assembly will be different each time you compile your mod.
CS will then automatically reload your mod and you don't have to reboot the game if you make a change to the mod.
In newer project version Visual Studio could complain once you make the change. The error message in this case is: "The specified version string contains wildcards, which are not compatible with determinism. Either remove wildcards from the version string, or disable determinism for this compilation" If you don't care about deterministic builds you can turn it off by editing the .csproj file of your project.
<PropertyGroup> ... <Deterministic>false</Deterministic> // <!-- set this to false --> ... </PropertyGroup>
Compile
To compile your mod you can simply press CTRL+SHIFT+B
and it should successfully compile and copy the DLL to the mods folder.
See the output log on the bottom to make sure everything worked.
Next step: Modding Basics