2014-03-26 54 views
0

我在項目中有以下代碼我嘗試將「1.2.2.0」中的"dotless" NuGet package升級到最新版本(當時「1.4.0.0」 ):已升級的dotLess錯誤:IImporter不包含'路徑'的定義

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); 

該錯誤位於底部的第三行。它說:

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?)

可惜的是,球隊並沒有將原來的方法與[過時]屬性,建議升級。 有誰知道如何替換「Importer.Paths.Add」方法?

+0

我知道這不是你正在尋找的答案,但是我們正在從無點轉移,轉而編寫更少的灰塵(例如,在我們的登臺服務器上)。在捆綁上可能會有更多的工作,但是直到/除非點無所事事地趕上更少的js,否則很難證明它的使用是合理的。所以這是一個選擇。 –

回答

0

我並不那麼熟悉無點的內部運作。但看看進口商the source code。從版本1.2.3開始,paths已經protected。再看看這個類,看起來你需要使用dotless.Parser.Tree.Import的實例手動添加你的路徑。

它確實看起來很像正常的無點路徑。所以,如果這些API在這些領域有點不穩定,我不會感到驚訝。你也可能想看看如何在如How to use ASP.Net MVC 4 to Bundle LESS files in Release mode?這樣的問題中捆綁工作,看看他們如何處理所有的無點類。

+0

我只是想測試做'parse.Importer.Imports.Add(...);'來編譯項目。但尚未測試(實際上並沒有明確的想法如何測試) – serhio

相關問題