全站通知:

高级模组设置

阅读

    

2023-11-30更新

    

最新编辑:Lu_23333

阅读:

  

更新日期:2023-11-30

  

最新编辑:Lu_23333

来自城市:天际线WIKI_BWIKI_哔哩哔哩
跳到导航 跳到搜索
页面贡献者 :
xl123071
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.

  1. Start Visual Studio
  2. Click File ‣ New ‣ Project… or press Ctrl+Shift+N
  3. Select the Class Library template for the C# language.
  4. Enter a name for your project (should be your mod name)
  5. 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.

  1. Right-click References within your project in the Solution Explorer and choose Add ‣ Reference…
  2. Click the Browse… button at the bottom of the dialog
  3. Navigate to <%STEAM%>\SteamApps\common\Cities_Skylines\Cities_Data\Managed
  4. 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.

  1. Right-click your project in the solution explorer and choose Properties or press ALT+ENTER
  2. Select Build events in the left panel
  3. 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

See also

说明

本文内容长期有效,适用任何游戏版本。

本页内容最初译自官方Wiki:Advanced Mod Setup,经双方编辑后内容可能与来源不同。