johan-v-r / LibSassBuilder

Sass builder for .NET projects
MIT License
99 stars 14 forks source link

EnableDefaultSassItems - Throwing Exceptions and Stopping Build #40

Closed chicklinmighall closed 2 years ago

chicklinmighall commented 2 years ago

Hi,

New to the library and attempting to use this on a DOTNET 5 Blazor WASM app. Everything is okay but as soon as I try and use EnableDefaultSassItems, I get issues.

Environment

Windows 10 21H1 (19043) Visual Studio 2019 (v 16.11.5) Blazor WASM NET5 (NETCORE 3.1) LibSassBuilder Version 1.6.4

Issue

If I have the following in my CSPROJ, I randomly get build exceptions

<PropertyGroup>
    <!--outputstyle option-->
    <LibSassOutputStyle>compressed</LibSassOutputStyle>
    <LibSassOutputStyle Condition="'$(Configuration)' == 'Debug'">expanded</LibSassOutputStyle>
    <!--level option-->
    <LibSassOutputLevel>verbose</LibSassOutputLevel>
    <!--msbuild output level-->
    <LibSassMessageLevel>High</LibSassMessageLevel>
    <EnableDefaultSassItems>false</EnableDefaultSassItems>
  </PropertyGroup>

  <ItemGroup>
    <!--add files manually-->
    <SassFile Include="Pages/**/*.scss"/>
    <!--<SassFile Include="wwwroot/**"/>-->
  </ItemGroup>

And I get the following in the "Build -> Output"

LibSassBuilder 1.6.3
Copyright (C) 2021 Johan van Rensburg

ERROR(S):
 A required value not bound to option name is missing.

 -l, --level      Specify the level of output (silent, default, verbose)

 --outputstyle    Specify the style of output (compressed, condensed, nested,
                   expanded)

  --help           Display this help screen.

  --version        Display version information.

  value pos. 0     Required. File(s) to process

C:\Users\[username]\.nuget\packages\libsassbuilder\1.6.4\build\LibSassBuilder.targets(90,5): error MSB3073: The command "dotnet "C:\Users\[username]\.nuget\packages\libsassbuilder\1.6.4\build\../tool/LibSassBuilder.dll" files  --outputstyle expanded --level verbose " exited with code 1.

As soon as I remove the <EnableDefaultSassItems>false</EnableDefaultSassItems> the project builds again without issue (note it does correctly build/process scss files when this is removed). On my main project where I first noticed this issue, I did find that sometimes the issue only appears when I clean/rebuild. Therefore, to ensure this is not something specific to this project, I have created another simple project and have been able to replicate the issue on that as well.

I hope this makes sense, I need to use this as I am needing to ignore some of the "Vendor" scss files and the simplest way was to create an "allowed list".

I do note that the Build Output does say that I am using LibSassBuilder 1.6.3, I don't have that installed (only started using this library a couple of days ago) so is there any chance there is a dll/version mismatch somewhere?

Another random thing I have noticed is that I have to include <None Include="**/*.scss" /> when using <EnableDefaultSassItems>false</EnableDefaultSassItems> or the SASS files disappear. Not sure if that helps narrow anything down, I believe #15 & #27 mentions this had been fixed/wasn't needed anymore.

I hope this makes sense, let me know if you need anything further. Hopefully, I am not being thick and just have missed something/haven't implemented it correctly. Thanks in advance.

amura11 commented 2 years ago

I ran into this same issue. It seems to be an issue with 1.6.4, downgrading to 1.6.3 got the build working again. The one downside is you run into the issue mentioned in #27 but you can work around that too using the <None Include="**/*.scss" />. This is an example of my config:

    <PropertyGroup>
        <EnableDefaultSassItems>false</EnableDefaultSassItems>
        <LibSassOutputStyle>compressed</LibSassOutputStyle>
        <LibSassOutputStyle Condition="'$(Configuration)' == 'Debug'">expanded</LibSassOutputStyle>
        <LibSassOutputLevel>verbose</LibSassOutputLevel>
    </PropertyGroup>

    <ItemGroup>
        <!-- Don't compile non-razor SCSS files but still show them in the project -->
        <None Include="**/*.scss" />
        <SassFile Include="**/*.razor.scss" />
        <SassFile Include="wwwroot/**/*.scss" />
    </ItemGroup>

Hopefully this helps!

Edit

After using this I found one issue with using <None Include="**/*.scss" />, changes made to files in this location won't be considered changed by VS and you SCSS may not be rebuilt. If you want changes to these files to cause a rebuild I found using <Content Include="**/*.scss" /> worked.

afuersch commented 2 years ago

I upgraded my Blazor Project to .NET6 and updated the library to version 2.0.0. Same as @chicklinmighall I have the EnableDefaultSassItems set to false and experience the same issue. Downgrading to a previous version is not an option, since my docker container won't build. Since the setting works with version 1.6.3 and not with 1.6.4 anymore, I investigated the code changes between the two versions and found the bug and a workaround to make it work.

The bug: If you have a look at commit 35dbf550dc09e1b77bdd2aa01e5256556b5a7838 of PR #28 you will see that the SassFile items will be aggregated to a SassFilesToCompile item, which contains the list of files to compile. But only when the setting EnableDefaultSassItems is true, else the SassFilesToCompile file list is empty and this is the reason why the error is thrown:

A required value not bound to option name is missing.

  value pos. 0     Required. File(s) to process

The workaround: You can just insert all your SassFile items again as SassFileToCompile items and your files are passed to the libsass compiler and the compilation works. For example:

<ItemGroup>
    <!--add files manually-->
    <SassFile Include="Pages/**/*.scss"/>
    <SassFile Include="wwwroot/**"/>
    <SassFileToCompile Include="Pages/**/*.scss"/>
    <SassFileToCompile Include="wwwroot/**"/>
</ItemGroup>

@johan-v-r I hope this issue gets fixed soon, since it breaks the compilation if the EnableDefaultSassItems is not true.

johan-v-r commented 2 years ago

Hi - thanks for the all the input!

@afuersch you are right, I have moved that SassFileToCompile to a default ItemGroup so it always (unconditionally) gets evaluated.

This change has been published with v2.0.1 - please check if that works.

afuersch commented 2 years ago

@johan-v-r Thanks a lot for the fix. I upgraded and the compilation works again.

chicklinmighall commented 2 years ago

Have recently updated and can confirm this work for me now, thanks for the update @johan-v-r. Happy to close this issue off.