0

I have two projects, that use the same code in the same location, but use different dependencies and app.config files, and both projects compile to the same exe name.

Currently, I have a PreBuild script configured, that copies the correct file from project_a.config or project_b.config to app.config.

Unfortunately, XBuild does not execute the PreBuild scripts when running from command line, so I have to do the copying before building.

Is there a way to use another file as app.config?

EDIT: Note, that this is only running on Linux.

The entry in my csproj file:

 <Command type="BeforeBuild" 
   command="cp -f MonoMultiJack.Linux.config app.config"
   workingdir="${ProjectDir}" />

And this is my build script:

#!/bin/bash
XBUILD=xbuild
SOLUTION=MonoMultiJack.Lnx.sln
# do some other stuff
${XBUILD} ${SOLUTION} /p:Configuration=Release /t:Clean
${XBUILD} ${SOLUTION} /p:Configuration=Release
Residuum
  • 11,878
  • 7
  • 40
  • 70
  • Related: http://stackoverflow.com/questions/2508020/give-app-config-another-name-after-build – Habib Mar 03 '15 at 20:41
  • where do you get the assumption "Unfortunately, XBuild does not execute the PreBuild scripts when running from command line, so I have to do the copying before building." from? – knocte Mar 04 '15 at 02:21
  • @knocte: I have tested it: XBuild does not copy the file to app.config before running with `${XBUILD} ${SOLUTION} /p:Configuration=Release`. This is also referenced on the web, e.g. http://wiki.directproject.org/share/view/25772231 – Residuum Mar 04 '15 at 09:20
  • The example that appears on that page is a command which is not cross-platform, so the reason is not that `xbuild doesn't run PreBuild scripts` it is that you must make sure that those scripts are cross platform! otherwise they only work in one platform – knocte Mar 04 '15 at 15:51

1 Answers1

1

Unfortunately, XBuild does not execute the PreBuild scripts when running from command line, so I have to do the copying before building.

This assumption of yours is wrong. PreBuild events work fine in xbuild, just as they do in MSBuild. What doesn't work is a script that is not cross-platform, such as using cmd.exe or the copy command (in Unix it's called cp), which only exist in Windows.

To prevent this problem, you need to use MSBuild conditions with xbuild, such as the ones explained here.

knocte
  • 16,941
  • 11
  • 79
  • 125