SlowCheetah

repository·main·Indexed 43 days ago

https://github.com/microsoft/slow-cheetah

A tool for automated XML and JSON file transformations during the MSBuild process, enabling environment-specific configurations for different build profiles. It supports XDT (XML Document Transform) and JDT (JSON Document Transform) and is provided as a NuGet package (Microsoft.VisualStudio.SlowCheetah) and a Visual Studio extension for generating and previewing transforms.

Tokens
3.1K
Snippets
6
Records
17
Agent score
56%

What's inside SlowCheetah

  1. Overview of slow-cheetah

    main

    slow-cheetah is a tool for performing transformations on XML (e.g., app.config) and JSON files during the build process. It allows you to apply different configurations based on your build configuration or publish profiles.

    It consists of two main components:

    1. NuGet Package: Adds an MSBuild task to automate transformations during the build.
    2. Visual Studio Extension: Provides a UI for generating and previewing transformations within the IDE.
  2. Understand SlowCheetah Main Build Targets

    main

    SlowCheetah uses a specific sequence of targets to manage file transformations during the build process. The core workflow involves collecting files marked for transformation and then applying those transformations after files have been copied to the output directory.

    Core Targets

    • ScCollectTransformFiles: Scans the project for files where TransformOnBuild is set to true. It populates the ScFilesToTransform item group with the necessary metadata. This runs before ScApplyTransforms.
    • ScApplyTransforms: Creates the destination directories and applies the transformation task to every item in ScFilesToTransform. This runs after CopyFilesToOutputDirectory.
  3. How to file issues and get help

    main

    If you encounter bugs, have feature requests, or need help using slow-cheetah, use GitHub Issues.

    Before filing a new issue, search the existing issues to ensure your topic hasn't already been addressed. For new problems, file a bug report or a feature request as a new Issue.

  4. Install SlowCheetah for the first time

    main

    If SlowCheetah has never been installed on your computer or used in any of your projects, simply install the latest NuGet package: Microsoft.VisualStudio.SlowCheetah.

    https://www.nuget.org/packages/Microsoft.VisualStudio.SlowCheetah/
  5. Migrate from old SlowCheetah versions to the new version

    main

    If you are upgrading from an older version of SlowCheetah, you must manually clean up your project files before installing the new NuGet package and Visual Studio extension. The new version uses a NuGet package for build/transformation logic and a VS extension for UI assistance, whereas older versions relied on manual project file edits and local app data installations.

    1. Clean up the Project File

    Remove the following elements from your .csproj (or equivalent) file:

    • The <PropertyGroup Label="SlowCheetah"> block.
    • The <Import Project="$(SlowCheetahTargets)" ... /> line.
    • Any <None Include="..." /> entries related to packageRestore.proj or SlowCheetah.Transforms.targets.

    Note: The only SlowCheetah-related lines that should remain in your project file are the transformation files themselves, which are marked with <IsTransformFile>true</IsTransformFile>.

    2. Clean up Project Files and Folders

    Delete the following from your project directory:

    • The Properties\SlowCheetah folder.
    • The packageRestore.proj file.

    3. Install the New Version

    Once the project is cleaned:

    1. Install or update to the latest Microsoft.VisualStudio.SlowCheetah NuGet package via the NuGet Package Manager.
    2. Download and install the latest SlowCheetah extension from the Visual Studio extension gallery.

    4. Optional: Clean up Local App Data

    If you no longer intend to use any older versions of SlowCheetah on your machine, you can safely delete the following folder: %LocalAppData%\Microsoft\MSBuild\SlowCheetah

    <!-- Remove this PropertyGroup -->
    <PropertyGroup Label="SlowCheetah">
      <SlowCheetahToolsPath>$([System.IO.Path]::GetFullPath( $(MSBuildProjectDirectory)\..\packages\SlowCheetah.2.5.15\tools\))</SlowCheetahToolsPath>
      <SlowCheetah_EnableImportFromNuGet Condition=" '$(SlowCheetah_EnableImportFromNuGet)'=='' ">true</SlowCheetah_EnableImportFromNuGet>
      <SlowCheetah_NuGetImportPath Condition=" '$(SlowCheetah_NuGetImportPath)'=='' ">$([System.IO.Path]::GetFullPath( $(MSBuildProjectDirectory)\Properties\SlowCheetah\SlowCheetah.Transforms.targets ))</SlowCheetah_NuGetImportPath>
      <SlowCheetahTargets Condition=" '$(SlowCheetah_EnableImportFromNuGet)'=='true' and Exists('$(SlowCheetah_NuGetImportPath)') ">$(SlowCheetah_NuGetImportPath)</SlowCheetahTargets>
    </PropertyGroup>
    
    <!-- Remove this Import -->
    <Import Project="$(SlowCheetahTargets)" Condition="Exists('$(SlowCheetahTargets)')" Label="SlowCheetah" />
    
    <!-- Remove these Includes -->
    <None Include="packageRestore.proj" />
    <None Include="Properties\SlowCheetah\SlowCheetah.Transforms.targets" />
  6. Use the SlowCheetah Visual Studio extension to add and preview transforms

    main

    The SlowCheetah Visual Studio extension provides a UI for managing file transformations within the IDE.

    To add transformations:

    1. Right-click a supported file in your project.
    2. Select the Add Transform option.

    This automatically creates transform files corresponding to your project's build configurations (e.g., Debug, Release) and any existing publish profiles.

    To preview changes:

    1. Right-click any generated transform file.
    2. Select the Preview Transform option to see the resulting file or the diff.
  7. Perform build-time transformations using the SlowCheetah NuGet package

    main

    To enable transformations during the build process without using the Visual Studio extension, you must install the Microsoft.VisualStudio.SlowCheetah NuGet package.

    You can manually configure transformations in your project file (.csproj, .vbproj, etc.) by setting specific metadata on the files:

    1. Target File: The file you want to transform must have <TransformOnBuild>true</TransformOnBuild>.
    2. Transform Files: The configuration-specific files must have <IsTransformFile>True</IsTransformFile>.
    3. Relationship: To link a transform file to its target, use the <DependentUpon> metadata pointing to the original file.

    This approach allows for automated transformations in environments where the Visual Studio extension is not present (e.g., CI/CD pipelines).

    <None Include="App.config">
        <TransformOnBuild>true</TransformOnBuild>
    </None>
    <None Include="App.Debug.config">
        <DependentUpon>App.config</DependentUpon>
        <IsTransformFile>True</IsTransformFile>
    </None>
    <None Include="App.Release.config">
        <DependentUpon>App.config</DependentUpon>
        <IsTransformFile>True</IsTransformFile>
    </None>