Search code examples
c#.netconfigurationweb-config-transformslowcheetah

Transform configurations on deployment of console applications


I've been deploying ASP.NET websites and managing their configurations using the web configuration transforms and building them using a command like:

MSBuild.exe MyMvcProj.csproj /P:Configuration:CustomConfiguration1

I've also got a console application which I need to deploy multiple times with different configurations and was wondering if there was any similar mechanism available to build the project and deploy it with a different configuration?

I've come across an article using custom XSLT to handle multi environment configs, but this seems like a very complicated and messy solution.

Thanks in advance!


Solution

  • It looks like the best way of deploying console apps is probably to use the publish tools which creates an installable application which is also update-able. However, that seemed a little full on for just deploying a few versions of a small utility.

    In the end I just used a batch file to simply run MSBuild, overwrite the configuration file and zip the directory to a specific location:

    "C:\WINDOWS\Microsoft.NET\Framework\v4.0.30319\MSBuild.exe" MyConsoleProj\MyConsoleProj.csproj /P:Configuration=ConfigA
    cp MyConsoleProj\app.ConfigA.config MyConsoleProj\bin\x86\ConfigA\MyConsoleProj.exe.config
    cd MyConsoleProj\bin\x86\ConfigA
    7z a -y C:\MyConsoleProj-ConfigA.zip
    cd ..\..\..\..
    

    It's pretty basic, but does the job allowing us to build the same project with multiple configurations very quickly ready to move out to remote servers.

    Also required for this is the open source 7-zip software.