Resolving relative paths for @import and @insert directives when using the compiler.

296 views
Skip to first unread message

Darragh

unread,
Mar 15, 2010, 9:30:26 AM3/15/10
to DotLess (Less Css for .NET)
Hi,

My @include and @insert directives are not working as expected, and I
think this is because the compiler is unable to resolve the file
locations. It appears the compiler expects the locations given for
these directives to be relative to the 'CurrentWorkingDirectory' (i.e.
the path from which the compiler is run), rather than relative to the
main .less file which includes the directive.

Does this make sense? Is this by design, or is this a bug?


Daniel Hölbling

unread,
Mar 15, 2010, 9:33:16 AM3/15/10
to dot...@googlegroups.com
Well .. sort of both.
The code in question is shared between HttpHandler based approach and the compiler approach.
I will write a fix that sets the current working directory to the location of the first .less file the compiler is executing.
Thanks for highlighting that problem.

greetings Daniel

Darragh

unread,
Mar 15, 2010, 10:19:37 AM3/15/10
to DotLess (Less Css for .NET)
Thanks for the speedy reply....

Actually I was able to fix this issue myself by adding the following
lines to dotless.Compiler -> Program.cs

var inputFilePath = arguments[0];
System.IO.Directory.SetCurrentDirectory(System.IO.Path.GetDirectoryName(System.IO.Path.GetFullPath(inputFilePath)));
inputFilePath = System.IO.Path.GetFileName(inputFilePath);

I tried getting this to work by looking at TreeBuilder.cs in the
dotless.Core project initially but couldn't get it to work....ymmv

Regards,
Darragh


On Mar 15, 1:33 pm, Daniel Hölbling <hoelblin...@gmail.com> wrote:
> Well .. sort of both.
> The code in question is shared between HttpHandler based approach and the
> compiler approach.
> I will write a fix that sets the current working directory to the location
> of the first .less file the compiler is executing.
> Thanks for highlighting that problem.
>
> greetings Daniel
>

James Foster

unread,
Mar 15, 2010, 9:08:54 PM3/15/10
to dot...@googlegroups.com
There's an extension to this.

When you import a file, any imports inside that file should be relative to that file. I implemented this in the Grammar branch but I'm not sure changing the current working directory is the right thing to do when running under ASP.NET??

But this isn't necessary for the time being. I just thought I'd mention it and see what you thought.

Daniel Hölbling

unread,
Mar 25, 2010, 4:18:36 AM3/25/10
to dot...@googlegroups.com
I just committed a new version that sets the current workingdirectory to the file's path so all imports are relative to the .less file now.

You can grab the latest Version from our build server.

greetings Daniel
Reply all
Reply to author
Forward
0 new messages