Search code examples
.netvisual-studiosilverlightslowcheetah

ServiceReferences.ClientConfig plus slow cheetah not transforming


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?


Solution

  • 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:

    1. Make sure Web project properties build output path is \bin\ and configuration specific folders is set to No in the Silverlight Applications section of project properties
    2. Make sure Silverlight project properties build output path is \bin\ (this was my first problem)
    3. Either use Slow Cheetah (easy) or modify the csproj xml of the silverlight project (kind of a pain but not bad once done once - here is the link to allow you to have configuration specific transforms for your ServiceReferences.ClientConfig file). With slow cheetah you can view your transform by right clicking on the configuration specific transforms. Both mine and Kit's transform work.
    4. Add xml (taken from the above link) into the silverlight project (csproj) file. It is similar to Kit's but not sure why his wouldn't compile and this one would (This was my second problem) - xml below
    5. Rebuild project, then publish. The .xap will have your transformed ServiceReferences.ClientConfig file in it.
    6. Add the MyProject.Publish.Xml to your repository if you would like to share your deployment configurations with your whole team
     <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>