c# - 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 小时)后,主题中提到的所有内容,例如 this、 this、 this、 this等,等等。没有任何效果。但所有主题似乎都是关于编译错误,而不是智能感知错误。
最终,我在这个答案中找到了原因,并在这个答案中再次找到了原因。这似乎是因为我们将所有调试二进制文件编译到同一目录中(这节省了很多磁盘空间)。
<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 空间。
解决方案
推荐阅读
- sql - 返回值进行比较
- azure - 带有计时器的 Azure 自动关机,但没有连接用户
- javascript - 如何优雅地检查 JS 中两个对象之间是否有任何字段具有更长的值?
- powershell - Powershell Workflow 的数组输出未正确格式化或导出
- java - 如何正确使用 Swagger Maven 插件和现有项目
- android-studio - 如何在 Flutter 项目中使用 AndroidStudio 3 中的 Android Profiler 和 Logcat
- python - Python 包认为我的依赖版本比我旧
- kubernetes - 如何与同一 k8s 集群中的 pod 内的 Kubernetes CRD 服务通信?
- r - 将一个单元格数据拆分为两个变量,然后保存在 csv 中
- javascript - Javascript String Array-Like-Object behaviour