我正在构建一个模块化的MVC4应用程序,其中每个模块(=区域)都是一个类库。 模型和控制器编译成.dll文件,视图则复制到适当的文件夹中。 在运行时,一切正常。 但在设计时,还有一个令人烦恼的问题:在类库内编辑Razor视图时,Visual Studio无法识别System.Web.Optimization命名空间。
The name "Styles" does not exist in the current context.
The name "Scripts" does not exist in the current context.
我尝试将程序集添加到根目录和内部web.config的system.web/compilation部分:
<add assembly="System.Web.Optimization, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
我也尝试了不使用特定版本的方法,但两种方法都没有解决问题,反而触发了一个asp.net运行时错误(在razor视图的第一行可见):
Could not load file or assembly 'System.Web.Optimization, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The system cannot find the file specified.
该程序集已被项目引用,并将“Copy Local”设置为“True”。它也作为一个命名空间添加到razor配置部分。
我怀疑这是我将来在其他程序集中会遇到的一般性问题。
编辑:我完成了在类库中的razor视图中启用Intellisense的一般设置。到目前为止,一切都正常,除了VS2010无法识别优化命名空间。
<add namespace="System.Web.Optimization"/>
? 你的代码中有吗? - Darin Dimitrov