在我的 app.config 文件中,我有以下内容:
<endpoint address="http://debug.example.com/Endpoint.asmx" stuff />
我该如何修改构建任务,以便在进行发布构建时将终端点地址更改为
<endpoint address="http://live.example.com/Endpoint.asmx" stuff />
在我的 app.config 文件中,我有以下内容:
<endpoint address="http://debug.example.com/Endpoint.asmx" stuff />
我该如何修改构建任务,以便在进行发布构建时将终端点地址更改为
<endpoint address="http://live.example.com/Endpoint.asmx" stuff />
<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>
如果您使用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并仅执行此操作。