johan-v-r / LibSassBuilder

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

SCSS files get excluded by default when added through Visual Studio #15

Closed mooski closed 3 years ago

mooski commented 3 years ago

Firstly, I just want to say that this is a great tool and it's worked for me where others have failed - so thank you for providing this for us all to use!

I have 2 issues with it which I'm hoping you can help with. I'll describe these separately - the first issue is how SCSS files seem to get excluded by default, and I'm not sure why this is happening or what's causing it. This is happening in a Blazor project of mine, but I've tried in a simple console application too and the same thing happens. This is happening in Visual Studio so I don't know if this is interfering somehow. These are the repro steps:

Visual Studio 2019, version 16.9.0. LibSassBuilder 1.6.1.

  1. Create a new C# console application in Visual Studio - choose .NET 5.0 as the target framework.
  2. Add the LibSassBuilder NuGet package to the project.
  3. In Solution Explorer, right-click on the project, choose Add > New Item, and add a new SCSS style sheet, e.g. StyleSheet1.scss.
  4. Build the solution, and note that the CSS does NOT get generated.
  5. Furthermore, right-click on the project in Solution Explorer and choose 'Edit Project File'. Note that the following elements have been automatically added:
  <ItemGroup>
    <SassFile Remove="StyleSheet1.scss" />
  </ItemGroup>
  1. Remove these offending elements.
  2. Build the solution and note that the CSS is now generated correctly.

This happens every time I add a new SCSS file, which is quite irritating as every time I have to go and manually remove this element from the .csproj file.

I hope you can help me to understand why this is happening.

johan-v-r commented 3 years ago

Hi Mark, thanks for the detailed steps!

I was able to replicate this issue, even without LibSassBuilder, as it seems related to this VS issue.
Replicate by just having this in the .csproj and add a new .scss file:

<ItemGroup>
    <FooFile Include="**/*.scss" />
</ItemGroup>

By tracking the files in ItemGroup - VS just adds these extra elements for some reason:

VS is trying to avoid double-including the same file. The Microsoft.Net.Sdk has a None "glob" that includes everything under the project root that isn't a Compile or EmbeddedResource. Opt out of that by setting EnableDefaultNoneItems property to false.

Unfortunately those suggestions didn't work for me. @JelleHissink do you have any thoughts on this?

JelleHissink commented 3 years ago

Hi, I noticed the same, googled... found a fix, did not yet have time to implement it. Will make this a prio.... I might have some time this evening.

Regards, Jelle

JelleHissink commented 3 years ago

I found some time during my lunch break...

johan-v-r commented 3 years ago

Awesome thanks @JelleHissink !

This fix is available in v1.6.2

mooski commented 3 years ago

Thanks @johan-v-r and @JelleHissink for taking a look so quickly and fixing the issue.

I hadn't realised that this is a Visual Studio issue, but I'm glad that you managed to find a fix for it - MSBuild is something of a mystery to me so there's no way that I've have got to a solution myself!

Thanks again.