Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ASP.Net intellisense incorrectly suggesting webroot for paths

Following a Pluralsight course I'm coding an ASP.NET 5/MVC 6 web app from effectively scratch. When referencing an object in the format such as:

~/js/site.js

or

~/css/site.css

in an .cshtml file, Intellisense is showing an error, saying the files can't be found suggesting the paths should be instead:

~/wwwroot/js/site.js
~/wwwroot/css/site.css

However using the first group of paths references the files correctly on the actual webpage, but using the second group of paths, as Visual Studio suggests breaks the webpage and both the js and css aren't loaded.

The items are located under the wwwroot folder, as you can see here:

Solution Explorer

Why is Intellisense behaving this way, and how can I fix this behavior?

Edit: Here's the project.json file:

{
  "version": "1.0.0-*",
  "compilationOptions": {
    "emitEntryPoint": true
  },

    "dependencies": {
        "Microsoft.AspNet.IISPlatformHandler": "1.0.0-rc1-final",
        "Microsoft.AspNet.Mvc": "6.0.0-rc1-final",
        "Microsoft.AspNet.Server.Kestrel": "1.0.0-rc1-final",
        "Microsoft.AspNet.StaticFiles": "1.0.0-rc1-final",
        "Microsoft.AspNet.Mvc.TagHelpers": "6.0.0-rc1-final"
    },

  "commands": {
    "web": "Microsoft.AspNet.Server.Kestrel"
  },

  "frameworks": {
    "dnx451": { },
    "dnxcore50": { }
  },

  "exclude": [
    "wwwroot",
    "node_modules"
  ],
  "publishExclude": [
    "**.user",
    "**.vspscc"
  ]
}
like image 991
Ranger Avatar asked Nov 10 '22 00:11

Ranger


1 Answers

For your intellisense to reference your files under the wwwroot without error, your project.json file needs to have the following:

"webroot": "wwwroot",

That should resolve your issue. This minor issue is a known bug at MS when you create a new MVC project with scaffolding in Visual Studio 2015. I think it has been resolved with 6.0.0-rc 1-final.

like image 131
Warner Avatar answered Nov 15 '22 10:11

Warner