Search code examples
c#cssasp.net.netautoprefixer

Bundler Transformer Autoprefixer postprocess file knowing psysical path


I have a project in ASP.NET MVC and I want to use Bundler Transformer Autoprefixer to process my css files. My use case is a little bit unusual and I need to process css content from physical path like "C:\somewhere\style.css". I think I can use AutoprefixCssPostProcessor class to do so, but it allows to process assets, that require virtual path to the file. Is it possible to postprocess such file using AutoprefixCssPostProcessor?


Solution

  • Works:

        var tempFileVirtualPath = $"/App_Data/Temp/{Guid.NewGuid()}.css"        
        System.IO.File.WriteAllText(Server.MapPath(tempFileVirtualPath), initialCssContent);
        var autoprefixer = new AutoprefixCssPostProcessor();
        var content = autoprefixer.PostProcess(new Asset(tempFileVirtualPath)).Content;
        var absolutePath = "C:\somewhere\style.css";
        System.IO.File.WriteAllText(absolutePath, content);