Tailwind.MSBuild 2.1.0

dotnet add package Tailwind.MSBuild --version 2.1.0
                    
NuGet\Install-Package Tailwind.MSBuild -Version 2.1.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="Tailwind.MSBuild" Version="2.1.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="Tailwind.MSBuild" Version="2.1.0" />
                    
Directory.Packages.props
<PackageReference Include="Tailwind.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 Tailwind.MSBuild --version 2.1.0
                    
#r "nuget: Tailwind.MSBuild, 2.1.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 Tailwind.MSBuild@2.1.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=Tailwind.MSBuild&version=2.1.0
                    
Install as a Cake Addin
#tool nuget:?package=Tailwind.MSBuild&version=2.1.0
                    
Install as a Cake Tool

<a name="readme-top"></a> <div align="center">

Tailwind.MSBuild

Tailwind CSS Integration for .NET Projects

<br />

Build Status Issues MIT License

NuGet Downloads

<hr /> </div>

<details> <summary>Table of Contents</summary> <ol> <li><a href="#about-the-project">About The Project</a></li> <li> <a href="#getting-started">Getting Started</a> <ul> <li><a href="#installation">Installation</a></li> <li><a href="#basic-use">Basic Use</a></li> <li><a href="#watch-mode">Watch Mode</a></li> </ul> </li> <li> <a href="#customize-your-build">Customize Your Build</a> <ul> <li><a href="#setting-build-properties">Setting Build Properties</a></li> <li><a href="#executing-tasks">Executing Tasks</a></li> </ul> </li> <li><a href="#license">License</a></li> </ol> </details>

About The Project

Tailwind.MSBuild is a NuGet package that adds MSBuild tasks for building Tailwind CSS to your project. With this package, you can easily integrate Tailwind CSS into your .NET project and automatically generate your stylesheets as part of your project's build process. It will also download the Tailwind Standalone CLI so you don't need to have npm installed.

Disclaimer: This project is not affiliated with Tailwind Labs.

<p align="right">(<a href="#readme-top">back to top</a>)</p>

Getting Started

Installation

Use your preferred method of managing NuGet packages or use one of the following installation methods.

Visual Studio

Install Tailwind.MSBuild using the NuGet Package Manager or with the following command in the Package Manager Console:

PM> Install-Package Tailwind.MSBuild
.NET CLI

You can add a package reference using the following command when the .NET CLI is available:

> dotnet add package Tailwind.MSBuild
Manually Edit Your .csproj File

You can manually add the following lines to your .csproj file within an ItemGroup:

<PackageReference Include="Tailwind.MSBuild" Version="2.*">
      <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
      <PrivateAssets>all</PrivateAssets>
</PackageReference>

Note: You will need to build your project once in order to create the initial configuration when using this method.

<p align="right">(<a href="#readme-top">back to top</a>)</p>

Basic Use

Once installed, you can customize Tailwind by modifying the tailwind.input.css files in your configuration directory which defaults to $(MSBuildProjectDirectory)\Properties\. If the directory or file does not exist, a default configuration will be initialized for you the next time you build your project. By default this file will add your project directory as a source path for Tailwind to scan for class names. For detailed instructions on configuring Tailwind CSS, see the official Configuration guide.

Each time you build your project, a css file will be generated at $(MSBuildProjectDirectory)\wwwroot\css\tailwind.css. You can also customize your input and output file paths. For example, to set your input file to "src/styles/tailwind.css" and your output file to "wwwroot/css/tailwind.css", you can add the following to your .csproj file:

<PropertyGroup Label="Tailwind Properties">
  <TailwindInputFile>$(MSBuildProjectDirectory)\src\styles\tailwind.css</TailwindInputFile>
  <TailwindOutputFile>$(MSBuildProjectDirectory)\wwwroot\css\site.css</TailwindOutputFile>
</PropertyGroup>

On Windows ARM64, the package prefers the release's native executable and uses x64 only when that release omits ARM64. A pinned release can reuse its cached native executable without a GitHub lookup. If the native executable is missing, the package checks the release metadata before using a cached x64 executable. On Windows ARM64, latest resolves to a concrete tag so the cache stays specific to that release.

<p align="right">(<a href="#readme-top">back to top</a>)</p>

Watch Mode

Tailwind.MSBuild supports watch and hot-reload workflows by starting the Tailwind CLI in watch mode when it can detect a watch build.

Auto-detected scenarios:

  • A build defaults to Tailwind watch when BuildingInsideVisualStudio or DotNetWatchBuild is true, or when the build receives DOTNET_WATCH=1 or DOTNET_WATCH=true. This covers child builds from dotnet watch build and dotnet watch run --no-hot-reload.
  • With the .NET 10 SDK's hot reload workflow, plain dotnet watch run starts Tailwind during the watcher's project scan. In ASP.NET Core apps, the SDK can apply generated CSS changes in the open browser once its hot reload session is ready and the stylesheet is included as a watched static asset.

For SDKs without these watch signals, run dotnet watch run --property:TailwindWatch=true from your project directory. Set TailwindWatch=false to opt out of automatic watch mode.

On startup, Tailwind.MSBuild compiles the stylesheet before starting the watcher. The initial compilation reports errors to MSBuild. On Linux it tries xdg-terminal-exec, x-terminal-emulator, and known terminal emulators. Close the terminal window to stop its watcher. If no terminal can launch the CLI, the watcher runs with output redirected to a .log file beside the watch lock. The build prints the process ID and log path for that fallback.

If Linux auto-detection picks the wrong terminal, or you want to force a specific one, set TailwindTerminalExecutable to a supported terminal executable name or absolute path.

To avoid duplicate Tailwind CLI instances during watch builds, Tailwind.MSBuild tracks running processes in a lock file. You can override the lock file location with TailwindLockFile.

<p align="right">(<a href="#readme-top">back to top</a>)</p>

Customize Your Build

Setting Build Properties

If you want to change any of the default settings Tailwind.MSBuild uses, you can override them by setting any of the following properties in your .csproj file.

MSBuild Property Name Default Value Description
TailwindVersion latest The version tag of the tailwind release to use.
TailwindInstallPath $(MSBuildThisFileDirectory)..\cli\ The directory where the tailwindcss cli should be located.
TailwindConfigDir $(MSBuildProjectDirectory)\Properties\ The directory containing the tailwind configuration files.
TailwindInputFile tailwind.input.css The name of the input css file.
TailwindOutputFile $(MSBuildProjectDirectory)\wwwroot\css\tailwind.css The path where the output css file will be located.
TailwindMinify false for Debug builds, true for Release builds Whether the generated css should be minified or not.
TailwindWatch true in detected watch builds, otherwise false Whether Tailwind runs in watch mode.
TailwindTerminalExecutable `` Optional Linux watch-mode terminal override.
TailwindLockFile $(BaseIntermediateOutputPath)\tailwind-cli\watch.lock The path to the Tailwind CLI lock file.

⚠️ A note about TailwindInstallPath:

For the default install path, $(MSBuildThisFileDirectory) expands to the directory where Tailwind.MSBuild.props was extracted to. This means the default value of TailwindInstallPath is the equivilant of {NuGetPackageCache}\tailwind.msbuild\*VERSION*\cli\.

Here is a sample configuration that overrides every setting.

<PropertyGroup Label="Tailwind Properties">
  
  <TailwindVersion>v4.1.18</TailwindVersion>
  
  <TailwindInstallPath>$(BaseIntermediateOutputPath)\tailwind-cli\</TailwindInstallPath>
  
  <TailwindConfigDir>$(MSBuildProjectDirectory)\Tailwind\</TailwindConfigDir>
  
  <TailwindInputFile>input.css</TailwindInputFile>
  <TailwindOutputFile>..\wwwroot\css\site.min.css</TailwindOutputFile>
  
  <TailwindMinify>true</TailwindMinify>
  
  <TailwindWatch>true</TailwindWatch>
  
  <TailwindTerminalExecutable>x-terminal-emulator</TailwindTerminalExecutable>
  
  <TailwindLockFile>$(BaseIntermediateOutputPath)\tailwind-cli\watch.lock</TailwindLockFile>
</PropertyGroup>

<p align="right">(<a href="#readme-top">back to top</a>)</p>

Executing Tasks

Tailwind.MSBuild.targets defines a build target named BuildTailwind that runs before the BeforeBuild target. This target executes two tasks that Tailwind.MSBuild implements. The first task is GetTailwindCLI which returns the absolute path to the tailwind CLI to the build engine. The output is stored in a property which is then passed to BuildTailwindCSS as the value for the StandaloneCliPath parameter.

For advanced scenarios where you need to run the tasks during a different point in the build process, see the tables below for the parameters required for each task and the associated MSBuild Property passed by default. It is recommended to read Tailwind.MSBuild.targets as an example of how to properly invoke the MSBuild tasks.

GetTailwindCLI
Task Parameter MSBuild Property
Version TailwindVersion
RootInstallPath TailwindInstallPath
<GetTailwindCLI Version="$(TailwindVersion)" RootInstallPath="$(TailwindInstallPath)">
  <Output TaskParameter="StandaloneCliPath" PropertyName="StandaloneCliPath" />
</GetTailwindCLI>
BuildTailwindCSS
Task Parameter MSBuild Property
StandaloneCliPath Output of GetTailwindCLI
ConfigDir TailwindConfigDir
InputFile TailwindInputFile
OutputFile TailwindOutputFile
Minify TailwindMinify
Watch TailwindWatch
TerminalExecutable TailwindTerminalExecutable
WatchLockFile TailwindLockFile
ProjectDirectory MSBuildProjectDirectory
<BuildTailwindCSS StandaloneCliPath="$(StandaloneCliPath)"
                  ConfigDir="$(TailwindConfigDir)"
                  InputFile="$(TailwindInputFile)"
                  OutputFile="$(TailwindOutputFile)"
                  Minify="$(TailwindMinify)"
                  Watch="$(TailwindWatch)"
                  TerminalExecutable="$(TailwindTerminalExecutable)"
                  WatchLockFile="$(TailwindLockFile)"
                  ProjectDirectory="$(MSBuildProjectDirectory)">
  <Output TaskParameter="GeneratedCssFile" PropertyName="GeneratedCssFile" />
</BuildTailwindCSS>

<p align="right">(<a href="#readme-top">back to top</a>)</p>

License

Distributed under the MIT License. See LICENSE.md for more information.

<p align="center">Copyright © 2023 Michael Rasicci</p>

There are no supported framework assets in this package.

Learn more about Target Frameworks and .NET Standard.

  • .NETStandard 2.0

    • No dependencies.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
2.1.0 257 11/7/2026
2.0.3 4,719 4/25/2026
2.0.2 4,814 2/14/2026
2.0.1 223 1/26/2026
1.1.0 44,829 8/27/2023
1.0.2 8,024 3/25/2023
1.0.1 120 3/24/2023
1.0.0 140 3/9/2023