-
-
Save marshalhayes/8bfb1fe2ea519727b4d74bfb0a21e672 to your computer and use it in GitHub Desktop.
| <Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> | |
| <!-- This file exposes the following parameters --> | |
| <!-- TailwindVersion: The version of the Tailwind Standalone CLI to download. --> | |
| <!-- TailwindDownloadPath: The path to where to download the Tailwind Standalone CLI. This property is optional, and defaults to %LOCALAPPDATA% on Windows, and $XDG_CACHE_HOME on Linux and MacOS. --> | |
| <!-- TailwindInputStyleSheetPath: The path to the input stylesheet. --> | |
| <!-- TailwindOutputStyleSheetPath: The path to the output stylesheet. --> | |
| <!-- TailwindOptimizeOutputStyleSheet: Whether to optimize the output stylesheet. This property is optional, and defaults to false. --> | |
| <!-- TailwindMinifyOutputStyleSheet: Whether to minify the output stylesheet. This property is optional, and defaults to false when Configuration is Debug, and true when Configuration is Release. --> | |
| <!-- TailwindGenerateSourceMap: Whether to generate a source map for the output stylesheet. This property is optional. --> | |
| <!-- TailwindOutputSourceMapPath: The path to where to write the generated source map file. This property is optional, and when not specified, inline source maps are generated. Requires TailwindGenerateSourceMap to be true. --> | |
| <!-- TailwindDownloadUrl: The URL to the Tailwind Standalone CLI. This property is optional, and defaults to downloading the specified version from GitHub. --> | |
| <!-- To override these properties, create a PropertyGroup in the csproj file --> | |
| <!-- For example: --> | |
| <!-- <PropertyGroup> --> | |
| <!-- <TailwindVersion>v4.0.14</TailwindVersion> --> | |
| <!-- <TailwindInputStyleSheetPath>Styles/main.css</TailwindVersion> --> | |
| <!-- <TailwindOutputStyleSheetPath>wwwroot/main.css</TailwindVersion> --> | |
| <!-- </PropertyGroup --> | |
| <PropertyGroup> | |
| <TailwindOptimizeOutputStyleSheet Condition="'$(TailwindOptimizeOutputStyleSheet)' == ''">false</TailwindOptimizeOutputStyleSheet> | |
| <TailwindMinifyOutputStyleSheet Condition="$(TailwindMinifyOutputStyleSheet) == '' And '$(Configuration)' == 'Debug'">false</TailwindMinifyOutputStyleSheet> | |
| <TailwindMinifyOutputStyleSheet Condition="$(TailwindMinifyOutputStyleSheet) == '' And '$(Configuration)' == 'Release'">true</TailwindMinifyOutputStyleSheet> | |
| <!-- The path to where Tailwind should be downloaded to --> | |
| <!-- This should be a path that is writable by the current user, as well as one that is accessible in CI/CD pipelines --> | |
| <!-- By default, this is set to the local app data folder on Windows, and $XDG_CACHE_HOME on Linux and MacOS --> | |
| <!-- On Linux and MacOS, use $XDG_CACHE_HOME or $HOME/.cache --> | |
| <TailwindDownloadPath Condition="'$(TailwindDownloadPath)' == '' And ($([System.OperatingSystem]::IsLinux()) Or $([System.OperatingSystem]::IsMacOS()))">$([MSBuild]::ValueOrDefault($([System.Environment]::GetEnvironmentVariable('XDG_CONFIG_HOME')), $([System.IO.Path]::Combine($([System.Environment]::GetEnvironmentVariable('HOME')), '.cache'))))</TailwindDownloadPath> | |
| <!-- On Windows, use local app data (%LOCALAPPDATA%) --> | |
| <TailwindDownloadPath Condition="'$(TailwindDownloadPath)' == '' And $([System.OperatingSystem]::IsWindows())">$(LOCALAPPDATA)</TailwindDownloadPath> | |
| </PropertyGroup> | |
| <!-- Validate the parameters before download or building --> | |
| <Target Name="ValidateParameters" BeforeTargets="DownloadTailwind; Tailwind"> | |
| <!-- Ensure the version is specified --> | |
| <Error Condition="'$(TailwindVersion)' == ''" Text="Tailwind version not specified. Please specify the version. For example: <PropertyGroup><TailwindVersion>v4.0.14</TailwindVersion></PropertyGroup>"/> | |
| <!-- Ensure the input stylesheet path is specified & the file exists --> | |
| <Error Condition="'$(TailwindInputStyleSheetPath)' == ''" Text="Tailwind input stylesheet not specified. Please specify the path to the input stylesheet in the csproj file. For example: <PropertyGroup><TailwindInputStyleSheetPath>Styles/main.css</TailwindInputStyleSheetPath></PropertyGroup>"/> | |
| <Error Condition="!Exists('$(TailwindInputStyleSheetPath)')" Text="Tailwind input stylesheet '$(TailwindInputStyleSheetPath)' does not exist. Please specify a path to a stylesheet. For example: <PropertyGroup><TailwindInputStyleSheetPath>Styles/main.css</TailwindInputStyleSheetPath></PropertyGroup>"/> | |
| <!-- Ensure the output stylesheet path is specified --> | |
| <Error Condition="'$(TailwindOutputStyleSheetPath)' == ''" Text="Tailwind output stylesheet not specified. Please specify the path to the output stylesheet in the csproj file. For example: <PropertyGroup><TailwindOutputStyleSheetPath>Styles/main.css</TailwindOutputStyleSheetPath></PropertyGroup>"/> | |
| <!-- Ensure the download path is specified --> | |
| <Error Condition="'$(TailwindDownloadPath)' == ''" Text="Tailwind download path not specified. Please specify the download path in the csproj file. For example: <PropertyGroup><TailwindDownloadPath>/tmp</TailwindDownloadPath></PropertyGroup>"/> | |
| </Target> | |
| <!-- This line supports hot reload by instructing dotnet watch to be aware of modifications to the input stylesheet --> | |
| <ItemGroup Condition="Exists('$(TailwindInputStyleSheetPath)')"> | |
| <Watch Include="$(TailwindInputStyleSheetPath)"/> | |
| </ItemGroup> | |
| <!-- Detect whether the system is using glibc or musl --> | |
| <Target Name="DetectLddVersion" BeforeTargets="DownloadTailwind" Condition="$([System.OperatingSystem]::IsLinux())"> | |
| <Exec Command="ldd --version" | |
| ConsoleToMsBuild="true" | |
| EchoOff="true" | |
| IgnoreExitCode="true" | |
| StandardOutputImportance="Low" | |
| StandardErrorImportance="Low"> | |
| <Output TaskParameter="ConsoleOutput" PropertyName="LddVersion" /> | |
| </Exec> | |
| <PropertyGroup> | |
| <IsMusl Condition="'$(LddVersion)' != '' And $(LddVersion.Contains('musl'))">true</IsMusl> | |
| </PropertyGroup> | |
| </Target> | |
| <Target Name="DownloadTailwind"> | |
| <PropertyGroup> | |
| <!-- Determine which version of Tailwind to use based on the current OS & architecture --> | |
| <TailwindReleaseName Condition="$([System.OperatingSystem]::IsLinux()) And '$(IsMusl)' == '' And $([System.Runtime.InteropServices.RuntimeInformation]::OSArchitecture) == X64">tailwindcss-linux-x64</TailwindReleaseName> | |
| <TailwindReleaseName Condition="$([System.OperatingSystem]::IsLinux()) And '$(IsMusl)' == '' And $([System.Runtime.InteropServices.RuntimeInformation]::OSArchitecture) == Arm64">tailwindcss-linux-arm64</TailwindReleaseName> | |
| <TailwindReleaseName Condition="$([System.OperatingSystem]::IsLinux()) And '$(IsMusl)' == 'true' And $([System.Runtime.InteropServices.RuntimeInformation]::OSArchitecture) == X64">tailwindcss-linux-x64-musl</TailwindReleaseName> | |
| <TailwindReleaseName Condition="$([System.OperatingSystem]::IsLinux()) And '$(IsMusl)' == 'true' And $([System.Runtime.InteropServices.RuntimeInformation]::OSArchitecture) == Arm64">tailwindcss-linux-arm64-musl</TailwindReleaseName> | |
| <TailwindReleaseName Condition="$([System.OperatingSystem]::IsMacOS()) And $([System.Runtime.InteropServices.RuntimeInformation]::OSArchitecture) == X64">tailwindcss-macos-x64</TailwindReleaseName> | |
| <TailwindReleaseName Condition="$([System.OperatingSystem]::IsMacOS()) And $([System.Runtime.InteropServices.RuntimeInformation]::OSArchitecture) == Arm64">tailwindcss-macos-arm64</TailwindReleaseName> | |
| <TailwindReleaseName Condition="$([System.OperatingSystem]::IsWindows()) And $([System.Runtime.InteropServices.RuntimeInformation]::OSArchitecture) == X64">tailwindcss-windows-x64.exe</TailwindReleaseName> | |
| <TailwindReleaseName Condition="$([System.OperatingSystem]::IsWindows()) And $([System.Runtime.InteropServices.RuntimeInformation]::OSArchitecture) == Arm64">tailwindcss-windows-arm64.exe</TailwindReleaseName> | |
| <TailwindDownloadUrl Condition="'$(TailwindDownloadUrl)' == '' And $(TailwindVersion) != 'latest'">https://github.com/tailwindlabs/tailwindcss/releases/download/$(TailwindVersion)/$(TailwindReleaseName)</TailwindDownloadUrl> | |
| <TailwindDownloadUrl Condition="'$(TailwindDownloadUrl)' == '' And $(TailwindVersion) == 'latest'">https://github.com/tailwindlabs/tailwindcss/releases/latest/download/$(TailwindReleaseName)</TailwindDownloadUrl> | |
| <TailwindDestinationFolder>$([System.IO.Path]::Combine('$(TailwindDownloadPath)', 'Tailwind', '$(TailwindVersion)'))</TailwindDestinationFolder> | |
| <TailwindCliPath>$([System.IO.Path]::Combine('$(TailwindDestinationFolder)', '$(TailwindReleaseName)'))</TailwindCliPath> | |
| </PropertyGroup> | |
| <!-- Download the file if it hasn't been already --> | |
| <!-- Note: Using latest will always reach out to GitHub to see if a new version is available --> | |
| <DownloadFile DestinationFolder="$(TailwindDestinationFolder)" | |
| DestinationFileName="$(TailwindReleaseName)" | |
| SourceUrl="$(TailwindDownloadUrl)" | |
| SkipUnchangedFiles="true" | |
| Retries="3" | |
| Condition="'$(TailwindVersion)' == 'latest' Or !Exists('$(TailwindCliPath)')"> | |
| <Output TaskParameter="DownloadedFile" PropertyName="TailwindCliPath"/> | |
| </DownloadFile> | |
| <!-- On unix systems, make the file executable --> | |
| <Exec Condition="Exists('$(TailwindCliPath)') And ($([System.OperatingSystem]::IsLinux()) Or $([System.OperatingSystem]::IsMacOS()))" | |
| Command="chmod +x '$(TailwindCliPath)'" | |
| EchoOff="true"/> | |
| </Target> | |
| <!-- When building the project, run the Tailwind CLI --> | |
| <!-- This target can also be executed manually. For example, with dotnet watch: `dotnet watch msbuild /t:Tailwind` --> | |
| <!-- In order to use hot reload, run both `dotnet watch run` and `dotnet watch msbuild /t:Tailwind` --> | |
| <Target Name="Tailwind" DependsOnTargets="DownloadTailwind" BeforeTargets="Build"> | |
| <PropertyGroup> | |
| <!-- Normalize the paths provided --> | |
| <TailwindCliPath>$([MSBuild]::NormalizePath('$(TailwindCliPath)'))</TailwindCliPath> | |
| <TailwindInputStyleSheetPath>$([MSBuild]::NormalizePath('$(TailwindInputStyleSheetPath)'))</TailwindInputStyleSheetPath> | |
| <TailwindOutputStyleSheetPath>$([MSBuild]::NormalizePath('$(TailwindOutputStyleSheetPath)'))</TailwindOutputStyleSheetPath> | |
| <TailwindOutputSourceMapPath Condition="'$(TailwindOutputSourceMapPath)' != ''">$([MSBuild]::NormalizePath('$(TailwindOutputSourceMapPath)'))</TailwindOutputSourceMapPath> | |
| <TailwindBuildCommand>"$(TailwindCliPath)" -i "$(TailwindInputStyleSheetPath)" -o "$(TailwindOutputStyleSheetPath)"</TailwindBuildCommand> | |
| <!-- Add optimize flag if specified --> | |
| <TailwindBuildCommand Condition="'$(TailwindOptimizeOutputStyleSheet)' == 'true'">$(TailwindBuildCommand) --optimize</TailwindBuildCommand> | |
| <!-- Add minify flag if specified --> | |
| <TailwindBuildCommand Condition="'$(TailwindMinifyOutputStyleSheet)' == 'true'">$(TailwindBuildCommand) --minify</TailwindBuildCommand> | |
| <!-- Add map flag if specified --> | |
| <TailwindBuildCommand Condition="'$(TailwindGenerateSourceMap)' == 'true' And '$(TailwindOutputSourceMapPath)' == ''">$(TailwindBuildCommand) --map</TailwindBuildCommand> | |
| <!-- Add map flag with output path if specified --> | |
| <TailwindBuildCommand Condition="'$(TailwindGenerateSourceMap)' == 'true' And '$(TailwindOutputSourceMapPath)' != ''">$(TailwindBuildCommand) --map "$(TailwindOutputSourceMapPath)"</TailwindBuildCommand> | |
| </PropertyGroup> | |
| <Exec Command="$(TailwindBuildCommand)" EchoOff="true"/> | |
| </Target> | |
| <!-- Delete the generated files when cleaning the project --> | |
| <Target Name="CleanTailwindOutput" AfterTargets="Clean"> | |
| <!-- Delete the output stylesheet --> | |
| <Delete Files="$(TailwindOutputStyleSheetPath)"/> | |
| <!-- Delete external source map file if specified --> | |
| <Delete Files="$(TailwindOutputSourceMapPath)" Condition="'$(TailwindOutputSourceMapPath)' != ''"/> | |
| </Target> | |
| </Project> |
👍 thanks!
Im the guy with the SpecialFolder problem on msbuild. This is how it currently looks in my code:
$([System.Environment]::GetFolderPath([System.Environment+SpecialFolder]::LocalApplicationData))
Maybe you can try building it on your system using windows and not WSL? I'm not really sure what the problem is.
Absolutely!
This should work for you on Windows:
<!-- Change the download path to this -->
<TailwindDownloadPath Condition="'$(TailwindDownloadPath)' == '' And $([System.OperatingSystem]::IsWindows())">$(LOCALAPPDATA)</TailwindDownloadPath>
<!-- Remove the quotes from the build command -->
<TailwindBuildCommand>$(TailwindCliPath) -i $(TailwindInputStyleSheetPath) -o $(TailwindOutputStyleSheetPath) --cwd $(ProjectDir)</TailwindBuildCommand>Thank you for catching this!
Removing the quotes on the build command is slightly worrying. I'll need to look for a more permanent solution there. Until I find a permanent solution, you won't be able to use a path that includes a space anywhere.
I'm still getting the same error unfortunately, I also tried building your mudblazor-tailwind template and I get the same error.
Just to make sure I understand, you changed the TailwindDownloadPath here to the below?
<TailwindDownloadPath Condition="'$(TailwindDownloadPath)' == '' And $([System.OperatingSystem]::IsWindows())">$(LOCALAPPDATA)</TailwindDownloadPath>And similarly, the TailwindBuildCommand here:
<TailwindBuildCommand>$(TailwindCliPath) -i $(TailwindInputStyleSheetPath) -o $(TailwindOutputStyleSheetPath) --cwd $(ProjectDir)</TailwindBuildCommand>Yes I copy pasted your code and changed both, making sure that I changed the TailwindDownloadPath for windows and not linux/mac. I made sure to check that msbuild works on my mvc projects and it does.
I've provided a revised version here. I tried it myself on Windows & it works.
Let me know it if works for you as well!
If you found this useful, leave a 👍 below!