johan-v-r / LibSassBuilder

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

Build failed with NET6 #39

Closed enricobenedos closed 1 year ago

enricobenedos commented 2 years ago

Good morning,

we migrated our Blazor WASM project to .NET 6 and now we are not able to compile anymore. It seems that this library asks to use .NET 5 SDK instead of .NET 6 one.

Microsoft (R) Build Engine version 17.0.0+c9eb9dd64 for .NET
Copyright (C) Microsoft Corporation. All rights reserved.

  Determining projects to restore...
  Restored D:\Projects\my-project\MyProject.GUI\MyProject.GUI.csproj (in 651 ms).
  It was not possible to find any compatible framework version
  The framework 'Microsoft.NETCore.App', version '5.0.0' (x64) was not found.
    - The following frameworks were found:
        3.1.16 at [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
        3.1.18 at [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
        3.1.19 at [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
        3.1.20 at [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
        6.0.0 at [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]

  You can resolve the problem by installing the specified framework and/or SDK.

  The specified framework can be found at:
    - https://aka.ms/dotnet-core-applaunch?framework=Microsoft.NETCore.App&framework_version=5.0.0&arch=x64&rid=win10-x64
C:\Users\enricobenedos\.nuget\packages\libsassbuilder\1.6.4\build\LibSassBuilder.targets(90,5): error MSB3073: The command "dotnet "C:\Users\enricobenedos\.nuget\packages\libsassbuilder\1.6.4\build\../tool/LibSassBuilder.dll" files "D:\Projects\my-project\MyProject.GUI\wwwroot\css\app.scss" "D:\Projects\my-project\MyProject.GUI\wwwroot\css\variables.scss" --outputstyle compressed --level default " exited with code -2147450730. [D:\Projects\my-project\MyProject.GUI\MyProject.GUI.csproj]

Thanks

louisoftokyo commented 2 years ago

Having the same problem.

JelleHissink commented 2 years ago

I had this issue too... seems that there is a change after installing VS2022. libsassbuilder now tries to load the wrong libsass.dll (x86 instead of x64).

On my machine I noticed dotnet build was also not working, I uninstalled my dotnet (32 bit from program files (x86)). And then all worked again.

I think a possible solution would be to force libsassbuilder.exe to run only as x86 or x64. But I don't have time to investigate further, and it seems my problem is solved by uninstalling the dotnet-sdk from x86 mode.

JelleHissink commented 2 years ago

"C:\Program Files (x86)\dotnet\dotnet.exe" --info vs "C:\Program Files\dotnet\dotnet.exe" --info

X64 has an sdk, the x86 does not have an sdk registered on my machine after I uninstalled VS2019 and installed VS2022.

JelleHissink commented 2 years ago

This is actually where the problem originates... for some it cannot find dotnet.exe, or no registered runtime. The call to dotnet libsassbuilder.dll causes the dll to be loaded in context of the x86 or x64 executable, and on my machine it is missing the native sass library.

JelleHissink commented 2 years ago

If you want this fix now before Johan can release a new version, you might want to look at the changes I made in the files.

It is easy to do on your own machine to get going again: %APPDATA%.nuget\packages\libsassbuilder\1.6.4\build\LibSassBuilder.targets

%APPDATA%.nuget\packages\libsassbuilder\1.6.4\build\LibSassBuilder.props

See: https://github.com/johan-v-r/LibSassBuilder/pull/41/files

adamhathcock commented 2 years ago

thanks for the info. I don't think that temporary fix is workable in a dockerized CI environment though

JelleHissink commented 2 years ago

@adamhathcock I know it does not work for all situations. But for me at least it enabled me to continue working locally. And in a linux environment the whole x86/x64 issue might not be a factor.

adamhathcock commented 2 years ago

The exact error I get is:

 /home/runner/.nuget/packages/libsassbuilder/1.6.4/build/LibSassBuilder.targets(90,5): error MSB3073: The command "dotnet "/home/runner/.nuget/packages/libsassbuilder/1.6.4/build/../tool/LibSassBuilder.dll" files "/home/runner/work/case-sites/case-sites/CaseFunnel.CaseToAnswer/wwwroot/css/caseStyle.scss" --outputstyle compressed --level default " exited with code 150. [/home/runner/work/case-sites/case-sites/CaseFunnel.CaseToAnswer/CaseFunnel.CaseToAnswer.csproj]
  It was not possible to find any compatible framework version
  The framework 'Microsoft.NETCore.App', version '5.0.0' (x64) was not found.
    - The following frameworks were found:
        6.0.0 at [/home/runner/.dotnet/shared/Microsoft.NETCore.App]

  You can resolve the problem by installing the specified framework and/or SDK.

  The specified framework can be found at:
    - https://aka.ms/dotnet-core-applaunch?framework=Microsoft.NETCore.App&framework_version=5.0.0&arch=x64&rid=ubuntu.20.04-x64

if you had to rename the file from dll to exe that would explain it for me. Though, not sure how the build artifact changed

adamhathcock commented 2 years ago

Maybe it's as simple as having to multi-target the exe for .net6? I guess I thought it would just work on the new runtime. Not sure why it wants net5 specifically

JelleHissink commented 2 years ago

The problem starts with half of the people having this issue that they have a x86 version of dotnet.exe without an x86 sdk or runtime, this is counter intuitive and a strange requirement.

Other half of the problem could be solved with having the .dll run in both x86 and x64 environments. But before even getting to that point dotnet.exe already fails to start.

johan-v-r commented 2 years ago

Hi All - there's a new release v2.0.0 that targets .NET 6 Please update and let us know... πŸ‘

adamhathcock commented 2 years ago

Appears to work for me. Thanks for the quick update!

enricobenedos commented 2 years ago

It newly build on our CI with .NET 6! Thanks

JelleHissink commented 2 years ago

I finally came to upgrading my project, at my end this still fails:

10>Sass compile files
10>Unhandled exception. LibSassHost.SassCompilerLoadException: During loading of Sass compiler error has occurred. Most likely it happened, because the 'libsass.dll' assembly or one of its dependencies was not found. Try to install the LibSassHost.Native.win-x86 package via NuGet. ---> System.DllNotFoundException: Unable to load DLL 'libsass' or one of its dependencies: The specified module could not be found. (0x8007007E)
10>   at LibSassHost.Internal.Native.Sass_Api.libsass_version()
10>   at LibSassHost.Internal.SassCompilerProxy.GetVersion()
10>   at LibSassHost.SassCompiler.Initialize()
10>   at LibSassHost.SassCompiler.Initialize()
10>   at LibSassHost.SassCompiler.CompileFile(String inputPath, String outputPath, String sourceMapPath, CompilationOptions options)
10>   at LibSassBuilder.Program.CompileFilesAsync(IEnumerable`1 sassFiles) in D:\a\LibSassBuilder\LibSassBuilder\src\LibSassBuilder\Program.cs:line 0
10>   at LibSassBuilder.Program.<>c.<<Main>b__0_2>d.MoveNext() in D:\a\LibSassBuilder\LibSassBuilder\src\LibSassBuilder\Program.cs:line 44
10>--- End of stack trace from previous location ---
10>   at CommandLine.ParserResultExtensions.WithParsedAsync[T](ParserResult`1 result, Func`2 action)
10>   at LibSassBuilder.Program.Main(String[] args) in D:\a\LibSassBuilder\LibSassBuilder\src\LibSassBuilder\Program.cs:line 22
10>   at LibSassBuilder.Program.<Main>(String[] args)
10>
10>C:\Users\JelleJHissink\.nuget\packages\libsassbuilder\2.0.0\build\LibSassBuilder.targets(90,5): error MSB3073: The command "dotnet "C:\Users\JelleJHissink\.nuget\packages\libsassbuilder\2.0.0\build\../tool/LibSassBuilder.dll" files "C:\Work\TEWC\TestUpgrade\Source\MijnPlannen\wwwroot\styling\site.scss" --outputstyle compressed --level default " exited with code -532462766.

On my machine I have both the 6.0 x86 and x64 installed now... however my dotnet.exe that is on my PATH first is the x86 version, not the x64. So it still fails when calling dotnet.exe like this. The tool should not depend on randomness like the order of the PATH environment. I still think calling the tool without dotnet and just call the .exe (at least on windows machines). Or otherwise include both x86 and x64 versions of the dependencies.

JelleHissink commented 1 year ago

I know this issue is closed, but on my end this still depends on the order in the PATH of dotnet.exe. I ran into this issue once more on a different laptop. If the x86 version comes first, the tool is run in x86 mode on windows. The PR that I made fixes this, the same issue exists in the dart version. However all pull requests are stale on both projects. What is the status? Should I fork, because I want to make some more changes with regards to hot reloading. But I don't know if it is worth investing the time?

johan-v-r commented 1 year ago

Hi @JelleHissink - I left a comment on that PR asking if that works for Linux as well?

I think we might need to add the LibSassHost.Native.win-x86 dependency.

Apologies I wasn't aware this was still an issue, will reopen.

johan-v-r commented 1 year ago

New version 2.0.3 includes #41 to resolve the x86 issue, thanks @JelleHissink πŸ‘