首页 > 解决方案 > Razor 视图引擎:如何告诉智能感知在哪里寻找包程序集

问题描述

我正在开发一个大型旧项目,该项目下有许多 ASP.NET MVC(框架)5 Web 项目。尽管一切都编译得很好并且已经在生产环境中运行了很多年,但维护它并不总是那么容易,因为 Razor Intellisense 在 View .csthml 页面上无法正常工作。例如,打开这样的文件会给出

Severity    Code    Description Project File    Line    Suppression State
Error   CS0234  The type or namespace name 'Linq' does not exist in the namespace 'System' (are you missing an assembly reference?) 4_Views_Language_Index.cshtml
Error   CS0234  The type or namespace name 'Helpers' does not exist in the namespace 'System.Web' (are you missing an assembly reference?)  4_Views_Language_Index.cshtml
Error   CS0234  The type or namespace name 'WebPages' does not exist in the namespace 'System.Web' (are you missing an assembly reference?) 4_Views_Language_Index.cshtml
Error   CS0234  The type or namespace name 'Mvc' does not exist in the namespace 'System.Web' (are you missing an assembly reference?)  4_Views_Language_Index.cshtml
Error   CS0234  The type or namespace name 'Mvc' does not exist in the namespace 'System.Web' (are you missing an assembly reference?)  4_Views_Language_Index.cshtml
Error   CS0234  The type or namespace name 'Mvc' does not exist in the namespace 'System.Web' (are you missing an assembly reference?)  4_Views_Language_Index.cshtml
Error   CS0234  The type or namespace name 'Optimization' does not exist in the namespace 'System.Web' (are you missing an assembly reference?) 4_Views_Language_Index.cshtml
Error   CS0234  The type or namespace name 'Routing' does not exist in the namespace 'System.Web' (are you missing an assembly reference?)  4_Views_Language_Index.cshtml
Error   CS0234  The type or namespace name 'Mvc' does not exist in the namespace 'System.Web' (are you missing an assembly reference?)  4_Views_Language_Index.cshtml
Error   CS0115  '_Page_Views_Language_Index_cshtml.Execute()': no suitable method found to override 4_Views_Language_Index.cshtml
Error   CS0234  The type or namespace name 'HttpApplication' does not exist in the namespace 'System.Web' (are you missing an assembly reference?)  4_Views_Language_Index.cshtml
Error   CS0103  The name 'Context' does not exist in the current context    4_Views_Language_Index.cshtml
Error   CS0234  The type or namespace name 'HttpApplication' does not exist in the namespace 'System.Web' (are you missing an assembly reference?)  4_Views_Language_Index.cshtml
Error   CS0103  The name 'DefineSection' does not exist in the current context  4_Views_Language_Index.cshtml
Error   CS0103  The name 'ViewBag' does not exist in the current context    4_Views_Language_Index.cshtml
Error   CS0103  The name 'Model' does not exist in the current context  4_Views_Language_Index.cshtml
Error   CS0103  The name 'Url' does not exist in the current context    4_Views_Language_Index.cshtml
Error   CS0103  The name 'Url' does not exist in the current context    4_Views_Language_Index.cshtml

尝试(+/- 10 小时)后,主题中提到的所有内容,例如 thisthisthisthis等,等等。没有任何效果。但所有主题似乎都是关于编译错误,而不是智能感知错误。

最终,我在这个答案中找到了原因并在这个答案中再次找到原因。这似乎是因为我们将所有调试二进制文件编译到同一目录中(这节省了很多磁盘空间)。

  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
    <DebugSymbols>true</DebugSymbols>
    <DebugType>full</DebugType>
    <Optimize>false</Optimize>
    <OutputPath>..\bin\</OutputPath>
    <DefineConstants>DEBUG;TRACE</DefineConstants>
    <ErrorReport>prompt</ErrorReport>
    <WarningLevel>4</WarningLevel>
  </PropertyGroup>

即 to ..\bin\,而不是bin\在示例/默认 MVC 5 web 模板中找到。这适用于编译和运行调试。但它破坏了 Razor Intellisense。

当我将..\bin本地目录复制到项目bin目录时,Razor Intellisense 神奇地再次开始工作!即 Razor Intellisense 似乎总是在项目本地目录中寻找程序集,bin\与项目设置无关!

谁能告诉我如何告诉 Razor Intellisense 在..\bin\目录中查找程序集?

编辑:与此同时,我发现了有关此问题的更多信息:

这些都不是解决方案......他们只是“修复”是通过将输出目录设置回bin\ . 我正在开发一个包含许多类库的大型单体,其中有数十个 Razor 类库,每个类库都有许多共同的依赖项。将编译输出放入同一个..\bin\ 目录可以节省很多 HDD 空间。

标签: c#.netasp.net-mvcrazorintellisense

解决方案


推荐阅读