Monday, January 26, 2015

Generating standalone binaries for Mono project (like a boss)

I see a lot of distrust in msbuild and especially xbuild scripts. Many developers prefer writing bash or worse, batch scripts which build the project. But why to add complexity if you have necessary tools at your disposal?

If you're writing some app that you want to distribute, you really need a standalone binary. For Mono, it can be easily generated by mkbundle utility. You really want to automate this stuff. So, what is the easiest way to do it? Make a new step in build scripts.

In xbuild scripts, just as in msbuild, there is an Exec task, which allows you to run an arbitrary application. So, in Mono it would look something like this:
  <Target Name='AfterBuild'>
  <Exec Command="mkbundle bin/$(Configuration)/PowerCertmgr.exe -o power-certmgr" 
        Condition="'$(OS)' == 'Unix'" />
  </Target>

We want to run this script only if OS is Unix-like. Why? Well, I'm working in Linux and I don't really care about Windows :) One should check if it runs on non-Unix systems, and in case of problems provide alternative implementations.

Even though xbuild scripts are underdeveloped compared to msbuild scripts, they can easily handle work like that. I really hope this approach will be more popular.

No comments:

Post a Comment