0

I have the following code in a project I try to upgrade the "dotless" NuGet package from the "1.2.2.0" to the latest (at moment "1.4.0.0"):

private void GetStylesheetContent(HttpContext context, string name)
{
    var conf = BundleConfigSectionHandler.GetConfig();
    var elt = conf.Stylesheets.GetBundle(name); 
    if (elt != null) {
        Minifier minifier = null;
        if (_conf.Stylesheets.Minify) {
            minifier = new Minifier();
        }    
        var files = elt.ListFiles();
        var existingFiles = new List<string>();    
        StringBuilder buffer = new StringBuilder();

        foreach (var file in files) {
            var physicalFile = context.Request.MapPath(file);
            if (File.Exists(physicalFile)) {
                existingFiles.Add(physicalFile);                        
                string content;
                var path = VirtualPathUtility.GetDirectory(file);
                if (file.EndsWith(".less", StringComparison.OrdinalIgnoreCase)) 
                {
                    var reader = new dotless.Core.Input.VirtualFileReader();
                    var localpath = VirtualPathUtility.ToAbsolute(file);
                    content = reader.GetFileContents(localpath);
                    var parse = new Parser();
                    parse.Importer = new Importer(reader);

        /*Error>*/ parse.Importer.Paths.Add(VirtualPathUtility.ToAbsolute(path));

                    var eng = new LessEngine(parse);
                    content = eng.TransformToCss(content, localpath);

The error is on the third line from bottom. It says:

Error 417 'dotless.Core.Importers.IImporter' does not contain a definition for 'Paths' and no extension method 'Paths' accepting a first argument of type 'dotless.Core.Importers.IImporter' could be found (are you missing a using directive or an assembly reference?)

Is a pity that the team didn't left the old method with an [Obsolete] attribute and suggestion to upgrade. Does anyone know how to replace the "Importer.Paths.Add" method ?

serhio
  • 28,010
  • 62
  • 221
  • 374
  • I know it's not the answer you're looking for, but we're moving away from dotless in favor of just compiling the less dusting a build (e.g. on our staging server). Probably more work on the bundles, but until/unless dotless catches up with less js, it's hard to justify using it. So that's an option. – Carl Bussema Apr 04 '14 at 01:30

1 Answers1

0

I'm not that familiar with the inner workings of dotless. But looking at the source code for the Importer. paths has been protected since version version 1.2.3. Looking around at the class a little more, it seems like you need to use an instance of dotless.Parser.Tree.Import to add your paths manually.

It does look like this is pretty far off the normal dotless path. So it wouldn't surprise me if the API is a little unstable in these areas. You also may want to look at how bundling works in a question like How to use ASP.Net MVC 4 to Bundle LESS files in Release mode? to see how they handle all the dotless classes.

Community
  • 1
  • 1
Steven V
  • 16,357
  • 3
  • 63
  • 76
  • I tried just for test to do `parse.Importer.Imports.Add(...);` to compile the project. but not tested yet (and actually have no clear idea how to test) – serhio Mar 27 '14 at 08:44