Multiple independent dll Exports (C#)

Godot Version

4.2

Question

Hey,

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
Server
Etc.

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?

Thanks!

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 :

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

In your code :

#if SOMECUSTOMDEFINE
GD.Print("this build defined SOMECUSTOMDEFINE ");
#endif

MSbuild :

dotnet build /p:SOMECUSTOMDEFINE=1