r/csharp • u/sH-Tiiger • Feb 19 '26
C# really needs a better build system than MSBuild
Hi!
I've lately been working on building a little game framework/engine in C#, and it's been great! C# is definitely not my main language, but I've really been liking it so far. The only thing I've found is that MSBuild really, really frustrates me. I'm used to the likes of Gradle, CMake, even Cargo, and MSBuild just feels handicapped in so many places.
A part of writing a game engine is of course making some kind of asset packing pipeline. You need to compile shaders, etc. My simple wish has been to just make this happen automatically at compile time, which honestly has been a nightmare:
- NuGet and local package references act completely different.
.targetsfiles aren't automatically included for local references, but are for NuGet packages. And basically all file paths are different, so you basically need to write all your build logic twice. - I like to split up my projects into multiple subprojects (e.g. Engine.Audio, Engine.Graphics, etc.). Again, for local package references, you can't reference another
.slnfile, so you have to mention every single csproj if you want to use it from another solution. God forbid something "internal" changes in my libary, and a new project is split out. - The asset packer is another C# project with a CLI. This requires me to reference the assembly EXE/DLL from the
.targetsfile. But the assembly file is in a different place depending on configuration, runtime identifier, etc. And for runtime identifiers, there's not even a built-in variable I can use to resolve that! - It's impossible to use different configurations in a NuGet package. For example, I can depend on the asset packer at runtime, to hot-reload assets. For my local project, I use an
#if DEBUGmacro for that to disable it for publishing. But when publishing a package to NuGet, you can only publish a single configuration, so it's impossible to build this into the framework. - The documentation for MSBuild is good! But there are no indicators if you did something wrong. It's completely valid to set any property, even if it doesn't exist, and you get no feedback on if something is wrong.
- There's more things, but I think my stance is clear by now.
There's build systems like Cake or NUKE, but they're more Makefile replacements, and are not really that useful if I'm building a library. Also, they are still built around MSBuild, and thus inherit a lot of the problems.
I'm suprised this isn't brought up more. Even on this subreddit, people are just.. fine with MSBuild. Which is fair, it honestly works for a lot of applications. But it's really frustrating that as soon as you try to do anything more complex with it, it just spectacularly falls apart.
79
u/Alikont Feb 19 '26
All your requests are perfactly achievable with MSBuild, but also are quite niche and weird to the point that every build system will be a hassle.
There is Shapmake that might cover your game needs, as it's made by Ubisoft. But it's still MSBuild generator under the hood.
117
u/polaarbear Feb 19 '26
"MSBuild sucks"
Cites freaking Gradle of all things as inspiration. This does not compute.
3
u/sH-Tiiger Feb 20 '26 edited Feb 20 '26
This thread already got way out of hand. People seem to be taking this way to seriously, when it's just some genuine criticism from someone who is kind of new to this language / ecosystem in general.
That being said, I'm genuinely so confused by some of the answers here:
I'm not trying to use MSBuild for something it isn't meant for, this is functionality that literally already exists. Unfortunately, yes, I have to deal with assemblies and raw DLLs, that's how MSBuild's API is designed.
That's all, I got what I came for I guess, thank you!
55
u/lynohd Feb 19 '26
Gradle is the worst thing on this planet cant stand dealing with it lol
72
u/r2d2rigo Feb 19 '26
I'll take csproj files and MSBuild any day over the unholy madness that CMake is. I shouldn't be learning a whole new Turing-complete scripting language just so I know how to build my projects.
17
u/raunchyfartbomb Feb 19 '26 edited Feb 19 '26
You can craft your project files and use .targets and .props files to define your builds and share that between projects using the <import project> tag.
If you want to change output folders, you have to do so before importing the sdk. I have some projects where I use this to redirect output folders and obj folders to avoid collisions during builds, where the each project uses the same files but different arguments. The build process itself is defined in a shared .targets file that does the sdk import.
If you want to define a builder packing order, create a packing project. It’s very easy. Add references to all of your other projects, then edit your csproj file to set ‘ReferenceOutputAssembly’ attribute to false. This will cause building the packing project to build the specified assembly, without using it as a dependency.
https://learn.microsoft.com/en-us/visualstudio/msbuild/common-msbuild-project-items?view=visualstudio
You then specify your packing items as needed:
You can reference items like this, assuming your project name and output assembly are the same:
13
u/psioniclizard Feb 19 '26
https://learn.microsoft.com/en-us/visualstudio/msbuild/exec-task?view=visualstudio
Is this what you are looking for? Just put it as target with BeforeTargets="PreBuildEvent" and run some scripts to compile shaders etc.
Unless I am missing something.
I won't say MSBUILD is great but it does have that option.
7
u/coppercactus4 Feb 19 '26
A lot of the things you are describing are totally possible with MsBuild. It's not an easy tool to use, but it's immensely powerful. I would suggest checking out the tool called structured log viewer which will give you a lot of information to how it works.
https://learn.microsoft.com/en-us/shows/visual-studio-toolbox/msbuild-structured-log-viewer
In addition.net added some commands like get property and get items so you can evaluate them outside of the build process
https://learn.microsoft.com/en-us/visualstudio/msbuild/evaluate-items-and-properties?view=visualstudio
31
u/Professional_Price89 Feb 19 '26
Never face any problem with MSBuild.
31
u/MayBeArtorias Feb 19 '26
Mate, you sound a bit confused tbh. About your war with class libraries: they are just DLL’s. If you want different behaviours you should compile different DLL’s tbh. And to add the possibility to reference a solution instead of an DLL would turn into transitive or circular dependency nightmare
5
u/Stable_Orange_Genius Feb 19 '26
I like how in JavaScript/typescript land you use JavaScript/typescript to define your build config (vite, esbuild, roll-up etc.). Meanwhile we need to screw around in shitty XML files. Most of the time that's fine but the moment you want to do something more advanced it's a pain in the ass. Especially since msbuild is incredibly badly documented
7
u/misaki_eku Feb 19 '26
Also building a game engine using c# and currently have no problem with MS build. For Nuget, most packages are shipping the build, not source code.
1
u/LookProfessional8471 Feb 19 '26
how many sln files do you want to have? how often do you want to split up libraries? not sure what the issue is here...
I started to try to answer your concerns, some of wich are valid, but then i thought that must be common knowledge and i dropped your post into gemini and it provided some pretty nice answers, with examples and everything.
i agree tho. managing that stuff by hand is awful but really not a big issue.
4
u/Otherwise-Pass9556 Feb 19 '26
Totally get this. MSBuild is “fine” until you try to do anything even slightly custom, then it turns into property/targets spaghetti real fast 😅 Once projects start splitting and you add custom tooling into the pipeline, the complexity (and usually build times) stack up quick. That’s actually where some teams start looking at distributed build acceleration tools like Incredibuild, not to fix MSBuild’s design, but to at least make the heavy multi-project builds less painful. Doesn’t solve the config quirks, but it can make iteration cycles a lot less brutal.
2
u/Arcodiant Feb 19 '26
I get your issue with trying to share projects and handle their references across multiple solutions, we have the same issue within our monorepo. You'll probably have an easy time putting everything into one sln file, then using solution filters to see the different subprojects.
6
u/DeadlyVapour Feb 19 '26
Git gud
1
u/afops Feb 19 '26
I think you only run into most of the issues if you ship libraries/nugets (even internally), or if you multi target applications for different platforms.
Most people target one framework/platform and just use big solutions and don’t think any more about it.
I do agree that compared to better systems like cargo it’s pretty terrible.
Also that sln files aren’t really a build system feature but more a VS/COM-bastard that is - poorly - parsed as a proj-list by some of the cli tools is infuriating.
1
u/Dr_Nubbs Feb 21 '26
Sounds like you might be using it wrong. But that's without more context. For example sln isn't even required, slnx is easier if you can use it but I'm guessing you are on unity or something if it is a game. Csproj can share values via build.props and there's a few other things
1
u/MelodicTelephone5388 Feb 22 '26
Most build systems are terrible. Just vibe code it and move on with your life 🤣 Spend your creativity on what you’re actually building
0
u/savornicesei Feb 19 '26
Been looking into KDE building documentation - they say CMake + Ninja is faster than MSBuild on C++ side.
Surprisingly, I had less headaches building KDE stuff from CLion (either using KDE craft or vcpkg) than from Visual Studio 2022.
There are quite a lot of things you can convince MSBuild to do, including publishing but might need to dive into the .targets files, documentation and trial and errors. You can inject your custom targets at different points in MSBuild flow.
With the new slnx format, defining build configurations becomes a single line in `Directory.Build.props` from your root directory:
<Configurations>Debug;Staging;Release;</Configurations>0
u/Camderman106 Feb 19 '26
When you publish a package using dotnet pack it produces a nuget package I was under the assumption that it contains both the debug and release versions. And that you’d consume the corresponding one in your downstream projects depending on that projects build settings. But I could be wrong. Can anyone confirm/deny this?
-7
u/simonask_ Feb 19 '26
Coming to msbuild and .sln/.csproj from literally ANY other build system (including the hellscape that is CMake) is a wet towel to the face.
It is so unbelievably bad that anyone making excuses for it has very clearly never used anything else. It is completely and utterly atrocious. The amount of outdated or simply wrong information on the internet rivals even CMake.
It simultaneously does way too little and way too much. It is human-readable, because you can’t achieve really basic things without tinkering with the XML, and at the same time completely anti-human - inconsistent and undiscoverable property names, verbose to the point of absurdity, and then it STILL doesn’t actually achieve its goals.
Why do I sometimes have to manually trigger a rebuild of my source generator project? Impossible to know.
This is a completely solved problem in other build systems like Cargo, which just does the right thing every time, are simple to configure, and provide accurate diagnostics.
OP: For an asset pipeline, I recommend building assets separately from building the engine. Writing Makefiles is easier, and you likely want to rebuild assets while the game is running anyway for hot reload.
You can also check out a more modern alternative called Werk (that I wrote), which works well on all platforms.
-1
u/wasabiiii Feb 19 '26
Yeah. I've been thinking about this for ages. Even done some prototyping work. But it's like 5 projects down on my to-do list.