MSBuild根据调试/发布构建更改配置值

3

在我的 app.config 文件中,我有以下内容:

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

我该如何修改构建任务,以便在进行发布构建时将终端点地址更改为

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

4
如果您的调试/发布配置分别命名为Debug和Release,那么可以这样做:
<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>

2

如果您使用MSBuild扩展包,则Xml任务可允许您更改XML文件中的条目。在MSBuild文件中导入自定义任务:

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

并更新XML值:

<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)"
/>

使用条件语句,在发布版本中替换您的XPath并仅执行此操作。


0

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接