I have a silverlight 5 project in VS 2010 and would like to have its config file changed based on my configuration, pretty much like one would change database connection strings for a web app.
My ServiceReferences.ClientConfig looks like this:
<configuration>
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="BasicHttpBinding_IWcfPortal" closeTimeout="00:10:00"
openTimeout="00:10:00" receiveTimeout="00:10:00" sendTimeout="00:10:00"
maxBufferSize="25000000" maxReceivedMessageSize="25000000" />
</basicHttpBinding>
</bindings>
<client>
<endpoint name="WcfCslaService" address="http://localhost:22/Services/WcfSlPortal.svc"
binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IWcfPortal"
contract="WcfPortal.IWcfPortal" />
</client>
</system.serviceModel>
My ServiceReferences.MyConfig.ClientConfig file (auto added with slow cheetah via right click, add transform) looks like this:
<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
<system.serviceModel>
<client>
<endpoint name="WcfCslaService" address="http://192.168.0.0:22/Services/WcfSlPortal.svc"
binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IWcfPortal" contract="WcfPortal.IWcfPortal"
xdt:Transform="Replace" />
</client>
</system.serviceModel>
My problem is that instead of replacing the whole node (like it is doing in my web.config in this same solution) the transform doesn't happen. I have tried clean/rebuild, manually deleting .xap file, building one project at a time. If I look in my silverlight project\bin folder and unzip my xap file it ends up containing all the ClientConfig files, and the main config file left untouched. I also have an error in my xap file underlining the "xdt:Transform" that says "The 'http://schemas.microsoft.com/XML-Document-Transform:Transform' attribute is not declared."
If I right click on ServiceReferences.MyConfig.ClientConfig, Preview Transform it shows me exactly what it should (same service with updated IP address). The other crazy thing is that this was working previously and I have no idea what I did to break it (broke right before I went to commit to the repo). I have uninstalled and reinstalled slow cheetah, restarted etc.
Anyone know how to fix this transform to work?
Thanks to Kit for the help. I finally got a little time to look into this and deploy to a few different servers using different configurations and came up with the following solution:
<UsingTask TaskName="TransformXml" AssemblyFile="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v10.0\Web\Microsoft.Web.Publishing.Tasks.dll" /> <Target Name="BeforeBuild" Condition="Exists('ServiceReferences.$(Configuration).ClientConfig')"> <Move SourceFiles="ServiceReferences.ClientConfig" DestinationFiles="ServiceReferences.Build.ClientConfig" /> <TransformXml Source="ServiceReferences.Build.ClientConfig" Destination="ServiceReferences.ClientConfig" Transform="ServiceReferences.$(Configuration).ClientConfig" /> </Target> <Target Name="AfterBuild" Condition="Exists('ServiceReferences.Build.ClientConfig')"> <Delete Files="ServiceReferences.ClientConfig" /> <Move SourceFiles="ServiceReferences.Build.ClientConfig" DestinationFiles="ServiceReferences.ClientConfig" /> </Target>