Wrong paths in css after dotnet bundle on GNU/Linux

147 Views Asked by At

Trying to port a web project from dotnet on Windows to dotnet on GNU/Linux. The C# code works fine, but I'm having problems with the minification of dotnet bundle. In minified output css, paths to for instance images are replaced with the path to the css file itself.

I have reduced it to a small test case where the problem can be reproduced.

Creating an empty directory with the following files (look at the out.min.css and compare the full filesystem path to the background url with in.css):

project.json

{
    "tools": {
        "BundlerMinifier.Core": "2.0.238",
    },

    "frameworks": {
        "netcoreapp1.0": {
        }
    },
}

bundleconfig.json

[
    {
        "outputFilename": "out.min.css",
        "inputFiles": [
            "in.css",
        ]
    },
]

in.css

body {
    background: url(bg.png);
}

then running dotnet bundle generates the following file:

out.min.css

body{background:url('/home/jsvh4h/dotnet/out.min.css')}

The background:url() should refer to bg.png, but instead it refers to the css file iteself. Doing this same operation on Windows using the same version of dotnet, the output is correct. Have anyone seen this behavior before and, better, can present a suggestion for fix or workaround?

Some potentially interesting system information

bash-4.2$ dotnet --version
1.0.0-preview2-003131
bash-4.2$ lsb_release -a
LSB Version:    :core-4.1-amd64:core-4.1-noarch:cxx-4.1-amd64:cxx-4.1-noarch:desktop-4.1-amd64:desktop-4.1-noarch:languages-4.1-amd64:languages-4.1-noarch:printing-4.1-amd64:printing-4.1-noarch
Distributor ID: CentOS
Description:    CentOS Linux release 7.3.1611 (Core)
Release:    7.3.1611
Codename:   Core
2

There are 2 best solutions below

1
On

That should have been fixed by BundlerMinifier#229. Updating BundleMinifier.Core to version 2.4.337 (which still supports netcoreapp1.0) should therefore solve your problem.

By the way, is there any reason that you are still using preview2 of .NET SDK 1.0? In the meantime the final version of .NET Core SDK 2.0 got released. If you don't want to upgrade to 1.1 or 2.0 I would at least install .NET Core SDK 1.0.4. The only additionally necessary step would to migrate from project.json to *.csproj using dotnet migrate.

0
On

Try adding ./ to the path like ./foo.png the . denotes the current directory in UNIX based systems.