3

In my app.config, I have

<endpoint address="http://debug.example.com/Endpoint.asmx" stuff />

How can I modify the build tasks so that when I do a release build it changes the endpoint address to

<endpoint address="http://live.example.com/Endpoint.asmx" stuff />

3 Answers 3

4

If your debug/release configurations are named Debug and Release respectively, this should do it:

<PropertyGroup Condition="'$(Configuration)' == 'Debug'">
  <endpoint address="http://debug.example.com/Endpoint.asmx" stuff />
  <!-- other things depending on Debug Configuration can go here -->
</PropertGroup>
<PropertyGroup Condition="'$(Configuration)' == 'Release'">
  <endpoint address="http://live.example.com/Endpoint.asmx" stuff />
</PropertGroup>
Sign up to request clarification or add additional context in comments.

Comments

2

If you use the MSBuild extension pack the Xml task will allow you to change an entry in an XML file. Import the custom tasks in your MSBuild file:

<Import Project="$(MSBuildExtensionsPath)\ExtensionPack\MSBuild.ExtensionPack.tasks" />

and update an XML value:

<PropertyGroup>
   <OldValue>http://debug.example.com/Endpoint.asmx</OldValue>
   <NewValue>http://live.example.com/Endpoint.asmx</NewValue>
</PropertyGroup>

<MSBuild.ExtensionPack.Xml.XmlFile 
    TaskAction="UpdateAttribute" 
    File="app.config" 
    XPath="/configuration/system.serviceModel/client/endpoint[@address='$(OldValue)']" 
    Key="address"
    Value="$(NewValue)"
/>

Substitute your XPath and only execute this during a release build using Condition .

Comments

0

If you're using VS 2012 or above, you can add a config transform to replace the values on build. If you're using 2010 this is available for web.config automatically, but for app.configs you'll need to do a slight hack on your *.csproj file outlined here: http://www.andrewdenhertog.com/msbuild/setting-web-app-settings-configuration-transforms-ducks-nuts-msbuild-part-8/

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.