Search code examples
xmlsilverlighttransformationslowcheetah

silverlight outofbrowser.xml transformation


I'm trying to transform a Silverlight Applications OutOfBrowser.xml File which is unter Projectname\Properties\ with slowcheetah.

Unfortunately, I only get Messages that there is no schema information for each of the single Element attributes (example: ShortName ) and elements (example: OutOfBrowserSettings.Blurb)

Thats what the xml looks like:

<OutOfBrowserSettings ShortName="SLTestApp" EnableGPUAcceleration="True"
                      ShowInstallMenuItem="True">       
    <OutOfBrowserSettings.Blurb>SLTestApp</OutOfBrowserSettings.Blurb>
    <OutOfBrowserSettings.WindowSettings>
        <WindowSettings Title="SLTestApp" />
    </OutOfBrowserSettings.WindowSettings>
    <OutOfBrowserSettings.SecuritySettings>
        <SecuritySettings ElevatedPermissions="Required" />
    </OutOfBrowserSettings.SecuritySettings>
    <OutOfBrowserSettings.Icons />
</OutOfBrowserSettings>

And this is what I use for transformation. I want to replace the complete xml.

<?xml version="1.0" encoding="utf-8" ?>
<OutOfBrowserSettings ShortName="RenamedApp" EnableGPUAcceleration="True"
                  ShowInstallMenuItem="True"
                  xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform"
                  xdt:Transform="Replace">
    <OutOfBrowserSettings.Blurb>RenamedApp</OutOfBrowserSettings.Blurb>
    <OutOfBrowserSettings.WindowSettings>
        <WindowSettings Title="RenamedApp" />
    </OutOfBrowserSettings.WindowSettings>
    <OutOfBrowserSettings.SecuritySettings>
        <SecuritySettings ElevatedPermissions="Required" />
    </OutOfBrowserSettings.SecuritySettings>
    <OutOfBrowserSettings.Icons />
</OutOfBrowserSettings>

Nothing gets transformed. If I publish the SilverlightApplication.Web Project the name for the local installation hasn't changed from SLTestApp to RenamedApp.

Any ideas?

Kind Regards


Solution

  • The problem is you're looking for replacing whole file - not just node/nodes. While it is possible via SlowCheetah, you'll have to modify your replacement xml a lot (change replace of root node to SetAttribute and change all child nodes to use Replace transformation).

    But is seems to me like an overkill to use transformation, when all you really want to do is to copy specific file.

    Lets say in your .csproj you want to replace OutOfBrowserSettings.xml with OutOfBrowserSettings.Debug.xml for Debug version and with OutOfBrowserSettings.Release.xml for Release version.

    Then in your .csproj there should be

    <ItemGroup>
      <None Include="Properties\OutOfBrowserSettings.Debug.xml">
      </None>
      <None Include="Properties\OutOfBrowserSettings.Release.xml">
      </None>
    </ItemGroup>
    

    Do not specify OutOfBrowserSettings.xml in your .csproj - we'll calculate them dynamically in BeforeBuild target:

    <Target Name="BeforeBuild">
      <Copy Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' " SourceFiles="$(ProjectDir)Properties\OutOfBrowserSettings.Debug.xml" DestinationFiles="$(ProjectDir)Properties\OutOfBrowserSettings.xml" ContinueOnError="true" />
      <Copy Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' " SourceFiles="$(ProjectDir)Properties\OutOfBrowserSettings.Release.xml" DestinationFiles="$(ProjectDir)Properties\OutOfBrowserSettings.xml" ContinueOnError="true" />
      <ItemGroup>
        <Content Include="$(ProjectDir)Properties\OutOfBrowserSettings.xml" />
      </ItemGroup> 
    </Target>
    

    So for Debug version, debug version is copied, for Release version, release version is copied and output is always included in Content (thus in .xap as well).