WebOptimizer icon indicating copy to clipboard operation
WebOptimizer copied to clipboard

AddLessBundle Works in Dev, but not when I publish to Azure.

Open tpspencer opened this issue 3 years ago • 2 comments

When I publish my core3.1 website to Azure the path to the css files returns a 404 www.mysite.com/css/StyleBundle.css

Here is my config.

app.UseWebOptimizer(); //placed before UseStaticFiles
app.UseStaticFiles();

var cssSettings = new CssSettings();
var jsSettings = new CodeSettings();

if (_Environment.IsDevelopment())
{
	cssSettings = CssSettings.Pretty();
	jsSettings = CodeSettings.Pretty();
}

services.AddWebOptimizer(options =>
{
    //css/Less bundles
    options.AddLessBundle("/css/BootstrapBundle.css",
        "Styles/bootstrapmac.less")
        .MinifyCss(cssSettings)
        .UseContentRoot();
});

tpspencer avatar Apr 28 '22 15:04 tpspencer

Update: It looks like it is AddLessBundle that does not work. When I add the following AddCssBundle code, the bundle gets added.


               options.AddCssBundle("/css/ab.css",
                    "Styles/a.css",
                    "Styles/b.css")
                .UseContentRoot();

tpspencer avatar Apr 28 '22 19:04 tpspencer

It turns out that UseContentRoot() does not work in Azure.

When I moved my Styles and Scripts folder from the root of my web project into the wwwroot folder and removed UseContentRoot() everything started to work.

tpspencer avatar Apr 28 '22 20:04 tpspencer