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:
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"
]
}
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With