Search code examples
.nettransformationweb.config-transformslowcheetahconfig-transformation

SlowCheetah: How to Include transformed files from a class library referenced in a a second project to that projects output?


Using SlowCheetah I have a custom.config file in my class library and I want this file transformed and included in the output of my console application which references it.

Slow Cheetah transforms the custom.config into its own bin folder, and I can include the custom.config by using copy-always/newer, but then it is the untransformed config thats copied. How can I copy the transformed config file to my output project after it has been transformed by slowcheetah?

Please note I am not trying to transform and include my app.config as classLibrary.dll.config. I can do that allready. What I'm looking for is the option to transform and include other custom.config files after transformation.


Solution

  • I'll post my own solution here, I ended up giving up on SlowCheetah and just doing it directly in a custom transform step in the build file (.csproj).

    <Target Name="AfterBuild">
      <ItemGroup>
        <!-- Files to transform -->
        <ConfigurationFile Include="$(OutputPath)\Config\*.config" Exclude="$(OutputPath)\Config\*.*.config" />
        <!-- Files to use to transform -->
        <TransformationFile Include="$(OutputPath)\Config\*.*.config" />
      </ItemGroup>
      <!-- Message for debugging -->
      <Message Text="Transforming %(ConfigurationFile.Identity)  ==&gt;  @(ConfigurationFile->'$(OutputPath)\Config\%(Filename).$(Configuration)%(Extension)')" Importance="normal" Condition="Exists('@(ConfigurationFile->'$(OutputPath)\Config\%(Filename).$(Configuration)%(Extension)')')"
      />
    
      <!-- This is the actual transform step -->
      <TransformXml Source="%(ConfigurationFile.Identity)" Transform="@(ConfigurationFile->'$(OutputPath)\Config\%(Filename).$(Configuration)%(Extension)')" Destination="@(ConfigurationFile->'$(OutputPath)\Config\%(Filename)%(Extension)')" StackTrace="True"
      Condition="Exists('@(ConfigurationFile->'$(OutputPath)\Config\%(Filename).$(Configuration)%(Extension)')')" />
    
    
    
      <!-- ===Uncomment this to clean up transform files from target directory=== -->
      <!--<Message Text="Deleting:  %(TransformationFile.Identity)" />
    	 <Delete Files="@(TransformationFile)" /> -->
    </Target>

    All my config files exist in referenced projects inside directories called "Config" and are called "somethingSpecific.config" and all transform files are called "somethingSpecific.someEnvironment.config".

    This build target will search for all files in the config folder, and attempt to find transform files that correspond to the build configuration. For any matches it finds it will perform the transform. Just make sure all config files and all transform files find their way to the correct folder in the output path.