Multiple independent dll Exports (C#)

Godot Version




So, I was wondering about any good techniques for having multiple distinct builds/dll artifacts being build from one project - and here I don’t mean Export Templates, let me explain.

So, in my current test setup, i have something like this:
Project/sln >
→ Game /csproj
→ Server /csproj
→ Client /csproj

Server, Client and Game all contain their own project in their own namespace. Additionally, Game holds all of the “godot” “game” stuff (scenes, data, assets etc.)

The project is setup in such a way that depending on various command line arguments, i load up my desired version of some composite scene(s) this could be:
Game with Client
Game with Server

This all works nicely and independently - the -problem- arises at Export. There are ways to create templates for all of these setups ofc (Server/Client etc.) And exclude folders and files depending on the template - But when Godot builds the .sln it just takes the whole codebase (ofc) and compiles into a set of project.dll files.

Now, this creates a situation where Server or Client code is included in binaries that don’t need them, or straight up should not contain it.

Now, I’ve looked into various methods of trying to separate this more cleanly, but it seems that outside of making x number of independent Godot Projects (which would be kinda meh, as i don’ want to maintain a duplicate Game in both Server and Client for example) I’m kind of out of luck?

So, does anyone have some nice techniques for dealing with this, or some insight into maybe what could be done instead?


Edit: got the .csproj and .sln confused (it’s early here haha)

After looking a bit more around on the internet it seems we can use C# Preprocessors to skip code during compilation.

I wonder then, when exporting from Godot those defines will not have been set, is there a way to specify the dotnet build arguments in the export presets somehow?

Or should I export from Godot, then use MSbuild and replace the DLL’s manually? Is there an easier way perhaps?

The awkward solution for anyone interested looks like this:

In .csproj :

    <DefineConstants Condition="'$(SOMECUSTOMDEFINE)'=='1'">$(DefineConstants);SOMECUSTOMDEFINE</DefineConstants>   

In your code :

GD.Print("this build defined SOMECUSTOMDEFINE ");

MSbuild :

dotnet build /p:SOMECUSTOMDEFINE=1

Have you ever found a solution to this?
I’m also in a similar situation: Client, Server, Game (trying to really separate the network part from the Game, as it becomes quite confusing).

Would like to make a Library (dll) with the Network things (which classes inherit from Godot Node) and consume within the Game Godot C# project.
Is this something impossible to do? I tried manually creating a Library Project in Visual Studio, but adding manually the Nuget packages gives duplication error, so instead, I set the in .csproj, nugets are added automatically, but I have an error because of duplicated Analizers within the dependencies (I see the extra garbage in the dependencies, but they cannot be removed; it seems the “Library” type of project automatically add them.

Such a simple feature, yet it seems nobody thought about it.