Home
Blog

Multiple C# Projects with Godot

Assumptions

Excluding Folders to be Compiled from the Main Project

Add this code into your .csproj file in the root of your project, changing path\to\folder to the folder with external code. Do not remove the \**.

<ItemGroup>
  <Compile Remove="path\to\folder\**" />
</ItemGroup>

The end result should look similar to this.

Please note that this uses Godot 4.1.3 and .NET 6.0, and is a new project.

<Project Sdk="Godot.NET.Sdk/4.1.3">

  <PropertyGroup>
    <TargetFramework>net6.0</TargetFramework>
    <EnableDynamicLoading>true</EnableDynamicLoading>
  </PropertyGroup>

  <ItemGroup>
    <Compile Remove="path\to\folder\**" />
  </ItemGroup>

</Project>

Creating new Projects

In most cases, adding a project via dotnet new will work fine.

Some cases, you might want references to the Godot API, in which case you need to create a new .csproj manually like so.

Here is an example for .NET 6.0 and Godot 4.1.3

<Project Sdk="Godot.NET.Sdk/4.1.3">

  <PropertyGroup>
    <TargetFramework>net6.0</TargetFramework>
    <EnableDynamicLoading>true</EnableDynamicLoading>
  </PropertyGroup>

</Project>

Adding Sub-Projects to the Main Project and .sln

Use dotnet add reference <path/to/.csproj> in the root of your project to add a subproject to the main project.

Use dotnet sln add <path/to/.csproj> in the root of your project to add a subproject to the .sln.

Adding .dll references to the Main Project

If you have a .NET compatible .dll in your project, you will need to edit the .csproj manually.

Example code, where the .dll is located in a folder called foo and the file is named bar.dll

<Reference Include="bar">
  <HintPath>foo\bar.dll</HintPath>
</Reference>

Conclusion

Hope this helps someone out there. If you have any questions feel free to ask on my Discord Server, X.com/Twitter, Mastodon.