Прочитав пост sLedgem и немного погуглив, я нашел идеальное решение, чтобы ServiceReferences работали как web.config.
Прежде всего: создайте разные файлы вручную;
ServiceReferences.Debug.ClientConfig
ServiceReferences.Release.ClientConfig
Вы также можете добавить свои собственные, если у вас больше двух конфигураций по умолчанию в Visual Studio.
Второе: добавьте зависимость файла в файл Project.csproj (откройте файл проекта в текстовом редакторе):
<ItemGroup>
<None Include="Properties\AppManifest.xml" />
<Content Include="ServiceReferences.ClientConfig">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
<Content Include="ServiceReferences.Debug.ClientConfig">
<DependentUpon>ServiceReferences.ClientConfig</DependentUpon>
</Content >
<Content Include="ServiceReferences.Release.ClientConfig">
<DependentUpon>ServiceReferences.ClientConfig</DependentUpon>
</Content >
</ItemGroup>
Теперь, когда вы перезагрузите проект, вы увидите, что ServiceReferences.Release.ClientConfig можно развернуть в обозревателе решений, а при его развертывании вы увидите файл Release и Debug.
В-третьих: добавить правила преобразования в файл проекта непосредственно перед закрытием </Project>
(снова откройте его в текстовом редакторе)
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets. -->
<UsingTask TaskName="TransformXml" AssemblyFile="$(MSBuildExtensionsPath)\Microsoft\VisualStudio\v10.0\Web\Microsoft.Web.Publishing.Tasks.dll" />
<Target Name="AfterCompile" Condition="exists('ServiceReferences.$(Configuration).ClientConfig')">
<!-- Generate transformed ServiceReferences config in the intermediate directory -->
<TransformXml Source="ServiceReferences.ClientConfig" Destination="$(IntermediateOutputPath)$(TargetFileName).ClientConfig" Transform="ServiceReferences.$(Configuration).ClientConfig" />
<!-- Force build process to use the transformed configuration file from now on. -->
<ItemGroup>
<ServiceReferencesConfigWithTargetPath Remove="ServiceReferences.ClientConfig" />
<ServiceReferencesConfigWithTargetPath Include="$(IntermediateOutputPath)$(TargetFileName).ClientConfig">
<TargetPath>$(TargetFileName).ClientConfig</TargetPath>
</ServiceReferencesConfigWithTargetPath>
</ItemGroup>
</Target>
Что он делает, так этопосмотрите в соответствующем файле servicereferences, в зависимости от вашей конфигурации, и скопируйте / замените код, используя ту же библиотеку TransformXML, которую использует web.config.
Exдостаточно:
в моем ServiceReferences.ClientConfig у меня есть следующий код:
<endpoint name="ICatalogueService"
address="address"
binding="basicHttpBinding"
bindingConfiguration="My_basicHttpBinding"
contract="Services.ServiceInterfaces.ICatalogueService"/>
ServiceReferences.Release.ClientConfig:
<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
<system.serviceModel>
<client>
<endpoint
name="ICatalogueService"
address="http://server/Services/CatalogueService.svc"
binding="basicHttpBinding"
bindingConfiguration="My_basicHttpBinding"
contract="Services.ServiceInterfaces.ICatalogueService"
xdt:Transform="Replace" xdt:Locator="Match(name)" />
</client>
<extensions />
</system.serviceModel>
</configuration>
Как видите, конечная точкабудет заменен, и сопоставление будет выполнено для атрибута name.
Если у вас есть какие-либо вопросы, дайте мне знать:)