AspNetCore.SassCompiler
1.82.0
See the version list below for details.
dotnet add package AspNetCore.SassCompiler --version 1.82.0
NuGet\Install-Package AspNetCore.SassCompiler -Version 1.82.0
<PackageReference Include="AspNetCore.SassCompiler" Version="1.82.0" />
paket add AspNetCore.SassCompiler --version 1.82.0
#r "nuget: AspNetCore.SassCompiler, 1.82.0"
// Install AspNetCore.SassCompiler as a Cake Addin #addin nuget:?package=AspNetCore.SassCompiler&version=1.82.0 // Install AspNetCore.SassCompiler as a Cake Tool #tool nuget:?package=AspNetCore.SassCompiler&version=1.82.0
AspNetCore.SassCompiler
Sass Compiler Library for .NET 6 and above, without node.
Installation
The installation of this package is quite simple, you can install this package using NuGet with the following command:
# Package Manager
PM> Install-Package AspNetCore.SassCompiler
# .NET CLI
dotnet add package AspNetCore.SassCompiler
Configuration
After adding the package, the Sass styles from the Source (defaults to: Styles) will automatically be compiled into .css
files in the TargetFolder (defaults to: wwwroot\css) on build.
You can also adjust the default configuration in the appsettings.json or sasscompiler.json, do note that when using appsettings.json
the configuration needs to be nested under a "SassCompiler" property, but when you're using sasscompiler.json
the settings should not be nested.
Available options
Name | Default value | Description |
---|---|---|
Source | "Styles" | The folder where all the .scss files reside, or an scss file |
Target | "wwwroot/css" | When Source is a folder, the folder to output the generated .css files to<br/>When Source is a file, the .css filepath where to save the css file |
Arguments | "--error-css" | Arguments passed to the dart-sass executable. see here for available arguments. |
GenerateScopedCss | true | Enable/disable support for scoped scss |
ScopedCssFolders | ["Views", "Pages", "Shared", "Components"] | The folders in which .scss files are considered for scoped css |
IncludePaths | [] | Add folders to search in when importing modules |
Compilations | [] | A list of source/target pairs that should be compiled. These will be added to the default Source and Target configured above. |
Configurations | {} | Add configuration to override specific options based on the build conifguration (e.g. Debug/Release) |
Examples
<details open> <summary>appsettings.json</summary>
{
"SassCompiler": {
"Source": "Styles",
"Target": "wwwroot/css",
"Arguments": "--style=compressed",
"GenerateScopedCss": true,
"ScopedCssFolders": ["Views", "Pages", "Shared", "Components"],
"IncludePaths": [],
"Compilations": [
// Specify a specific file source/target in addition to the "Styles" -> "wwwroot/css" Source/Target above
{ "Source": "wwwroot/scss/site.scss", "Target": "wwwroot/css/site.min.css" },
// Or an extra directory to a different target directory
{ "Source": "Lib/Styles", "Target": "wwwroot/lib/css" }
],
// You can override specific options based on the build configuration
"Configurations": {
"Debug": { // These options apply only to Debug builds
"Arguments": "--style=expanded"
}
}
}
}
</details>
<details> <summary>sasscompiler.json</summary>
{
"Source": "Styles",
"Target": "wwwroot/css",
"Arguments": "--style=compressed",
"GenerateScopedCss": true,
"ScopedCssFolders": ["Views", "Pages", "Shared", "Components"],
"IncludePaths": [],
"Compilations": [
// Specify a specific file source/target in addition to the "Styles" -> "wwwroot/css" Source/Target above
{ "Source": "wwwroot/scss/site.scss", "Target": "wwwroot/css/site.min.css" },
// Or an extra directory to a different target directory
{ "Source": "Lib/Styles", "Target": "wwwroot/lib/css" }
],
// You can override specific options based on the build configuration
"Configurations": {
"Debug": { // These options apply only to Debug builds
"Arguments": "--style=expanded"
}
}
}
</details>
Sass watcher
To use the Sass watcher in your project, you must add the following code to your startup.cs:
public void ConfigureServices(IServiceCollection services)
{
#if DEBUG
services.AddSassCompiler();
#endif
}
We recommend adding the #if DEBUG
statement to only use a watcher during debug mode.
Note: The Sass watcher is currently not supported inside of a docker container. This should only be an issue when you're developing inside of a docker container, running the published application in docker is supported as the compiler is automatically run during the MSBuild publish step. See this issue for the progress.
Blazor WASM
If you use this with Blazor WebAssembly and want to customize the settings you need to use the sasscompiler.json, using appsettings.json is not supported. The sass watcher is currently not supported for Blazor WebAssembly projects, the MSBuild task is still available and will compile your scss during build and publish.
Compiling SCSS at runtime
It is also possible to compile SCSS files at runtime by using the ISassCompiler
interface. By default however, the
sass executables are not included in a Release build. To make be able to use the ISassCompiler
interface in production
you need to add the following property to your csproj file: <SassCompilerIncludeRuntime>true</SassCompilerIncludeRuntime>
.
If you don't want to use the hosted service to automatically compile your scss files during development, but do want to
have the ISassCompiler
available, you can use the AddSassCompilerCore()
method instead of the AddSassCompiler()
method on the IServiceCollection
. This will register what is required to use the ISassCompiler
interface without
registering the hosted service.
Publish
This library also includes an MSBuild task that runs during the publish of your application. Because of this you don't need to include the Sass Watcher in your release builds and you can safely add the generated .css files to the .gitignore file as they are regenerated during publish.
Alpine linux
If you're publishing your application inside an alpine linux container, you will need to install gcompat
(using apk add gcompat
) before running dotnet build
or dotnet publish
.
This is needed because the dart runtime which is what the sass
compiler uses requires this package on alpine linux.
Examples
Take a look at one of our examples on how it can be integrated in your project. We've created example projects for ASP.NET Core MVC, Blazor Server/Wasm and RazorClassLibrary projects.
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 was computed. net5.0-windows was computed. net6.0 is compatible. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. 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. |
.NET Core | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
.NET Standard | netstandard2.0 is compatible. netstandard2.1 was computed. |
.NET Framework | net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
MonoAndroid | monoandroid was computed. |
MonoMac | monomac was computed. |
MonoTouch | monotouch was computed. |
Tizen | tizen40 was computed. tizen60 was computed. |
Xamarin.iOS | xamarinios was computed. |
Xamarin.Mac | xamarinmac was computed. |
Xamarin.TVOS | xamarintvos was computed. |
Xamarin.WatchOS | xamarinwatchos was computed. |
-
net6.0
- Microsoft.Extensions.Configuration.Binder (>= 3.1.0)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 3.1.0)
- Microsoft.Extensions.Hosting.Abstractions (>= 3.1.0)
- Microsoft.Extensions.Options (>= 3.1.0)
NuGet packages (19)
Showing the top 5 NuGet packages that depend on AspNetCore.SassCompiler:
Package | Downloads |
---|---|
JJMasterData.Web
JJMasterData is a codeless CRUD Generator from database metadata. This package contains the Data Dictionary Razor Class Library with all necessary packages. |
|
Enter.Ui
Package Description |
|
ThePensionsRegulator.GovUk.Frontend
Based on the GOV.UK Design System and GovUk.Frontend.AspNetCore. Adds extra features and components. |
|
ThePensionsRegulator.GovUk.Frontend.Umbraco
GOV.UK Design System components implemented using the block list editor in Umbraco, and classes used to build applications based on these components. |
|
ThePensionsRegulator.Frontend
Based on the GOV.UK Design System and GovUk.Frontend.AspNetCore. Adds extra components targeted at The Pensions Regulator including The Pensions Regulator branding. |
GitHub repositories (3)
Showing the top 3 popular GitHub repositories that depend on AspNetCore.SassCompiler:
Repository | Stars |
---|---|
MudBlazor/MudBlazor
Blazor Component Library based on Material design with an emphasis on ease of use. Mainly written in C# with Javascript kept to a bare minimum it empowers .NET developers to easily debug it if needed.
|
|
dotnetcore/BootstrapBlazor
Bootstrap Blazor is an enterprise-level UI component library based on Bootstrap and Blazor.
|
|
JJConsulting/JJMasterData
.NET CRUD generator library with Bootstrap support to create dynamic forms at runtime from a data dictionary.
|
Version | Downloads | Last updated |
---|---|---|
1.83.0 | 4,434 | 12/13/2024 |
1.82.0 | 5,712 | 12/4/2024 |
1.81.1 | 1,528 | 12/3/2024 |
1.80.6 | 25,485 | 11/4/2024 |
1.80.5 | 5,200 | 10/30/2024 |
1.80.4 | 4,961 | 10/24/2024 |
1.80.2 | 5,110 | 10/18/2024 |
1.80.1 | 2,243 | 10/17/2024 |
1.79.5 | 28,380 | 10/13/2024 |
1.79.3 | 22,290 | 9/21/2024 |
1.79.1 | 5,745 | 9/18/2024 |
1.77.8 | 62,514 | 7/12/2024 |
1.77.5 | 27,067 | 6/12/2024 |
1.77.4 | 6,198 | 6/3/2024 |
1.77.3 | 6,861 | 5/30/2024 |
1.77.2 | 20,175 | 5/17/2024 |
1.77.1 | 19,324 | 5/11/2024 |
1.77.0 | 448 | 5/10/2024 |
1.75.0 | 27,250 | 4/12/2024 |
1.74.1 | 14,850 | 4/4/2024 |
1.72.0 | 54,128 | 3/14/2024 |
1.71.1.1 | 22,724 | 3/1/2024 |
1.71.1 | 11,062 | 2/24/2024 |
1.71.0 | 4,170 | 2/16/2024 |
1.70.0 | 36,773 | 1/18/2024 |
1.69.7 | 19,459 | 1/3/2024 |
1.69.5 | 89,592 | 10/26/2023 |
1.69.3 | 15,161 | 10/12/2023 |
1.69.2 | 844 | 10/11/2023 |
1.69.1 | 1,042 | 10/10/2023 |
1.68.0 | 13,769 | 9/21/2023 |
1.67.0 | 2,502 | 9/15/2023 |
1.66.0 | 25,198 | 8/18/2023 |
1.64.2 | 23,212 | 8/1/2023 |
1.64.1 | 2,868 | 7/22/2023 |
1.64.0 | 5,572 | 7/20/2023 |
1.63.6 | 49,829 | 6/22/2023 |
1.63.5 | 5,634 | 6/21/2023 |
1.63.3 | 8,812 | 6/12/2023 |
1.63.2 | 690 | 6/8/2023 |
1.62.1 | 43,110 | 4/26/2023 |
1.61.0 | 14,924 | 4/7/2023 |
1.60.0 | 4,649 | 3/25/2023 |
1.59.3 | 3,497 | 3/16/2023 |
1.58.1 | 35,611 | 2/15/2023 |
1.58.0 | 7,537 | 2/1/2023 |
1.57.1 | 19,613 | 12/20/2022 |
1.56.2 | 2,177 | 12/9/2022 |
1.56.1 | 7,505 | 11/21/2022 |
1.55.0 | 15,817 | 9/22/2022 |
1.54.9 | 2,791 | 9/8/2022 |
1.54.8 | 2,759 | 9/1/2022 |
1.54.6 | 779 | 8/30/2022 |
1.54.5.1 | 3,957 | 8/22/2022 |
1.54.5 | 1,690 | 8/21/2022 |
1.54.4.1 | 2,762 | 8/16/2022 |
1.54.4 | 1,339 | 8/11/2022 |
1.54.3 | 2,200 | 8/5/2022 |
1.54.1 | 983 | 8/3/2022 |
1.54.0 | 8,664 | 7/23/2022 |
1.53.0 | 9,704 | 7/1/2022 |
1.52.3 | 3,021 | 6/9/2022 |
1.52.2 | 1,623 | 6/3/2022 |
1.52.1.2 | 2,396 | 5/26/2022 |
1.52.1.1 | 1,279 | 5/23/2022 |
1.52.1 | 1,971 | 5/21/2022 |
1.52.0 | 621 | 5/20/2022 |
1.51.0.4 | 1,532 | 5/9/2022 |
1.51.0.3 | 748 | 5/5/2022 |
1.51.0.2 | 849 | 5/3/2022 |
1.51.0.1 | 6,345 | 5/2/2022 |
1.51.0 | 17,911 | 4/26/2022 |
1.50.1 | 966 | 4/19/2022 |
1.50.0.1 | 1,359 | 4/11/2022 |
1.50.0 | 1,629 | 4/7/2022 |
1.49.11 | 608 | 4/6/2022 |
1.49.9 | 5,198 | 2/25/2022 |
1.49.8 | 1,002 | 2/19/2022 |
1.49.7 | 3,066 | 2/3/2022 |
1.49.4 | 1,201 | 2/1/2022 |
1.49.0 | 1,171 | 1/19/2022 |
1.48.0 | 699 | 1/13/2022 |
1.47.0 | 992 | 1/10/2022 |
1.45.2 | 2,937 | 12/31/2021 |
1.45.1 | 1,147 | 12/21/2021 |
1.45.0.1 | 382 | 12/19/2021 |
1.45.0 | 931 | 12/11/2021 |
1.44.0.1 | 450 | 12/10/2021 |
1.43.5 | 3,097 | 11/25/2021 |
1.43.4 | 1,175 | 10/27/2021 |
1.43.3 | 564 | 10/22/2021 |
1.43.2 | 678 | 10/14/2021 |
1.43.1 | 642 | 10/6/2021 |
1.42.1.1 | 617 | 9/29/2021 |
1.42.1 | 510 | 9/22/2021 |
1.42.0 | 464 | 9/21/2021 |
1.41.1 | 467 | 9/17/2021 |
1.41.0 | 441 | 9/15/2021 |
1.40.0 | 393 | 9/14/2021 |
1.39.2 | 530 | 9/10/2021 |
1.39.0 | 504 | 9/9/2021 |
1.0.4 | 2,251 | 8/12/2021 |
1.0.3 | 514 | 6/22/2021 |
1.0.2 | 540 | 6/17/2021 |
1.0.1 | 463 | 6/15/2021 |
1.0.0 | 459 | 6/14/2021 |
0.1.0 | 1,009 | 6/10/2021 |