zoukankan      html  css  js  c++  java
  • 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"

  • 相关阅读:
    DotNetty是微软的Azure团队,使用C#实现的Netty的版本发布
    C# 与 .NET Framework 对应关系
    C# 基于Directshow.Net lib库 USB摄像头使用DirectShow.NET获取摄像头视频流
    Actor模型的状态(State)+行为(Behavior)+邮箱(Mailbox)
    c# 无法加载DLL:找不到指定的模块(异常来自HRESULT:0X8007007E)
    管道式编程(Pipeline Style programming)
    Word文档转Markdown插件(Windows)
    纯Java实现定时任务(转)
    Spring MVC使用Schedule实现定时任务
    Spring Boot使用Schedule实现定时任务
  • 原文地址:https://www.cnblogs.com/chucklu/p/12674634.html
Copyright © 2011-2022 走看看