johan-v-r / LibSassBuilder

Sass builder for .NET projects
MIT License
98 stars 15 forks source link

The process cannot access CSS file on build #43

Closed enchev closed 2 years ago

enchev commented 2 years ago

Thanks for the great tool!

I receive often the following error on Visual Studio project rebuild:

1>Sass compile files
1>Sass compile files
1>Unhandled exception. System.IO.IOException: The process cannot access the file 'C:\Users\vladi\OneDrive\Documents\GitHub\blazor.radzen.com\Radzen.Blazor\themes\dark-base.css' because it is being used by another process.
1>   at Microsoft.Win32.SafeHandles.SafeFileHandle.CreateFile(String fullPath, FileMode mode, FileAccess access, FileShare share, FileOptions options)
1>   at Microsoft.Win32.SafeHandles.SafeFileHandle.Open(String fullPath, FileMode mode, FileAccess access, FileShare share, FileOptions options, Int64 preallocationSize)
1>   at System.IO.Strategies.OSFileStreamStrategy..ctor(String path, FileMode mode, FileAccess access, FileShare share, FileOptions options, Int64 preallocationSize)
1>   at System.IO.Strategies.FileStreamHelpers.ChooseStrategyCore(String path, FileMode mode, FileAccess access, FileShare share, FileOptions options, Int64 preallocationSize)
1>   at System.IO.Strategies.FileStreamHelpers.ChooseStrategy(FileStream fileStream, String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, FileOptions options, Int64 preallocationSize)
1>   at System.IO.File.AsyncStreamReader(String path, Encoding encoding)
1>   at System.IO.File.InternalReadAllTextAsync(String path, Encoding encoding, CancellationToken cancellationToken)
1>   at LibSassBuilder.Program.CompileFilesAsync(IEnumerable`1 sassFiles) in D:\a\LibSassBuilder\LibSassBuilder\src\LibSassBuilder\Program.cs:line 97
1>   at LibSassBuilder.Program.<>c.<<Main>b__0_2>d.MoveNext() in D:\a\LibSassBuilder\LibSassBuilder\src\LibSassBuilder\Program.cs:line 44
1>--- End of stack trace from previous location ---
1>   at CommandLine.ParserResultExtensions.WithParsedAsync[T](ParserResult`1 result, Func`2 action)
1>   at LibSassBuilder.Program.Main(String[] args) in D:\a\LibSassBuilder\LibSassBuilder\src\LibSassBuilder\Program.cs:line 22
1>   at LibSassBuilder.Program.<Main>(String[] args)
1>Sass files compiled
1>C:\Users\vladi\.nuget\packages\libsassbuilder\2.0.1\build\LibSassBuilder.targets(95,5): error MSB3073: The command "dotnet "C:\Users\vladi\.nuget\packages\libsassbuilder\2.0.1\build\../tool/LibSassBuilder.dll" files "C:\Users\vladi\OneDrive\Documents\GitHub\blazor.radzen.com\Radzen.Blazor\themes\dark-base.scss" "C:\Users\vladi\OneDrive\Documents\GitHub\blazor.radzen.com\Radzen.Blazor\themes\dark.scss" "C:\Users\vladi\OneDrive\Documents\GitHub\blazor.radzen.com\Radzen.Blazor\themes\default-base.scss" "C:\Users\vladi\OneDrive\Documents\GitHub\blazor.radzen.com\Radzen.Blazor\themes\default.scss" "C:\Users\vladi\OneDrive\Documents\GitHub\blazor.radzen.com\Radzen.Blazor\themes\humanistic-base.scss" "C:\Users\vladi\OneDrive\Documents\GitHub\blazor.radzen.com\Radzen.Blazor\themes\humanistic.scss" "C:\Users\vladi\OneDrive\Documents\GitHub\blazor.radzen.com\Radzen.Blazor\themes\software-base.scss" "C:\Users\vladi\OneDrive\Documents\GitHub\blazor.radzen.com\Radzen.Blazor\themes\software.scss" "C:\Users\vladi\OneDrive\Documents\GitHub\blazor.radzen.com\Radzen.Blazor\themes\standard-base.scss" "C:\Users\vladi\OneDrive\Documents\GitHub\blazor.radzen.com\Radzen.Blazor\themes\standard.scss" --outputstyle expanded --level default " exited with code -532462766.

After several project clean/rebuild commands the error goes away till the next change in some of the scss files. The csproj and the scss files are located here, your input will be greatly appreciated!

enchev commented 2 years ago

We've found that this is caused by the parallel builds with multiple target frameworks, i.e. <TargetFrameworks>netstandard2.1;net5.0</TargetFrameworks> Fixed with condition.