Code Monkey home page Code Monkey logo

aspnetcore.sasscompiler's People

Contributors

adiessl avatar koenvzeijl avatar michaelvs97 avatar sleeuwen avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

aspnetcore.sasscompiler's Issues

Version stamp on generated files

Are there planes for creating version stamps on the generated files? Then your SassCompiler would be a complete soulution without any node or other npm packages.

Anyway thanks for making this great nuget packages

Cannot build from clone

Describe the bug

Cant build from clone

To Reproduce

  1. git clone https://github.com/koenvzeijl/AspNetCore.SassCompiler.git -o AspNetCore.SassCompiler
  2. cd AspNetCore.SassCompiler
  3. dotnet build
  4. See error below
/Users/mikes/Documents/Repos/AspNetCore.SassCompiler/Samples/AspNetCore.SassCompiler.RazorClassLibrary/obj/Debug/net6.0/AspNetCore.SassCompiler.RazorClassLibrary.AssemblyInfo.cs(13,36): error CS0234: The type or namespace name 'SassCompilerAttributeAttribute' does not exist in the namespace 'AspNetCore.SassCompiler' (are you missing an assembly reference?) [/Users/mikes/Documents/Repos/AspNetCore.SassCompiler/Samples/AspNetCore.SassCompiler.RazorClassLibrary/AspNetCore.SassCompiler.RazorClassLibrary.csproj]
/Users/mikes/Documents/Repos/AspNetCore.SassCompiler/Samples/AspNetCore.SassCompiler.RazorClassLibrary/obj/Debug/net6.0/AspNetCore.SassCompiler.RazorClassLibrary.AssemblyInfo.cs(13,36): error CS0234: The type or namespace name 'SassCompilerAttribute' does not exist in the namespace 'AspNetCore.SassCompiler' (are you missing an assembly reference?) [/Users/mikes/Documents/Repos/AspNetCore.SassCompiler/Samples/AspNetCore.SassCompiler.RazorClassLibrary/AspNetCore.SassCompiler.RazorClassLibrary.csproj]

Expected behavior
Build successfully

Screenshots
If applicable, add screenshots to help explain your problem.

Desktop (please complete the following information):

  • OS: MacOS 13.0
  • Browser Edge
  • Version Latest

Allow aliased file paths when importing through scss files

Add configuration for custom module paths similar to ESM. A feature when using JavaScript modules is that you can add something like this to jsconfig/tsconfig:

{
    "compilerOptions": {
        "baseUrl": ".",
        "paths": {
            "@constants/*": [
                "./src/constants/*"
            ],
            "@utils/*": [
                "./src/utils/*"
            ]
        }
    }
}

This will allow the compiler to use these paths to resolve imports in your different modules. Could something similar be done with sass imports?

I've run into a problem where I have many scoped scss files in my project, at different levels in the project structure. And something like this would be very useful.

Describe the solution you'd like

Instead of importing an scss file like this: @import '../../../Styles/_global.scss'; ,
you could do something like: @import '~globals/_global.scss' or just @import '_global.scss'

Additional context

It appears webpack has a way to do this using something like this:

// Webpack config
{
  test: /\.scss$/,
  loader: 'sass-loader',
  options: {
    sassOptions: {
      includePaths: [path.resolve(__dirname, '<path to styles>')],
    },
  },
},

which you would then use like this:

@import 'filename.scss'; // Imported from <path to styles> folder.

.style {
  //...
}

Can you install this Lib as a dev dependency

Is your feature request related to a problem? Please describe.
If I use PrivateAssets="all" my app crashes.
It is looking for the lib at runtime even though I only use it for generating assets at build time

Describe the solution you'd like
Ability to use Lib as a dev dependency in order to reduce app payload

Ability to watch multiple projects

When I first tried using this package I immediately ran into problems with the watch feature. In our solution we split modules between multiple projects where the startup project has almost no code to speak of, only the startup code. After testing it for some time and looking through this repository I came to the conclusion that the current solution is only adding folders from the startup directory too the watch list, which limits it's usability. Now I think this should be addressed some how, and if there is some way that this can be achieved that I clearly missed please let me know.

I decided to try create a proof of concept solution there for I forked and got it working
https://github.com/Mr-Badger/AspNetCore.SassCompiler/tree/target-multiple-projects
This solution is rather naïve and needs more work, there for I didn't create a PR.

Now there's a few things to consider, such as:

  • Possibly find a better way to determine the root folder of the project
  • Should only projects that include this nuget package be added to the watch
  • Add file/folder excludes
  • How would this work/perform in large projects

How to include files generated in a library project in the referencing project?

Hi!
I think this might not be a bug,, but I can't get the compiled files to be copied properly into the output directories of my executable projects. I'm compiling my scss in the library project that is referenced by several executable projects, and also other library projects too. I managed to make it work in my pipeline with docker, but there's a way to create conditions for the file not being copied. If you manually remove the bin directory of the executable project and try to run it again locally, then the compiled files won't be placed into the newly regenerated bin directory.
Here's an example project:
SassCompileTest.zip

There's a SassCompileTest project, it's a console app that prints if the compiled style was found or not. It references library project SassCompileLib, it has a source sass file style-sources/style.scss. On build, a new file is generated - style-compiled/style.css.

Steps to reproduce the bug:

  1. Run the SassCompileTest console project.
  2. The first time it should print true, which indicates that the file was correctly copied to the output directory.
  3. Go to the SassCompileTest project directory and remove the bin directory.
  4. Run the SassCompileTest console project again.
  5. Now it should return false. The file was not copied.

Expected:
The SassCompileTest app prints true, the newly regenerated bin directory has style-compiled/style.css.

I'm using a pc with windows 10, and .NET 8.0.204 sdk.

I've used suggestions from the issue #170
Thanks!

Non-Critical Question

So I've been trying to get a handle on how to use sass in both web project and several RCL projects that get composed into it. Having tried all the various packages and extensions this one remains the easiest to use and the most seamless. I would love to be able to configure more than one project/path and watch that, but that's for another day.

My question is, when I have this package installed and configure a source/target path the css files automatically get created if they don't exist. Similarly if I delete the css files either at design time or runtime *!!?) they are immediately updated. I can't for the life of me figure out how that is happening and since there are no msbuild or vs2022 logs/output at design time there isn't a clear way to track which system is making it happen. Oddly this does not work if the css file already exists and I update the scss, then I have to build to update it. That would be amazing but since it's all magic I have no clue if its possible.

Thanks so much,

James

“Could not load file or assembly 'System.Runtime, Version=4.2.2.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. ” in visual studio

Describe the bug
console error after installing AspNetCore.SassCompiler on Visual studio 2022 (and Visual studio 2020, width .NET 5) :
严重性 代码 说明 项目 文件 行 禁止显示状态
错误 MSB4062
未能从程序集 C:\Users\Windson.nuget\packages\aspnetcore.sasscompiler\1.44.0\build..\lib\netcoreapp3.1\AspNetCore.SassCompiler.dll 加载任务“AspNetCore.SassCompiler.CompileSass”。Could not load file or assembly 'System.Runtime, Version=4.2.2.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. 系统找不到指定的文件。 请确认 声明正确,该程序集及其所有依赖项都可用,并且该任务包含实现 Microsoft.Build.Framework.ITask 的公共类。 SassCompilerWeb C:\Users\Windson.nuget\packages\aspnetcore.sasscompiler\1.44.0\build\AspNetCore.SassCompiler.targets 7

To Reproduce
Steps to reproduce the behavior:

  1. Install AspNetCore.SassCompiler by nutget;
  2. See error

Screenshots
image

Desktop (please complete the following information):

  • OS: Windows 10
  • Version: 10.0.19044

Additional context
I try ver 1.44 and 1.43.5.1 on visual studio 2022 and visual studio 2020 but get the same error, but not any error on Rider 2021.2。

in-place compilation

Is your feature request related to a problem? Please describe.
I hoped to move from LibSassBuilder to DartSassBuilder but the latter one seems to be dead. What I like about DartSassBuilder is the in-place compilation of scss files. Css files are located beside scss files. No input or output folder needed.

Describe the solution you'd like
During the build process find all scss files in a project and compile them in-place. Use the directory of the scss file. Simply run scss compilation in folders where scss files are located. This would make configuration of source and destination folder obsolete.

Describe alternatives you've considered
none

Additional context
none

net7 Support

Do you think this is just a case of adding net7.0 to the target frameworks.
I would be happy to work with you on testing.
We would like our build to only need net7 SDK

Multiple source/target, .min naming, and earlier build step for Blazor

Issue
I like the simplicity of this nuget, and was hoping to use this to compile sass to scoped css files for a Blazor Server project. This currently doesn't work as expected for three reasons.

  1. AFAICT SassCompiler doesn't have a way to name compressed output files [file].min.css instead of [file].css when doing many to many.
  2. SassCompiler targets before CopyToOutputDirectory, so it does not run itself before the Blazor build step that aggregates scoped css files into [assemblyname].min.css
  3. SassCompiler only accepts one input/output pair. While sass's many/many syntax can compile all the scss files in a Blazor project's /Pages directory into their component-scoped css file counterparts, it cannot at the same time compile global styles in a /Styles directory destined for wwwroot/css.

Proposed solution

The SassCompiler object in appsettings.json could hold a list of input/target/argument sets which would be run in series using the order in which they are listed.

The SassCompiler build step could be targeted early enough that the compiled .css files are available for the Blazor css aggregation build step to find.

Alternatives
I could potentially add a separate post build step to rename minified css files to have .min.

Maybe there's a clever way to hack in adding .min via the attributes or targetfolder with the current code? I don't believe dart sass supports renaming outside of one to one file compilation, but there may be commandline/powershell type tricks to do it. I don't enough about what MSBUILD could carry through from parameters yet to answer that.

our current npm/node.js solution

Docker + Alpine Linux - AspNetCore.SassCompiler.targets(11,5): error : Error running sass compiler:

I have edited this issue now that I have done some more research and have create a bare repository to help demo the issue:

The issue seems to be when building with an Alpine Linux Docker image with AspNetCore.SassCompiler.

If you inherit from the usual FROM mcr.microsoft.com/dotnet/sdk:6.0 Ubuntu image then all builds and works as normal however if you inherit from the Alpine version FROM mcr.microsoft.com/dotnet/sdk:6.0-alpine then you get build errors such as:

#14 0.508 Microsoft (R) Build Engine version 17.2.0+41abc5629 for .NET
#14 0.508 Copyright (C) Microsoft Corporation. All rights reserved.
#14 0.508
#14 2.574 /root/.nuget/packages/aspnetcore.sasscompiler/1.52.3/build/AspNetCore.SassCompiler.targets(11,5): error : Error running sass compiler:  [/source/aspnetcore-alpine-sass.csproj]
#14 2.574 /root/.nuget/packages/aspnetcore.sasscompiler/1.52.3/build/AspNetCore.SassCompiler.targets(11,5): error : . [/source/aspnetcore-alpine-sass.csproj]
#14 5.668   aspnetcore-alpine-sass -> /source/bin/release/net6.0/linux-musl-x64/aspnetcore-alpine-sass.dll
#14 5.732   aspnetcore-alpine-sass -> /app/
------
executor failed running [/bin/sh -c dotnet publish -c release -o /app -r linux-musl-x64 --no-self-contained --no-restore]: exit code: 1

I think it may have something to do with dart sass itself.

I have created a repo to demonstrate the bug and have a little more info in the readme.md over there.

https://github.com/solrevdev/aspnetcore-alpine-sass

Desktop (please complete the following information):

 OS: 64bit Mac OS X 10.15.7 19H1922
 Kernel: x86_64 Darwin 19.6.0
 Uptime: 2h 43m
 Packages: 547
 Shell: zsh 5.9
 Resolution: 1920x1080
 DE: Aqua
 WM: Quartz Compositor
 WM Theme: Blue
 Disk: 11G / 480G (5%)
 CPU: Intel Core i7-3615QM @ 2.30GHz
 GPU: Intel HD Graphics 4000
 RAM: 8217MiB / 16384MiB
dotnet --info
.NET SDK (reflecting any global.json):
 Version:   6.0.300
 Commit:    8473146e7d

Runtime Environment:
 OS Name:     Mac OS X
 OS Version:  10.15
 OS Platform: Darwin
 RID:         osx.10.15-x64
 Base Path:   /usr/local/share/dotnet/sdk/6.0.300/

Host (useful for support):
  Version: 6.0.5
  Commit:  70ae3df4a6

.NET SDKs installed:
  3.1.419 [/usr/local/share/dotnet/sdk]
  6.0.300 [/usr/local/share/dotnet/sdk]

.NET runtimes installed:
  Microsoft.AspNetCore.App 3.1.25 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 6.0.5 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App]
  Microsoft.NETCore.App 3.1.25 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]
  Microsoft.NETCore.App 6.0.5 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]

To install additional .NET runtimes or SDKs:
  https://aka.ms/dotnet-download

Changing Build Task Event

Hi, first of all thanks the compiler package it really helps.

I'm trying to use both BuildBundlerMinifier and your sass compiler but sass msbuild task is running after the one for BuildBundlerMinifier.
This is causing me some trouble as bundle needs to happen after the sass compile.

Here is what is configured for BuildBundlerMinifier
<Target Name="BundleMinify" AfterTargets="CompileTypeScriptWithTSConfig" BeforeTargets="BeforeCompile" Condition="'$(RunBundleMinify)' != 'False'">

Maybe if you change your task target things get in order?
Here is yours:

<Target Name="Compile Sass" BeforeTargets="Build;ResolveScopedCssInputs">

Problems with .NET 8 on build server (alpine amd64) with nuget path set

Describe the bug
After upgrading to .NET 8 the build server is not able to compile our solution anymore.

/builds/X/X/.nuget/aspnetcore.sasscompiler/1.69.5/build/AspNetCore.SassCompiler.targets(11,5): error : Error running sass compiler: /builds/X/X/.nuget/aspnetcore.sasscompiler/1.69.5/build/../runtimes/linux-x64/sass: exec: line 20: /builds/X/X/.nuget/aspnetcore.sasscompiler/1.69.5/runtimes/linux-x64/src/dart: not found [/builds/X/X/XYZ/ABC/ABC/ABC.csproj]

To Reproduce
Use dotnet restore/run/build/test with --packages referencing a directory (relative path) like .nuget like:

dotnet restore --packages .nuget
dotnet build --no-restore
dotnet test --no-restore --no-build

Expected behavior
Would expect that dart is found and SassCompiler works as normal.

System
Container: mcr.microsoft.com/dotnet/sdk:8.0.100-1-alpine3.18-amd64

Additional context
In the local folder on my windows (with .nuget sitting in C:\user\XXX\.nuget) i can see the 'dart' file in the folder where the build script under linux says it's missing.

System.TypeInitializationException: The type initializer for 'AspNetCore.SassCompiler.ChildProcessTracker' threw an exception. ---> System.DllNotFoundException: Unable to load shared library 'kernel32.dll' or one of its dependencies.

When running dotent watch I got the following

[14:16:32 FTL] Host terminated unexpectedly due to an unhandled exception
System.TypeInitializationException: The type initializer for 'AspNetCore.SassCompiler.ChildProcessTracker' threw an exception.
 ---> System.DllNotFoundException: Unable to load shared library 'kernel32.dll' or one of its dependencies. In order to help diagnose loading problems, consider setting the DYLD_PRINT_LIBRARIES environment variable: dlopen(libkernel32.dll, 1): image not found
   at AspNetCore.SassCompiler.ChildProcessTracker.CreateJobObject(IntPtr lpJobAttributes, String name)
   at AspNetCore.SassCompiler.ChildProcessTracker..cctor()
   --- End of inner exception stack trace ---
   at AspNetCore.SassCompiler.ChildProcessTracker.AddProcess(Process process)
   at AspNetCore.SassCompiler.SassCompilerHostedService.StartProcess()
   at AspNetCore.SassCompiler.SassCompilerHostedService.StartAsync(CancellationToken cancellationToken)
   at Microsoft.Extensions.Hosting.Internal.Host.StartAsync(CancellationToken cancellationToken)
   at Microsoft.Extensions.Hosting.HostingAbstractionsHostExtensions.RunAsync(IHost host, CancellationToken token)
   at Microsoft.Extensions.Hosting.HostingAbstractionsHostExtensions.RunAsync(IHost host, CancellationToken token)
   at Microsoft.Extensions.Hosting.HostingAbstractionsHostExtensions.Run(IHost host)
   at Microsoft.AspNetCore.Builder.WebApplication.Run(String url)
   at Program.<Main>$(String[] args) in /Users/solrevdev/Projects/project/src/Web/Program.cs:line 109
[14:16:32 INF] Shut down complete

My csproj

<PackageReference Include="AspNetCore.SassCompiler" Version="1.52.1" />

My appsettings.json

"SassCompiler": {
        "SourceFolder": "Styles",
        "TargetFolder": "wwwroot/css",
        "Arguments": "--style=compressed",
        "GenerateScopedCss": true,
        "ScopedCssFolders": ["Views", "Pages", "Shared", "Components"],
        // You can override specific options based on the build configuration
        "Configurations": {
            "Debug": {
                // These options apply only to Debug builds
                "Arguments": "--style=expanded"
            }
        }
    }

Program.cs

    var builder = WebApplication.CreateBuilder(args);

#if DEBUG
    // Setup sass compiler
    builder.Services.AddSassCompiler();
#endif

OS:

OS: macOS 11.6.6 20G624 x86_64
Host: Macmini7,1

.NET

dotnet --info
.NET SDK (reflecting any global.json):
 Version:   6.0.300
 Commit:    8473146e7d

Runtime Environment:
 OS Name:     Mac OS X
 OS Version:  11.6
 OS Platform: Darwin
 RID:         osx.11.0-x64
 Base Path:   /usr/local/share/dotnet/sdk/6.0.300/

Host (useful for support):
  Version: 6.0.5
  Commit:  70ae3df4a6

.NET SDKs installed:
  3.1.419 [/usr/local/share/dotnet/sdk]
  6.0.300 [/usr/local/share/dotnet/sdk]

.NET runtimes installed:
  Microsoft.AspNetCore.App 3.1.25 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 6.0.5 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App]
  Microsoft.NETCore.App 3.1.25 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]
  Microsoft.NETCore.App 6.0.5 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]

To install additional .NET runtimes or SDKs:
  https://aka.ms/dotnet-download

Runtime SASS compilation

Good evening, firstly congratulations on the project!

Is there a possibility of making a public class available in which I pass the path to a sass file and the path to the output and the method performs the compilation?

My use case:
We are developers of a library that uses Bootstrap, and we want to include the possibility for a user in our system that don't know web development to choose the primary color of the theme and thus compile Bootstrap.

P.S: I forked the project and didn't find an easy way because the logic is coupled with IHostedService

Sass watcher with GenerateAssemblyInfo=false

Sass command not found, not watching for changes.
GetSassCommand() is returning null when Sass watcher was enable and GenerateAssemblyInfo was false.

To Reproduce
Steps to reproduce the behavior:

  1. Set GenerateAssemblyInfo to false in csproj file
  2. Add the Sass watcher to your startup.cs.
  3. Run the application

Expected behavior
The GetSassCommand() method able to find the ../runtimes/.. sass executable instead null.

Additional context
Maybe a better way to locate the sass binary instead using reflection by [SassCompilerAttribute]

Conditionally disable SassCompiler?

Hello,

In my CI process I need SassCompiler to be conditionally disabled because a specific CI pipeline will not install npm packages by design and then SassCompiler cannot compile a specific scss that references a css provided by a npm package.

Building and running various unit tests don't need scss compilation results to succeed because they don't deal with the visual part of the webapp.

How can I achieve this?

I thought that conditionally not including the nuGet package in the webapp project (the only project with scss files) would work, but it still executes scss compilation when building. In my webapp I tried this locally to check how it works:

<ItemGroup Condition="'$(ASPNETCORE_ENVIRONMENT)' != 'Development'">
	<PackageReference Include="AspNetCore.SassCompiler" Version="1.71.0" />
</ItemGroup>

I also first tested a custom property passed at build time.

I just clean the bin and obj folders and run my build. I finally tested it locally because it kept failing in Azure with Sass compilation remaining enabled.

Thanks for helping.

SassCompiler keeps restarting in .Net 6 Razorpages

Describe the bug
When installing the package and adding the appsettings I see that the sass compiler keeps restarting and no sass files are ever compiled. The compiler does seem to work when GenerateScopedCss is set to false.

Log excerpt:

info: AspNetCore.SassCompiler.SassCompilerHostedService[0]
      Started Sass watch
info: AspNetCore.SassCompiler.SassCompilerHostedService[0]
      Duplicate source ".\Project\POC.App/Pages".
info: AspNetCore.SassCompiler.SassCompilerHostedService[0]
      Usage: sass <input.scss> [output.css]
info: AspNetCore.SassCompiler.SassCompilerHostedService[0]
             sass <input.scss>:<output.css> <input/>:<output/> <dir/>
info: AspNetCore.SassCompiler.SassCompilerHostedService[0]
      === Input and Output ===================
info: AspNetCore.SassCompiler.SassCompilerHostedService[0]
          --[no-]stdin               Read the stylesheet from stdin.
info: AspNetCore.SassCompiler.SassCompilerHostedService[0]
          --[no-]indented            Use the indented syntax for input from stdin.
info: AspNetCore.SassCompiler.SassCompilerHostedService[0]
      -I, --load-path=<PATH>         A path to use when resolving imports.
info: AspNetCore.SassCompiler.SassCompilerHostedService[0]
                                     May be passed multiple times.
info: AspNetCore.SassCompiler.SassCompilerHostedService[0]
      -s, --style=<NAME>             Output style.
info: AspNetCore.SassCompiler.SassCompilerHostedService[0]
                                     [expanded (default), compressed]
info: AspNetCore.SassCompiler.SassCompilerHostedService[0]
          --[no-]charset             Emit a @charset or BOM for CSS with non-ASCII characters.
info: AspNetCore.SassCompiler.SassCompilerHostedService[0]
                                     (defaults to on)
info: AspNetCore.SassCompiler.SassCompilerHostedService[0]
          --[no-]error-css           When an error occurs, emit a stylesheet describing it.
info: AspNetCore.SassCompiler.SassCompilerHostedService[0]
                                     Defaults to true when compiling to a file.
info: AspNetCore.SassCompiler.SassCompilerHostedService[0]
          --update                   Only compile out-of-date stylesheets.
info: AspNetCore.SassCompiler.SassCompilerHostedService[0]
      === Source Maps ========================
info: AspNetCore.SassCompiler.SassCompilerHostedService[0]
          --[no-]source-map          Whether to generate source maps.
info: AspNetCore.SassCompiler.SassCompilerHostedService[0]
                                     (defaults to on)
info: AspNetCore.SassCompiler.SassCompilerHostedService[0]
          --source-map-urls          How to link from source maps to source files.
info: AspNetCore.SassCompiler.SassCompilerHostedService[0]
                                     [relative (default), absolute]
info: AspNetCore.SassCompiler.SassCompilerHostedService[0]
          --[no-]embed-sources       Embed source file contents in source maps.
info: AspNetCore.SassCompiler.SassCompilerHostedService[0]
          --[no-]embed-source-map    Embed source map contents in CSS.
info: AspNetCore.SassCompiler.SassCompilerHostedService[0]
      === Other ==============================
info: AspNetCore.SassCompiler.SassCompilerHostedService[0]
      -w, --watch                    Watch stylesheets and recompile when they change.
info: AspNetCore.SassCompiler.SassCompilerHostedService[0]
          --[no-]poll                Manually check for changes rather than using a native watcher.
info: AspNetCore.SassCompiler.SassCompilerHostedService[0]
                                     Only valid with --watch.
info: AspNetCore.SassCompiler.SassCompilerHostedService[0]
          --[no-]stop-on-error       Don't compile more files once an error is encountered.
info: AspNetCore.SassCompiler.SassCompilerHostedService[0]
      -i, --interactive              Run an interactive SassScript shell.
info: AspNetCore.SassCompiler.SassCompilerHostedService[0]
      -c, --[no-]color               Whether to use terminal colors for messages.
info: AspNetCore.SassCompiler.SassCompilerHostedService[0]
          --[no-]unicode             Whether to use Unicode characters for messages.
info: AspNetCore.SassCompiler.SassCompilerHostedService[0]
      -q, --[no-]quiet               Don't print warnings.
info: AspNetCore.SassCompiler.SassCompilerHostedService[0]
          --[no-]quiet-deps          Don't print compiler warnings from dependencies.
info: AspNetCore.SassCompiler.SassCompilerHostedService[0]
                                     Stylesheets imported through load paths count as dependencies.
info: AspNetCore.SassCompiler.SassCompilerHostedService[0]
          --[no-]verbose             Print all deprecation warnings even when they're repetitive.
info: AspNetCore.SassCompiler.SassCompilerHostedService[0]
          --[no-]trace               Print full Dart stack traces for exceptions.
info: AspNetCore.SassCompiler.SassCompilerHostedService[0]
      -h, --help                     Print this usage information.
info: AspNetCore.SassCompiler.SassCompilerHostedService[0]
          --version                  Print the version of Dart Sass.
warn: AspNetCore.SassCompiler.SassCompilerHostedService[0]
      Sass compiler exited, restarting in 1 second.

To Reproduce
Steps to reproduce the behavior:

  1. Create a new .Net 6 Razor Webapp
  2. Install SassCompiler
  3. Add config and Service
  4. run the app.

Expected behavior
Sass being compiled.

BeforeTargets="Build" is not sufficient to include CSS in build output

Describe the bug
The current BeforeTargets="Build;ResolveScopedCssInputs;BundleMinify" is not sufficient to include the generated assets in a Blazor library.

I have to use a copy of the library and use BeforeTargets="BeforeBuild"in order for the generated css to be included in published output without building twice.

Expected behaviour
Include the generated css in build output even if it doesn't exist (e.g. in a clone publish scenario such as a CI pipeline).

Desktop (please complete the following information):

  • OS: macOS Linux and probably windows
  • Browser Any
  • Version Any

Dart Zombie Process on Windows

Dart Zombie Process After Stop Every Debug Session
Every time I start a debug session the Sass Watch (dart) starts but don't terminate when running session is stopped manually o even for an exception.

To Reproduce
Steps to reproduce the behavior:

  1. Debug
  2. Monitor process
  3. Stop debug session
  4. See Zombie Process

Expected behavior
Send dart.exe Termination when main application exit

Screenshots
image

Desktop:

  • OS: Windows 11
  • Browser: Any

Additional context
Have to run "taskkill /f /im dart.exe" every time the debug session end to cleanup unnecessary process.

Support for Razor Class Library

It would be nice to see support for stand-alone support in Razor Class Libraries.
For example:
All my components (I'm using Blazor) reside in a separate Razor Class Library, it would be nice that on build the transpiler is triggered and can be linked to the Razor Class Library and not a Runable project.

Unit / Integration tests

First of all, thank you for providing this NuGet package @koenvzeijl and @sleeuwen (and thanks for the swift merges of my PRs 😉). We have been able to integrate it into our development process where it replaced LibSassBuilder. Its advantage is not only that it is using Dart Sass, it also seems to do the compilation quite a bit faster. Comparing the compilation times on our build machines reveals that AspNetCore.SassCompiler only uses around 20 percent of the time that LibSassBuilder previously used.

While digging through the source code I noticed that there are currently no unit or integration tests and wondered if you thought about adding some, for example to make sure that future Dart Sass versions do still adhere to the same console output that the regular expression expects. Maybe one of you is already working on it? If not, I might be able to contribute some tests.

dotnet watch with sass hosted watcher constantly reloads css files

Describe the bug
When running the app with hosted compiler and dotnet watch, the app will constantly reload static css

To Reproduce
Steps to reproduce the behavior:

  1. Download this repo
  2. Navigate to the blazor sample app
  3. Run the app in watch mode: 'dotnet watch run'
  4. See that the app constantly reloads css because the file is changed

Expected behavior
I expected the css files to only change when the sass process actually recompiles them.

Screenshots
If applicable, add screenshots to help explain your problem.
image

Additional context/Thoughts.
I'm not sure what can actually be done, or if this is an issue with the sass versions you are using.
When looking at the css files, it seems to me that the sass process does change the "last modified" etc.

Unsure if it would be possible to use a File Watcher and start the sass process when it detects errors instead.
If thats not viable, and/or the issue is with the Sass binary, maybe just add a note to readme

CSS isolation support

Is your feature request related to a problem? Please describe.
When using files like *.cshtml.scss, there is problem, that generated file has extension .cshtml.css e.g.: in wwwrooot and during build I am getting following exception:

The scoped css file 'wwwroot\css\Test.cshtml.css' was defined but no associated razor component or view was found for it.

It is Razor Pages project, .NET 6.0, VS 2022

Describe the solution you'd like
It would be nice if the cshtml extension is removed during build.

Sass watcher Suport for Blazor WASM

Is your feature request related to a problem? Please describe.
Sass watcher is currently only supported for Blazor Server

Describe the solution you'd like
It would be Great if it would also be supported for Blazor WASM

Describe alternatives you've considered
Currently i am running a sass watcher plugin in vscode.
I have not found a solution to watch the sass files in Visual Studio for now.
I could also watch the sass files in a terminal using comand line sass. But it would of course be great if it would just do that automatically in visual studio using this compiler too.

Sass compiler continuously restarting

When I installed this package it continuously kept restarting.
This is what it produces in my console (just keeps outputting the same thing)

info: AspNetCore.SassCompiler.SassCompilerHostedService[0]
      Started Sass watch
info: AspNetCore.SassCompiler.SassCompilerHostedService[0]
      Positional and ":" arguments may not both be used.
info: AspNetCore.SassCompiler.SassCompilerHostedService[0]
      Usage: sass <input.scss> [output.css]
info: AspNetCore.SassCompiler.SassCompilerHostedService[0]
             sass <input.scss>:<output.css> <input/>:<output/> <dir/>
info: AspNetCore.SassCompiler.SassCompilerHostedService[0]
      === Input and Output ===================
info: AspNetCore.SassCompiler.SassCompilerHostedService[0]
          --[no-]stdin               Read the stylesheet from stdin.
info: AspNetCore.SassCompiler.SassCompilerHostedService[0]
          --[no-]indented            Use the indented syntax for input from stdin.
warn: AspNetCore.SassCompiler.SassCompilerHostedService[0]
      Sass compiler exited, restarting in 1 second.

Image of the issue

I copied my project and removed everything till I was down to a basic ASP MVC template. The issue was still there. I put it on my secondary GitHub account.

However, when I downloaded that repository to check if the issue still persisted it was suddenly gone.
On the project that I shaved down to a basic MVC template (the code between that and the linked repo is the same) the issue still exists so I sadly cannot tell you what steps to take to reproduce it (obviously already cleared bin/obj).

All three projects use the latest version of ASP.Net Core (MVC) with .Net5

Support for css isolation in Blazor Server on m1 Mac

Describe the bug
Building the project doesn't update the .razor.css file when there are changes to the .razor.scss file.

To Reproduce
Steps to reproduce the behavior:

  1. Change a color in a .razor.scss file
  2. Build the project
  3. Look at the associated .razor.css file for the change
  4. See no change

Expected behavior
CSS isolation appears to be supported.

Desktop (please complete the following information):

  • OS: macOS 12.3.1 (m1)

In-process SASS processing

Currently, I am working on a project in which I want to do occasional runtime SASS processing. There was once a package to do this, but it has not been updated in years to the point I doubt it will work all that well.

I'd essentially like the option of having some static object available where I could just convert a given string of SCSS to a string of CSS. It could be expanded upon later, but since dart-sass supports stdin, the code in this library could theoretically be expanded to support passing strings to this executable and reading the output.

Blazor WASM project does not build

When using the AspNetCore.SassCompiler package in a Blazor WebAssembly project, the build process fails with the following error:

error NETSDK1082: Für "Microsoft.AspNetCore.App" stand für den angegebenen RuntimeIdentifier "browser-wasm" kein Runtimepaket zur Verfügung.

To Reproduce
Steps to reproduce the behavior:

  1. dotnet new blazorwasm
  2. dotnet add package AspNetCore.SassCompiler
  3. dotnet build
  4. See error

Expected behavior
Build completes successfully

Additional context
I am using .Net 6.

Support Maui Blazor

Is your feature request related to a problem? Please describe.
Hot Reload not working on Maui Blazor projects.

Describe the solution you'd like
Support for Maui Blazor Projects.

Describe alternatives you've considered
There really isn't any.

Additional context
I also get this error the second time I try to build a project:
image

Allow `IOptions<SassCompilerOptions>`

I'm getting sass executable not found on IIS. (Runtime Sass compilation)

Solved with deploying the executable and this:

using AspNetCore.SassCompiler;

[assembly:SassCompiler("Sass\\dart.exe","Sass\\Sass.snapshot")]

Please allow an IOptions<SassCompiler>with the path, this feels so hacky

Exclude lib from build output when no runtime feature used

I would like not to have AspNetCore.SassCompiler.dll included in the build results.

I do not use any library feature which acts at runtime. I would like to have the possibility to use only the MSBuild task without including the AspNetCore.SassCompiler in the resulting binaries (and .deps.json).

Is there a relatively simple way to achieve that? Is it possible to add such functionality to this library?

Source Maps Cannot be Disabled

Describe the bug
Applying the --no-source-map argument has no effect on the generated output. Source maps are always generated for both, normal import files and CSS isolation files.

To Reproduce

  1. Add the --no-source-map flag to the Arguments property in either appsettings.json > SassCompiler or sasscompiler.json (it does not matter whether it is applied in the global Arguments property or in a configuration override)
  2. Build the project in any configuration or publish the project
  3. Inspect the produced output

Expected behavior
The --no-source-map should disable any source map generated by the underlying dart-sass compiler.

Desktop (please complete the following information):

  • OS: Windows 10 (22H2/19045.3086), Visual Studio Enterprise 2022 (17.6.3)
  • Version: 1.63.6

Additional context
The issue occurs in any project environment, regardless of existing/upgraded project or brand-new project.

SassCompilerHostedService: sass command not found, not watching for changes.

Describe the bug
We're getting:

fail: AspNetCore.SassCompiler.SassCompilerHostedService[0]
sass command not found, not watching for changes.

To Reproduce
We dont know really, we use .net6 with several components (MVC + BlazorServer)

with .net5 it worked, some where on the way adding dependencis and upgrade packages, it stopped working.

we use in appsettings.json

"SassCompiler": {
"SourceFolder": "wwwroot/scss",
"TargetFolder": "wwwroot/css",
"Arguments": "--style=compressed"
}

Expected behavior
Should compile and watch

Screenshots

from cmd:

fail: AspNetCore.SassCompiler.SassCompilerHostedService[0]
sass command not found, not watching for changes.

Additional context
Any idea where to start debuging? "sass command not found" what sass command?

Docker support

Currently the code below is throwing an error (as is logical) in a docker container.

builder.Services.AddSassCompiler();

Maybe add a note that it isn't supported in docker container (also discovered that hot reload isn't standard enabled in a docker container).

Blazor WASM Net7.0 - Scss to css seems to happen after building the application

Describe the bug
I am experimenting with Sass and wanted to try Sass out but it seems like the style.css is already built before the compiler starts its task.
image

Is there a workaround?

To Reproduce

  1. Create Blazor WASM .NET 7.0
  2. Add AspNetCore.SassCompiler
  3. Add an isolated Scss file
  4. Build
  5. See no changes

Expected behavior
Scss should be compiled before the styles.css is created

Desktop (please complete the following information):

  • OS: Windows 11
  • Browser: Chrome
  • Version 1.66.0

Make SassCompilerOptions public to configure Options in code instead of appsettings

Is your feature request related to a problem? Please describe.
The current implementation forces to configure the options through an appsettings.json file. A lot of other middleware allows a "services.Configure()" solution, when the Options are public.

A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]

Describe the solution you'd like
I reckon that making SassCompilerOptions public would allow for overriding some variables without needing to update an appsettings.

Describe alternatives you've considered
None.

Additional context
(Having appsettings as copy-if-newer could override some changed files on servers)

Support architecture arm64

Is your feature request related to a problem? Please describe.
We use several CI systems including arm64. Build stops with

/root/.nuget/packages/aspnetcore.sasscompiler/1.53.0/build/AspNetCore.SassCompiler.targets(11,5): error MSB4018: The "CompileSass" task failed unexpectedly. [/builds/[MASKED].csproj]
/root/.nuget/packages/aspnetcore.sasscompiler/1.53.0/build/AspNetCore.SassCompiler.targets(11,5): error MSB4018: System.ComponentModel.Win32Exception (8): An error occurred trying to start process '/root/.nuget/packages/aspnetcore.sasscompiler/1.53.0/build/../runtimes/linux-x64/sass' with working directory '/builds/[MASKED]'. Exec format error [/builds/[MASKED].csproj]

Describe the solution you'd like
Extend your GitHub Workflow update-sass

Describe alternatives you've considered
None

Additional context
None

Support Windows on Arm

On the Arm version of Windows 11, when loading the project, I receive the message Your OS or CPU architecture is currently not supported..
Please support the ARM version of Windows.

I believe it is possible to run the ARM64 version of Dart, but it appears to be still experimental. Therefore, I consider providing the option to run the x64 version of dart.exe as a viable solution to address the issue.

Publish path is incorrect

Describe the bug
Default location when publishing for release seems to default to wwwroot/, not wwwroot/css.

To Reproduce
Steps to reproduce the behavior:

  1. Leave default config untouched and publish for release OR
  2. Try this in appsettings.json
"SassCompiler": {
  "Arguments": "--style=compressed",
  "Configurations": {
    "Release": {
      "TargetFolder": "wwwroot/css"
    }
  }
}

Have tried publishing to a fresh folder, and it won't ever put the file in the css/ folder.

Expected behavior
Compiled file is in wwwroot/css

Desktop (please complete the following information):

  • OS: [e.g. iOS] Windows 11
  • VS 2022 17.7.1

v1.74.1 broke CI build on ubuntu

Describe the bug
It seems the latest update breaks our CI build.
The CSS is just not there or in the wrong place (not sure which) but I see nothing in the logs either.
Building locally on macOS seems fine too.
I suspect the linux64 runtime.

To Reproduce
Steps to reproduce the behaviour:

  1. Use v1.74.1 the CSS is missing after deploying of website https://github.com/MudBlazor/MudBlazor/actions/runs/8602958141
  2. Revert to v1.72.0 everything is fine again
    https://github.com/MudBlazor/MudBlazor/actions/runs/8606643719

Expected behaviour
CSS is deployed to the website.

Error When Building Project

  1. Can't find stylesheet to import
  2. AspNetCore.SassCompiler.targets(34, 5): [MSB3073] The command ""/Volumes/NVMeSSD/bbqchickenrobot/.nuget/packages/aspnetcore.sasscompiler/1.42.1.1/build/../runtimes/osx-x64/sass" --style=compressed "/Volumes/NVMeSSD/bbqchickenrobot/projects/preston/OpenSeaBot/src/OpenSeaScraper/Assets/scss":"/Volumes/NVMeSSD/bbqchickenrobot/projects/preston/OpenSeaBot/src/OpenSeaScraper/wwwroot/css"" exited with code 65.

Getting the following errors when compiling my source code. It's a new project w/o much code. Here is my configuration file:

"SassCompiler": { "SourceFolder": "Assets/scss", "TargetFolder": "wwwroot/css" },

I'm running on MacOS so not sure if this is what's causing the issue.

NuGet Package Info

Hi,

great initiative! Trying it out.
Just wanted to suggest to add Project Url to Nuget info since it's not appearing. Had to search google for this project ;)

Also wanted to say I found a couple of issues while using it. In my case I have 3 .scss files:

_init.scss (imported in both plugins.scss and style.scss)
plugins.scss
style.scss

so unless I specify in the appsettings.json the path\style.scss, the compiler keeps returning an error.

The second issue is that the compiler is having some troubles with my Sass folder organization. I'm using Metronic Theme and this theme has multiple folders for components and plugins. It seems that your compiler tries to create a standalone components.css file when components scss files should be compiled into style.css. Of course, it doesn't work and returns an error since it lacks some variables and mixins.

style.scss contents:

// Initialize
@import "init";
// Components
@import "components/components";

Generated components.css:

/* Error: Undefined variable.
 *   ,
 * 3 |   @each $color, $value in $colors {
 *   |                           ^^^^^^^
 *   '
 *   wwwroot\lib\bootstrap\scss\_root.scss 3:27           @import
 *   wwwroot\lib\metronic\components\components.scss 6:9  root stylesheet */

body::before {
  font-family: "Source Code Pro", "SF Mono", Monaco, Inconsolata, "Fira Mono",
      "Droid Sans Mono", monospace, monospace;
  white-space: pre;
  display: block;
  padding: 1em;
  margin-bottom: 1em;
  border-bottom: 2px solid black;
  content: "Error: Undefined variable.\a   \2577 \a 3 \2502    @each $color, $value in $colors {\a   \2502                            ^^^^^^^\a   \2575 \a   wwwroot\\lib\\bootstrap\\scss\\_root.scss 3:27           @import\a   wwwroot\\lib\\metronic\\components\\components.scss 6:9  root stylesheet";
}

Also, does this project support Sass Modules? I'm using Metronic Theme and they use Modules:

@use 'sass:math';

Thanks!

GenerateScopedCss: CompileSass task hangs if 50 or more SCSS files have to get compiled

Describe the bug

If AspNetCore.SassCompiler is used in a project that has at least 50 SCSS files that have to be compiled it cannot be built.

To Reproduce

Steps to reproduce the behavior

Checkout the following repository: https://github.com/adiessl/SassCompilerTest

dotnet build .\BlazorApp\BlazorApp.csproj --> 50 of 250 SCSS files get compiled, then it hangs

Attempting to stop the build via Ctrl + C does not work, gives the following output:

Attempting to cancel the build...
C:\Users\{UserName}\.nuget\packages\aspnetcore.sasscompiler\1.51.0\build\AspNetCore.SassCompiler.targets(7,5): warning MSB4220: Waiting for the currently executing task "CompileSass" to cancel. [C:\{PathToRepo}\SassCompilerTest\BlazorApp\BlazorApp.csproj]

Killing the process dart.exe via Task Manager makes the build fail eventually.

dotnet build .\BlazorApp\BlazorApp.csproj --> another 50 SCSS files get compiled, then it hangs again.

Stopping the build has to be done the same way than above.


Remarks

  1. Via Process Explorer one can find out that dart.exe is called as follows:

    "C:\Users\{UserName}\.nuget\packages\aspnetcore.sasscompiler\1.51.0\build\..\runtimes\win-x64\src\dart.exe" "C:\Users\{UserName}\.nuget\packages\aspnetcore.sasscompiler\1.51.0\build\..\runtimes\win-x64\src\sass.snapshot" --style=expanded --no-source-map --no-error-css --stop-on-error --no-unicode Components --update
    

    Executing this command directly via PowerShell for example compiles all 250 SCSS files without a problem.

  2. Deleting 201 components with their SCSS files makes the build succeed. That means ...

    • ... 49 components: build succeeds.
    • ... 50 components: build hangs

Expected behavior

The compilation should work and the build should continue.

System info

dotnet --info

.NET SDK (reflecting any global.json):
 Version:   6.0.202
 Commit:    f8a55617d2

Runtime Environment:
 OS Name:     Windows
 OS Version:  10.0.19044
 OS Platform: Windows
 RID:         win10-x64
 Base Path:   C:\Program Files\dotnet\sdk\6.0.202\

Host (useful for support):
  Version: 6.0.4
  Commit:  be98e88c76

Source.scss -> Target.min.css

Is your feature request related to a problem? Please describe.
I want to be able to define the name of the output file.
I am happy to PR this

Describe the solution you'd like
[Obselete]
SourceFolder and TargetFolder
in favour of
Source and Target parameters.
Check if the parameters are directories or files and follow appropriate logic.

Any of the following should be able to work

{
  "SourceFolder": "Styles",
  "TargetFolder": "wwwroot/css",
  "Arguments": "--style=compressed",
}
{
  "Source": "Styles",
  "Target": "wwwroot/css",
  "Arguments": "--style=compressed",
}
{
  "Source": "Styles/MudBlazor.scss",
  "Target": "wwwroot/MudBlazor.min.css",
  "Arguments": "--style=compressed",
}

Describe alternatives you've considered
Renaming file after MSBuildTask completes but this over complicates the project file.
Dart SASS already does this natively

Additional context
Add any other context or screenshots about the feature request here.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.