Skip to content
This repository has been archived by the owner on Apr 20, 2018. It is now read-only.

.NET MVC Project cshtml files not being updated #625

Open
Giovanni-Mattucci opened this issue Aug 11, 2016 · 6 comments
Open

.NET MVC Project cshtml files not being updated #625

Giovanni-Mattucci opened this issue Aug 11, 2016 · 6 comments

Comments

@Giovanni-Mattucci
Copy link

Giovanni-Mattucci commented Aug 11, 2016

I'm having trouble with usemin not updating URLs within my .cshtml files.
Here is my current setup in my gruntfile.js:

// Renames files for browser caching purposes
filerev: {
    dist: {
      src: [
        '<%= config.distDir %>/Content/css/{,*/}*.css',
        '<%= config.distDir %>/Scripts/{,*/}*.js',
        '<%= config.distDir %>/Content/images/{,*/}*.*'
      ]
    }
  },

  // Performs rewrites based on rev and usemin blocks in html
  usemin: {
    options: {
      assetsDirs: [
        '<%= config.distDir %>',
        '<%= config.distDir %>/Scripts'
      ],
      patterns: {
        jsmaprefs: [
          [/(main\.js\.map)/, 'Update js to reference our revved map']
        ]
      }
    },
    html: ['<%= config.distDir %>/Views/Shared/_Layout.cshtml'],
    css: ['<%= config.distDir %>/Content/css/{,*/}*.css'],
    jsmaprefs: ['<%= config.distDir %>/Scripts/{,*/}*.js']
  }

Does usemin only work with .html files? Or will it scan any file and replace those URL strings?

As an FYI I utilized this yeoman generator to create this file initially.

@Giovanni-Mattucci Giovanni-Mattucci changed the title .NET MVC Project cshtml files not getting updated .NET MVC Project cshtml files not being updated Aug 11, 2016
@XmlmXmlmX
Copy link

XmlmXmlmX commented Dec 21, 2016

No, for me it works with cshtml-files. Correct path?
Two of my collegues have the same problem. For me it works.
No errors.

@vankooch
Copy link

vankooch commented Apr 7, 2017

Hi,

I've had the same problems here but now I've found a working version. The trick is to remove the starting~ from every href and srcattribute in your cshtml files.

Does not work:

<link rel="stylesheet" href="~/styles/bootstrap.css">

Works:

<link rel="stylesheet" href="/styles/bootstrap.css">

My Gruntfile is:

        // Usemin bundler
        "useminPrepare": {
            options: {
                dest: "<%= config.release.wwwroot %>",
                root: "<%= config.debug.wwwroot %>"
            },
            html: "<%= config.debug.root %>/Views/Shared/_Layout.cshtml",
            css: "<%= config.debug.styles %>/*.css"
        },

        // Performs rewrites based on rev and the useminPrepare configuration
        "usemin": {
            options: {
                assetsDirs: ["<%= config.release.wwwroot %>"]
            },
            html: ["<%= config.release.root %>/Views/*/*.cshtml"],
            css: ["<%= config.release.styles %>/*.css"]
        },

        // Add version tag to filenames
        "filerev": {
            dist: {
                src: [
                    "<%= config.release.styles %>/*.css",
                    "<%= config.release.scripts %>/*.js",
                    "<%= config.release.images %>/**/*"
                ]
            }
        },

The problem is that this will brake all the Area views because the links wont work anymore...

@angel006z
Copy link

Gruntfile use to relative path;
but I hope to support “〜/” and “/”.

@angel006z
Copy link

+1

1 similar comment
@angel006z
Copy link

+1

@angel006z
Copy link

+99

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants