Ran*_*ger 5 c# asp.net asp.net-mvc razor asp.net-core-mvc
在Pluralsight课程之后,我正在从头开始编写ASP.NET 5/MVC 6 Web应用程序.以以下格式引用对象时:
~/js/site.js
Run Code Online (Sandbox Code Playgroud)
要么
~/css/site.css
Run Code Online (Sandbox Code Playgroud)
在.cshtml文件中,Intellisense显示错误,说无法找到文件,建议路径应该是:
~/wwwroot/js/site.js
~/wwwroot/css/site.css
Run Code Online (Sandbox Code Playgroud)
但是,使用第一组路径在实际网页上正确引用文件,但使用第二组路径,因为Visual Studio建议中断网页,并且不加载js和css.
这些项目位于wwwroot文件夹下,如下所示:
为什么Intellisense以这种方式表现,我该如何解决这种行为?
编辑:这是project.json文件:
{
"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"
]
}
Run Code Online (Sandbox Code Playgroud)
小智 1
为了让您的智能感知能够准确无误地引用 wwwroot 下的文件,您的 project.json 文件需要具有以下内容:
"webroot": "wwwroot",
这应该可以解决你的问题。当您在 Visual Studio 2015 中使用脚手架创建新的 MVC 项目时,这个小问题是 MS 的一个已知错误。我认为它已在 6.0.0-rc 1-final 中得到解决。