madskristensen / WebEssentials2012

http://vswebessentials.com
Other
95 stars 46 forks source link

Visual Studio 2012 crashes during/after automatic LESS compilation when minified CSS files are missing #14

Open KernelLeak opened 10 years ago

KernelLeak commented 10 years ago

In our project we use LESS and CSS minification, but we don't want to check the minified CSS files into Subversion since they are easily rebuilt during the build - or so we thought.

The problem is that when Web Essentials is configured to automatically compile LESS files on build, it'll then produce an exception if the minified CSS file doesn't already exist (see below) and a second or two later VS2012 crashes...

The exception is as follows:

System.IO.FileNotFoundException: Could not find file 'C:\Lokale Dateien\eCS\GSIS\eCS.GSIS\Content\Content.min.css'.
File name: 'C:\Lokale Dateien\eCS\GSIS\eCS.GSIS\Content\Content.min.css'
   at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
   at System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, Int32 rights, Boolean useRights, FileShare share, Int32 bufferSize, FileOptions options, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy, Boolean useLongPath, Boolean checkHost)
   at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, FileOptions options, String msgPath, Boolean bFromProxy, Boolean useLongPath, Boolean checkHost)
   at System.IO.StreamReader..ctor(String path, Encoding encoding, Boolean detectEncodingFromByteOrderMarks, Int32 bufferSize, Boolean checkHost)
   at System.IO.File.InternalReadAllText(String path, Encoding encoding, Boolean checkHost)
   at System.IO.File.ReadAllText(String path)
   at MadsKristensen.EditorExtensions.LessProjectCompiler.MinifyFile(String lessFileName, String source)
   at MadsKristensen.EditorExtensions.LessProjectCompiler.Completed(CompilerResult result)
   at MadsKristensen.EditorExtensions.LessCompiler.ProcessExited(Object sender, EventArgs e)
   at System.Diagnostics.Process.OnExited()
   at System.Diagnostics.Process.RaiseOnExited()
   at System.Diagnostics.Process.CompletionCallback(Object context, Boolean wasSignaled)
   at System.Threading._ThreadPoolWaitOrTimerCallback.WaitOrTimerCallback_Context(Object state, Boolean timedOut)
   at System.Threading._ThreadPoolWaitOrTimerCallback.WaitOrTimerCallback_Context_f(Object state)
   at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
   at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
   at System.Threading._ThreadPoolWaitOrTimerCallback.PerformWaitOrTimerCallback(Object state, Boolean timedOut)

Why would the LESS compiler ever need to read the existing minified file?

If all .min.css files exist (i.e. by opening the LESS file by hand and saving it again) the build finishes without problems and Visual Studio doesn't crash.

KernelLeak commented 10 years ago

Looking at MinifyFile in LessProjectCompiler.cs it seems the logic in there is backwards - it first reads the file's contents (to see if they've changed) and only when it knows that the contents have changed it'll check if the file even exists... :/

KernelLeak commented 10 years ago

Hello? Is there anybody still reading this?

zpqrtbnk commented 10 years ago

Ping. Same issue here, which means that .CSS files have to be version-controlled.

franklin-ross commented 10 years ago

Same with .coffee files to .js files. Initially we just let VS check everything into git, then we got sick of merging JS files which should get regenerated anyway and removed them all. But then we have to go through and manually compile each of the files first. Not so bad if you just fire up the coffee command line compiler and tell it to compile all of the coffee in the solution folder, but it still seems pretty dumb to have to do so.

charlesj commented 10 years ago

I just ran into this as well. It would be nice if it wasn't possible to crash VS during a build and just threw a build error instead. If I get a chance, I'll look at the code to see if I can do this.