• razor syntax with errors compiles when it should not compile


    razor syntax with errors compiles when it should not compile

     
     

    This is by design. The build of of MVC views is disabled by default. You can enable the build of your MVC views in Visual Studio like that:

    • Right click on your project in Visual Studio
    • Unload project
    • Edit project

    • Change the value for MvcBuildViews from false to true

      <?xml version="1.0" encoding="utf-8"?>
      <Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
      ...
      <MvcBuildViews>true</MvcBuildViews>
      ...

    • Reload project

    Next time you compile and there are errors in your MVC views, it will not compile. The downside is, the compilation process will take longer.

    Update

    Here is an answer on SO, explaining how to avoid the error:

    It is an error to use a section registered as allowDefinition='MachineToApplication' beyond application level. This error can be caused by a virtual directory not being configured as an application in IIS

    Compile Views in ASP.NET MVC

    回答1

    From the readme word doc for RC1 (not indexed by google)

    ASP.NET Compiler Post-Build Step

    Currently, errors within a view file are not detected until run time. To let you detect these errors at compile time, ASP.NET MVC projects now include an MvcBuildViews property, which is disabled by default. To enable this property, open the project file and set the MvcBuildViews property to true, as shown in the following example:

    <Project ToolsVersion="3.5" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
      <PropertyGroup>
        <MvcBuildViews>true</MvcBuildViews>
      </PropertyGroup>

    Note Enabling this feature adds some overhead to the build time.

    You can update projects that were created with previous releases of MVC to include build-time validation of views by performing the following steps:

    1. Open the project file in a text editor.
    2. Add the following element under the top-most <PropertyGroup> element: <MvcBuildViews>true</MvcBuildViews>
    3. At the end of the project file, uncomment the <Target Name="AfterBuild"> element and modify it to match the following:
    <Target Name="AfterBuild" Condition="'$(MvcBuildViews)'=='true'">
        <AspNetCompiler VirtualPath="temp" PhysicalPath="$(ProjectDir)..$(ProjectName)" />
    </Target>

    3>C:WindowsMicrosoft.NETFrameworkv4.0.30319Temporary ASP.NET Files emp6ca5e0e49aa282d8App_Web_ww2uriuv.4.cs(55): error CS0234: The type or namespace name 'ECardWallViewModel' does not exist in the namespace 'UK.Connect.Model.ECard' (are you missing an assembly reference?)

    看开头第一行找到文件,发现这个报错的文件,根本没有include到项目中。可以直接删除

    #pragma checksum "C: epositoryEdenredUKUK60Connect_BackendUKERecognitionUK.Connect.Recognition.WebViewsECardNotificationECardsView.cshtml" "{ff1816ec-aa5e-4d10-87f7-6f4963833460}" "7E9AC76728AA1DA2C6A3CC8E6AB64781E8C8D505"

  • 相关阅读:
    2021 Duilib最新入门教程(二)Duilib编译动态库
    2021 Duilib最新入门教程(一)Duilib简介
    webgl图库选型
    CUDA编程学习记录
    C++时间戳获取
    FFMPEG编译问题记录
    程序员的35岁
    Linux发行版及其目标用户
    服务器关机或重启
    Linux下找出吃内存的方法总结
  • 原文地址:https://www.cnblogs.com/chucklu/p/12674634.html
Copyright © 2020-2023  润新知