- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
当我尝试查看我的 Razor 页面时,我得到以下信息
fail: Microsoft.AspNetCore.Server.Kestrel[13]
Connection id "0HLFVN3H0G8MT", Request id "0HLFVN3H0G8MT:00000001": An unhandled exception was thrown by the application.
Microsoft.AspNetCore.Mvc.Razor.Compilation.CompilationFailedException: One or more compilation failures occurred:
jhhodq42.4nm(4,41): error CS0234: The type or namespace name 'Razor' does not exist in the namespace 'Microsoft.AspNetCore' (are you missing an assembly reference?)
jhhodq42.4nm(5,62): error CS0012: The type 'Attribute' is defined in an assembly that is not referenced. You must add a reference to assembly 'netstandard, Version=2.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51'.
这是一条令人困惑的消息,因为我的包引用在下面并且包括 网络标准
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Mvc" Version="2.1.1" />
<PackageReference Include="Microsoft.AspNetCore.Server.Kestrel" Version="2.1.2" />
<PackageReference Include="Microsoft.Extensions.Logging" Version="2.1.1" />
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="2.1.1" />
<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="2.1.1" />
<PackageReference Include="Microsoft.Extensions.Configuration.CommandLine" Version="2.1.1" />
<PackageReference Include="NETStandard.Library" Version="2.0.3" />
<PackageReference Include="Newtonsoft.json" Version="11.0.2" />
</ItemGroup>
我的目标是 .netcore 2.1
我的startup.cs是
public void ConfigureServices(IServiceCollection services)
{
services.AddMvc();
}
public void Configure(IApplicationBuilder app, IHostingEnvironment env,
ILoggerFactory loggerFactory)
{
loggerFactory.AddConsole();
loggerFactory.AddDebug();
app.UseMvc();
app.UseMvc(routes =>
{
routes.MapRoute(
name: "default",
template: "{controller=Home}/{action=Index}/{id?}");
});
}
我反复清除和恢复包缓存,并在 VS2017 和 dotnetcli 下复制了它,非常感谢任何指针。我目前最好的猜测是存在相互冲突的依赖关系,但我仍然是 .netcore 的新手并且不确定如何调试,感谢任何帮助
最佳答案
有an issue在对这个主题进行了长时间讨论的官方存储库上。在撰写本文时,该问题仍未解决,但您似乎可以尝试几种可能的解决方案。但是,看起来有多种(目前尚未明确定义)导致此问题的原因,因此我鼓励您尝试所有这些。我将在此处包括其中一些项目,因此它不是仅链接的答案,但我认为完整阅读该问题是明智的。
<system.web>
<compilation debug="true" targetFramework="4.7.1" >
<assemblies>
<add assembly="netstandard, Version=2.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51"/>
</assemblies>
</compilation>
<httpRuntime targetFramework="4.7.1" />
</system.web>
注意:
A web.config file is required when hosting the app in IIS or IIS Express. Settings in web.config enable the ASP.NET Core Module to launch the app and configure other IIS settings and modules. If the web.config file isn't present and the project file includes
<Project Sdk="Microsoft.NET.Sdk.Web">
, publishing the project creates a web.config file in the published output (the publish folder).
.csproj
. <ItemGroup>
<Reference Include="netstandard" />
</ItemGroup>
根据您提出问题的方式,我假设您的项目是全新的,并且可以选择创建一个新项目。
更改 global.json到目标版本 2.1.2
dotnet SDK,而不是 2.0.3
.
安装最新版本的SDK
希望那里能为您解决问题。
编辑:我注意到你打了两次电话给 app.UseMvc()
.我怀疑它有什么作用,因为我想这些调用只是设置状态,但没有必要调用它两次。
关于c# - .net core AspnetCore Razor View 因 CompilationFailedException 而失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51803486/
我在构建项目时遇到以下错误: org.gradle.api.internal.tasks.compile.CompilationFailedException: Compilation failed;
我在构建项目时遇到以下错误: org.gradle.api.internal.tasks.compile.CompilationFailedException: Compilation failed;
我正在尝试使用 Ant 脚本和 Java 编译我的 JasperReports 模板。我收到此错误: jasper java.lang.NoClassDefFoundError: org/codeha
我有 ASP.Net MVC 应用程序,其中一部分是将 razor View 编译为字符串。该代码与此示例非常相似: https://long2know.com/2017/08/rendering-a
我是java报告部分的初学者。我在互联网上找到了代码,当我调用 jFrame 时,我成功创建了 jasper 报告,但出现以下错误: org/codehaus/groovy/control/Compi
我想对 ASP.NET Core MVC 网站进行集成测试。我首先添加一个空的 MVC WebApplication 项目: netcoreapp2.0
当我尝试查看我的 Razor 页面时,我得到以下信息 fail: Microsoft.AspNetCore.Server.Kestrel[13] Connection id "0HLFVN3H0G
尝试了好几天;谷歌搜索并尝试各种“修复”和“依赖项”等,但仍然无法构建用于发布的 APK。调试没问题。 我的命令:flutter build apk --release 错误: AILURE:构建失败
我在用 Android Studio 3.1.2 JRE:1.8.0_152-release-1024-b01 x86_64 Gradle版本4.4 我正在关注异常org.gradle.api.tas
我是一名优秀的程序员,十分优秀!