Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Use different pre-build events for different build configurations in Visual Studio

Is it possible to use different pre-build events for different build configurations in Visual Studio? For example, I'd like both a release configuration for a beta & live system and have the relevant app.[type].config get copied to app.config before it is compiled.

At the moment the configuration settings are baked into the .settings file, using the settings from the default app.config file.

like image 629
jaffa Avatar asked Oct 09 '22 06:10

jaffa


2 Answers

Or just put the Condition on your target ... eg.,

Condition="'$(Configuration)' == 'Debug'" 

.. or on your task.

If you're using Visual Studio VB/C# simple post build events, you can hand-edit the project file to put such conditions on the PreBuildEvent/PostBuildEvent property tags; and repeat the tags for Release.

Dan (msbuild dev)

like image 154
cheerless bog Avatar answered Oct 12 '22 10:10

cheerless bog


You can do this in a couple of ways, depending on your exact situation:

Option 1: Check the $(ConfigurationName) variable in your pre-build script, like so:

IF EXISTS $(ProjectDir)app.$(ConfigurationName).config 
    COPY $(ProjectDir)app.$(ConfigurationName).config $(ProjectDir)app.config

Option 2: Add a "BeforeCompile" MSBuild target to your project file:

<Target Name="BeforeBuild">
    <!-- MSBuild Script here -->
</Target>

Option 3: Use configuration file transformations; this VSIX plug-in adds the web.config transform features to non-web projects. These are XSLT files that let you rewrite your config files on build (unlike web projects, where it happens on publish.)

like image 22
Michael Edenfield Avatar answered Oct 12 '22 12:10

Michael Edenfield