使用"nameof"剃刀视图中的运算符 [英] Using "nameof" operator in Razor views
问题描述
在我的VS.NET 2015开发计算机上,使用 nameof
运算符就像一个咒语.
On my VS.NET 2015 development machine, the Razor views that use the nameof
operator work like a charm.
部署到Windows服务器时,它无法编译CSHTML Razor视图:
When deploying to a Windows server, it fails to compile the CSHTML Razor views:
名称'nameof'在当前上下文中不存在.
The name 'nameof' does not exist in the current context.
德语:
Der Name'nameof'ist im aktuellen Kontext nicht vorhanden.
Der Name 'nameof' ist im aktuellen Kontext nicht vorhanden.
我已经安装了.NET Framework 4.6("ASP.NET版本:4.6.81.0"),但没有成功.
I've installed .NET Framework 4.6 ("ASP.NET version: 4.6.81.0") with no success.
很可能我缺少一些简单的东西.
Most likely I'm missing something plain simple.
不过,我真的很笨.它是web.config设置吗?还是其他?
Still, I'm really clueless. Is it a web.config setting? Or something else?
我的问题:
如何在CSHTML Razor视图中启用C#6功能(如nameof
运算符)?
How to enable C# 6 features (like the nameof
operator) in CSHTML Razor views?
推荐答案
确保在文件"web.config"中存在节点system.codedom
.
Make sure in your file "web.config" the node system.codedom
exists.
<system.codedom>
<compilers>
<compiler language="c#;cs;csharp" extension=".cs"
type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.CSharpCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
warningLevel="4" compilerOptions="/langversion:6 /nowarn:1659;1699;1701"/>
<compiler language="vb;vbs;visualbasic;vbscript" extension=".vb"
type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.VBCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
warningLevel="4" compilerOptions="/langversion:14 /nowarn:41008 /define:_MYTYPE=\"Web\" /optionInfer+"/>
</compilers>
</system.codedom>
您将引用软件包Microsoft.CodeDom.Providers.DotNetCompilerPlatform
.
这篇关于使用"nameof"剃刀视图中的运算符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!