MSBuild Change configuration value based on debug / release assembly

In my app.config I have

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

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

<endpoint address="http://live.example.com/Endpoint.asmx" stuff />
+3
source share
3 answers

If you use the MSBuild extension package , the Xml task will allow you to modify the entry in the XML file. Import custom tasks into the MSBuild file:

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

and update the 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)"
/>

Replace your XPath and execute it only during release build using the condition.

+2
source

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

<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>
+4
source

If you are using VS 2012 or higher, you can add a configuration conversion to replace the values ​​in the assembly. If you use 2010, it is available for web.config automatically, but for app.configs you need to do a little hack in the * .csproj file described here: http://www.andrewdenhertog.com/msbuild/setting-web-app- settings-configuration-transforms-ducks-nuts-msbuild-part-8 /

0
source

Source: https://habr.com/ru/post/1785882/


All Articles