These assets are not a style sheet bug in BundleTransformer

I ran into this annoying error telling me that .less files are not style sheets. Oh yeah.

BundleTransformer.Core.Validators.InvalidAssetTypesException: These assets are not stylesheets: "Site / Content / Stylesheets / Less / style.less

I have BundleTransformer.Less (as a package).

My BundleConfig.cs:

bundles.Add(new LessStyleBundle("~/SiteCSS").IncludeDirectory("~/Content/Stylesheets/Less", "*.less"));

      

My LessStyleBundle class:

 public sealed class LessStyleBundle : StyleBundle
    {

        private static readonly IBundleTransform _cssTransformer = new StyleTransformer();
        private static readonly IBundleTransform _cssMinify = new CssMinify();

        public LessStyleBundle(string virtualPath)
            : base(virtualPath)
        {
            Orderer = new NullOrderer();
            Transforms.Add(_cssTransformer);
            Transforms.Add(_cssMinify);
        }
    }

      

And rendering the layout:

@Styles.Render("~/SiteCSS")

      

Does anyone face the same problem? Thanks a lot for any advice.

+3


source to share


2 answers


Check the file Web.config

. There should be the following settings:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
    <bundleTransformer xmlns="http://tempuri.org/BundleTransformer.Configuration.xsd">
        <core ...>
            <css ...>
                ...
                <fileExtensions>
                    <add fileExtension=".css" assetTypeCode="Css" />
                    <add fileExtension=".less" assetTypeCode="Less" />
                    ...
                </fileExtensions>
                ...
            </css>
            ...
        </core>
    </bundleTransformer>
</configuration> 

      



Also, I don't recommend writing your own LessStyleBundle

class. Better to use the class BundleTransformer.Core.Bundles.CustomStyleBundle

and install the BundleTransformer.MicrosoftAjax module (read the file after installation readme.txt

).

+4


source


Install the nuget BundleTransformer.Less package. This will fix the problem.



check package.config

+2


source







All Articles