Using “nameof” operator in Razor views

后端 未结 2 2066
爱一瞬间的悲伤
爱一瞬间的悲伤 2021-02-05 03:21

On my VS.NET 2015 development machine, the Razor views that use the nameof operator work like a charm.

When deploying to a Windows server, it fails to compile the CSHTML

相关标签:
2条回答
  • 2021-02-05 04:00

    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=\&quot;Web\&quot; /optionInfer+"/>
        </compilers>
     </system.codedom>
    

    And you'd reference the package Microsoft.CodeDom.Providers.DotNetCompilerPlatform.

    0 讨论(0)
  • 2021-02-05 04:03

    According to this site, you need to reference the Roslyn compiler in your Web.config file to get C# 6 features to work in your razor views.

    This can be achieved simply by installing the CodeDOM Providers for .NET Compiler NuGet package.

    PM> Install-Package Microsoft.CodeDom.Providers.DotNetCompilerPlatform
    
    0 讨论(0)
提交回复
热议问题