godotengine / godot-proposals

Godot Improvement Proposals (GIPs)
MIT License
1.12k stars 69 forks source link

Allow custom properties to be passed to msbuild on project export. #9119

Open FreshDaikon opened 6 months ago

FreshDaikon commented 6 months ago

Describe the project you are working on

A multiplayer game with several export templates.

Describe the problem or limitation you are having in your project

When dealing with several exports using C# / msbuild, it became apparent that simply setting features isn't quite sufficient in my use case.

So, to make a concrete example, let's take a structure like this :

Main Project Folder

Client

Client.csproj

Game

Game.csproj

Server

Server.csproj

project.godot project.csproj project.sln

Currently, when rebuilding the project or exporting (using Godot, not msbuild directly) - everything will be napped up and compiled into a single project.dll. For obvious reasons, any excluded files in the export template wont be considered if they are part of the .sln (i.e .cs files) as msbuild will make this single .dll before packing the rest of the project.

I've considered different ways to get around this problem, but it always ends up being either complicated setups using submodules with git or separating the project into several distinct projects. In both cases it complicates the rather simple structure above and introduces unnecessary points of potential failure.

I will admit though, that even as i've scoured the internet for solutions, that I am not very knowledgeable about build processes in general so it might be that there exists solutions that I am just unaware of.

Describe the feature / enhancement and how it helps to overcome the problem or limitation

So, when building our project with msbuild, we can pass all kinds of properties and configurations. These can be whatever you want basically, and you can react to them in your .csproj files to configure your build task to be whatever you want them to be.

This makes it possible to set up our main .csproj to include/exclude parts of the project at the build stage (ether using constants or properties or any combination thereof) based on these custom properties.

And as expected it all works as long as you stay in the terminal doing commands like : dotnet build /p:SERVERBUILD=true for example.

The problem is that I can't (to the best of my knowledge) get Godot to pass any properties or custom constants to msbuild when building the C# solution on export.

As such, I suggest we add a way to pass these custom properties to msbuild when exporting godot projects.

Describe how your proposal will work, with code, pseudo-code, mock-ups, and/or diagrams

This might be a bit naive, but simply add a (perhaps behind a "advanced" checkbox) field in the export template to specify msbuild properties to be passed to msbuild on export?

So, per export template we could define custom properties to either manipulate the build process or to define constants for #if CUSTOMCONSTANT #endif statements in the C# code.

If this enhancement will not be used often, can it be worked around with a few lines of script?

Again, I am no expert, and so there might be ways to workaround this without resorting to multiple projects. But as far as i know, this isn't currently possible.

Is there a reason why this should be core and not an add-on in the asset library?

This is about improving project export templates out of the box.

raulsntos commented 6 months ago
FreshDaikon commented 6 months ago

@raulsntos Yeah, that's pretty much exactly what i'm talking about! Didn't find it in my googling. And interesting that feature tags used to be readable in csproj...

Out of curiosity, is there any harm in doing a godot export for say, 3-5 different templates, then going back and doing it all in msbuild again, and then replace the .dll's in the output folders ? Do they differ in any meaningful way?