c# - 编译 fo index.cshtml 会引发运行时错误
问题描述
我正在尝试更新一个私有 nuget 包,对此进行的一些更改导致我出现此错误屏幕。
错误本质上是
An error occurred during the compilation of a resource required to process this request. Please review the following specific error details and modify your source code appropriately.
Generated Code
One or more compilation references may be missing. If you're seeing this in a published application, set 'CopyRefAssembliesToPublishDirectory' to true in your project file to ensure files in the refs directory are published.The type or namespace name 'Hosting' does not exist in the namespace 'Microsoft.AspNetCore.Razor' (are you missing an assembly reference?)+[assembly: global::Microsoft.AspNetCore.Razor.Hosting.RazorCompiledItemAttribute(typeof(AspNetCore.Views_Home_Index), @"mvc.1.0.view", @"/Views/Home/Index.cshtml")]
The type or namespace name 'Hosting' does not exist in the namespace 'Microsoft.AspNetCore.Razor' (are you missing an assembly reference?)
我通过在网上尝试各种解决方案完成了我的作业,例如
1)CopyRefAssembliesToPublishDirectory'
在文件true
中设置。.csproj
2)Remove ASP.Net Temporary files
仍然没有运气。
到目前为止,我知道我尝试打开一个网页,当 asp.net 尝试动态编译时,它无法构建解决方案。
我的理解是否完整,我还能做些什么来调试并找到解决方案?
这里有几.csproj
行
<TargetFramework>net461</TargetFramework>
<PackageReference Include="Microsoft.AspNetCore.StaticFiles" Version="1.1.3" />
<PackageReference Include="System.Net.Http" Version="4.3.3" />
作为私人性质,我不能分享大部分代码,但只能分享常见的东西。
任何帮助深表感谢。
解决方案
将其设置为<Project Sdk="Microsoft.NET.Sdk.Web" ToolsVersion="15.0">
并包含以下文件
<PackageReference Include="Microsoft.AspNetCore.Mvc" Version="2.2.0" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.Razor.ViewCompilation" Version="2.2.0" />
<PackageReference Include="Microsoft.AspNetCore.StaticFiles" Version="2.2.0" />
<PackageReference Include="Microsoft.AspNetCore.SpaServices" Version="2.2.0" />
帮助解决了问题
推荐阅读
- build - WebpackError: ReferenceError: Image is not defined(在“gatsby build”期间,“gatsby develop”工作正常)
- laravel - 如何在 laravel 8 中设置一个漂亮的 url?
- reactjs - React 测试使用 mockstore 和自定义存储来测试它
- python - 如何使输出 csv 文件中的值在同一列中分开
- apache-spark - 如何减少 BigQuery 中的临时表过期时间
- php - PHP在SMARTY模板中准确显示while循环数据
- python - 一本书的词汇表
- python - 是否有一种相当于 R 的 Python 方法来查找前一周的最后一个非 NAT 日期
- hibernate - 如何通过hibernate ogm将mogodb atlas连接到带有jpa的java EE 8 Framework?
- html - django密码重置确认