andrewb
andrewb

Reputation: 3095

CSS file is not being deployed from bundle in MVC site

Bundles are new to me but in my _layout.cshtml file I have the following:

@Styles.Render("~/Content/css")

And in the App_Start\BundleConfig.cs file I have the following:

bundles.Add(new StyleBundle("~/Content/css").Include(
    "~/Content/bootstrap.css",
    "~/Content/site.css",
    "~/Content/Portal.css"));

When I view the site on localhost by launching it from Visual Studio, all the styles are inserted, like so:

<link href="/Content/bootstrap.css" rel="stylesheet"/>
<link href="/Content/site.css" rel="stylesheet"/>
<link href="/Content/Portal.css" rel="stylesheet"/>

However when I deploy to testing server the portal6.css file is not included in the markup, and in fact was not even copied into my Publish directory. I manually copied that CSS file to the Content folder but it seems like the bundle is not referencing it.

Does any one know what the issue is?

Upvotes: 0

Views: 2826

Answers (2)

moto_geek
moto_geek

Reputation: 580

Check #1

In Visual Studio, right-click the file, verify BUILD ACTION = CONTENT. CONTENT = Include to deployment package files. This is the most common issue is this is set to NONE.

Check #2

If the above is correctly set, the next thing that can happen is your build is not seeing this property when building the project independently of the solution. This is what has happened to me. For some reason, the build configuration does not update the new property set on a file that's may be added to the project outside of the GUI.

Visual Studio

1) Perform "Clean Solution" or Clean under "Build" 2) Now "Build" or perform "Publish" and the file will now be part of the deployment package folder.

BONUS NOTE: And lastly, also note if your web.config setting debug=false, the bundle will build the default file names "file.css". If debug=true, this instructs bundle to look for "file.min.css" version and will grab the minifying file version. So this can cause unexpected results as well if the CSS file contents are different or contain css classes that don't match the original css file.

Upvotes: 0

EdSF
EdSF

Reputation: 12341

...in fact was not even copied into my Publish directory. I manually copied that CSS file to the Content folder...

Sounds like it's just a case of marking the Build Action of the project file as Content in project file properties - otherwise, it will not be "published" as you have noticed/stated.

To view the portal.css properties:

  • select the file
  • then F4 or ALT + ENTER
  • in Properties tab/window check if Build Action is set to Content (chances are that it's set to None having been "manually copied")

    sample properties of font-awesome.css
    example view of some css file (font-awesome.css) that needs to be "published"

Note: Assumes the file is "included in Project" (not just in file system) - so it should be visible in your Project view in VS (without the "view all files" toggle enabled).

Hth...

Upvotes: 2

Related Questions