CssExtractor.MSBuild 1.2.0

There is a newer version of this package available.
See the version list below for details.
dotnet add package CssExtractor.MSBuild --version 1.2.0
                    
NuGet\Install-Package CssExtractor.MSBuild -Version 1.2.0
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="CssExtractor.MSBuild" Version="1.2.0">
  <PrivateAssets>all</PrivateAssets>
  <IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="CssExtractor.MSBuild" Version="1.2.0" />
                    
Directory.Packages.props
<PackageReference Include="CssExtractor.MSBuild">
  <PrivateAssets>all</PrivateAssets>
  <IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add CssExtractor.MSBuild --version 1.2.0
                    
#r "nuget: CssExtractor.MSBuild, 1.2.0"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package CssExtractor.MSBuild@1.2.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=CssExtractor.MSBuild&version=1.2.0
                    
Install as a Cake Addin
#tool nuget:?package=CssExtractor.MSBuild&version=1.2.0
                    
Install as a Cake Tool

CssExtractor.MSBuild

Overview

CssExtractor.MSBuild is a custom MSBuild task designed to extract CSS classes and styles from various file types, deduplicate them, and write them to a single output file. This output can be utilized by CSS processors such as Tailwind CSS. The task is configurable via regular expressions, allowing users to specify which files to exclude and how to extract CSS classes.

Features

  • Extracts CSS classes from common file types such as HTML, CSHTML, and Razor.
  • Supports configurable regex patterns for file exclusion and class extraction.
  • Deduplicates CSS classes to ensure a clean output.
  • Outputs the extracted CSS classes to a specified file for further processing.

Installation

To use CssExtractor.MSBuild in your project, include it as a dependency in your project file (.csproj):

<PackageReference Include="CssExtractor.MSBuild" Version="1.0.0" />

Configuration

You can configure the CssExtractor task in your MSBuild project file. Below is an example configuration:

<Target Name="ExtractCssClasses">
  <CssExtractorTask 
    OutputFile="path/to/output.css"
    CssExtractorExcludeFiles="(node_modules|\.git)"
    CssExtractorPatterns="\.className\s*{[^}]*}"
    />
</Target>

Properties

  • OutputFile: The path to the output file where the deduplicated CSS classes will be written.
  • CssExtractorExcludeFiles: A regex pattern to exclude certain files from the extraction process. Multiple patterns can be specified.
  • CssExtractorPatterns: A regex pattern to define how CSS classes should be extracted from the files. Multiple patterns can be specified.

Examples

Integrating with Tailwind via Tailwind.MSBuild

To integrate the output from CssExtractor.MSBuild with Tailwind, you can create a target in your project file that runs the CssExtractor task before the Tailwind build process:

<Target Name="Build" BeforeTargets="TailwindBuild">
  <CssExtractorTask 
    OutputFile="path/to/tailwind.css"
    CssExtractorExcludeFiles="(node_modules|\.git)"
    CssExtractorPatterns="\.className\s*{[^}]*}"
    />
</Target>

Executing Tailwind via CLI

If you prefer to execute Tailwind via the command line, you can run the following command after the CssExtractor task has been executed:

npx tailwindcss -i ./src/input.css -o ./dist/output.css --minify

Make sure to adjust the input and output paths according to your project structure.

License

This project is licensed under the MIT License. See the LICENSE file for more details.

Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (1)

Showing the top 1 NuGet packages that depend on CssExtractor.MSBuild:

Package Downloads
Htmx.Components

A comprehensive ASP.NET Core library for building interactive web applications with server-side rendering and HTMX integration. Provides ready-to-use components, state management, and built-in authorization with minimal JavaScript.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.7.4 194 7/10/2025
1.7.3 131 7/10/2025
1.7.2 131 7/10/2025
1.7.1 133 7/10/2025
1.7.0 130 7/10/2025
1.6.0 132 7/9/2025
1.5.0 131 7/9/2025
1.4.0 133 7/9/2025
1.3.2 134 7/7/2025
1.3.0 137 7/7/2025
1.2.0 135 7/4/2025
1.0.1 130 7/3/2025