zoukankan      html  css  js  c++  java
  • 如何调试MVC4的代码

    http://www.yulebiao.com/questions/9952825/how-to-debug-asp-net-mvc-4-source-code  这是网上参考的连接

    下载了 http://aspnetwebstack.codeplex.com/SourceControl/list/changesets 这上面 .NET 4.0 RTM的源码,

    装了一个git,然后下载就可以了

    git clone https://git01.codeplex.com/aspnetwebstack.git 

    时间稍微长了点儿,半个小时吧;

    然后里面src全是MVC4的源码(其实很大一部分都在里面了)

    解决反感是runtime.sln的,打开之后,在里面新建一个MVC4的项目,

    这里有个问题,我下载的MVC4,在 system.web.mvc项目里Properties\CommonAssembley.cs里,全是5.0.0.0的版本号,

    我把他改成了5.0.0.1

    #if ASPNETMVC [assembly: AssemblyVersion("5.0.0.1")] [assembly: AssemblyFileVersion("5.0.0.1")] [assembly: AssemblyProduct("Microsoft ASP.NET MVC")] #elif ASPNETWEBPAGES 

    然后修改根目录下的 web.config

     <appSettings>
        <add key="webpages:Version" value="3.0.0.0" />
        <add key="webpages:Enabled" value="false" />
        <add key="PreserveLoginUrl" value="true" />
        <add key="ClientValidationEnabled" value="true" />
        <add key="UnobtrusiveJavaScriptEnabled" value="true" />

      </appSettings>  这里之所以改成3.0.0.0的原因,是因为在我下载的源码里,他的版本号就是3.0,

     <runtime>

        <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
          <dependentAssembly>
            <assemblyIdentity name="System.Web.Helpers" publicKeyToken="31bf3856ad364e35" />
            <bindingRedirect oldVersion="1.0.0.0-2.0.0.0" newVersion="3.0.0.0" />
          </dependentAssembly>
          <dependentAssembly>
            <assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" />
            <bindingRedirect oldVersion="1.0.0.0-4.0.0.0" newVersion="5.0.0.1" />
          </dependentAssembly>
          <dependentAssembly>
            <assemblyIdentity name="System.Web.WebPages" publicKeyToken="31bf3856ad364e35" />
            <bindingRedirect oldVersion="1.0.0.0-2.0.0.0" newVersion="3.0.0.0" />
          </dependentAssembly>
          <dependentAssembly>
            <assemblyIdentity name="EntityFramework" publicKeyToken="b77a5c561934e089" />
            <bindingRedirect oldVersion="1.0.0.0-5.0.0.0" newVersion="5.0.0.0" />
          </dependentAssembly>
          <dependentAssembly>
            <assemblyIdentity name="WebGrease" publicKeyToken="31bf3856ad364e35" />
            <bindingRedirect oldVersion="1.0.0.0-1.3.0.0" newVersion="1.3.0.0" />
          </dependentAssembly>
        </assemblyBinding>
      </runtime> 这里的改成了我自己的版本号

     然后修改view下面的web.config

     <configSections>

        <sectionGroup name="system.web.webPages.razor" type="System.Web.WebPages.Razor.Configuration.RazorWebSectionGroup, System.Web.WebPages.Razor, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35">
          <section name="host" type="System.Web.WebPages.Razor.Configuration.HostSection, System.Web.WebPages.Razor, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" />
          <section name="pages" type="System.Web.WebPages.Razor.Configuration.RazorPagesSection, System.Web.WebPages.Razor, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" />
        </sectionGroup>
      </configSections>  这里修改成了3.0,当然具体是什么,看你自己下载的,但是我觉得大部分应该跟我的是一样的(环境VS2012,源码4.0 RTM)
    <system.web.webPages.razor>
        <host factoryType="System.Web.Mvc.MvcWebRazorHostFactory, System.Web.Mvc, Version=5.0.0.1, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
        <pages pageBaseType="System.Web.Mvc.WebViewPage">

          <namespaces> 

    <pages
            validateRequest="false"
            pageParserFilterType="System.Web.Mvc.ViewTypeParserFilter, System.Web.Mvc, Version=5.0.0.1, Culture=neutral, PublicKeyToken=31BF3856AD364E35"
            pageBaseType="System.Web.Mvc.ViewPage, System.Web.Mvc, Version=5.0.0.1, Culture=neutral, PublicKeyToken=31BF3856AD364E35"

            userControlBaseType="System.Web.Mvc.ViewUserControl, System.Web.Mvc, Version=5.0.0.1, Culture=neutral, PublicKeyToken=31BF3856AD364E35"> 

    同样,修改之(具体是不是不修改也成,我就不知道了,我是按照网上的方法改的,最后的地方,会给出连接大家注意学习吧) 

    这样,配置文件和MVC代码中的版本号,就修改完了,

    然后打开VS2012的命令行,执行

     Run "sn.exe -Vr *,31BF3856AD364E35" in the Visual Command line  (哈哈,你看,我真的是COPY的,原创的东西几乎没有)

    然后把项目中的system.web.mvc的引用,改到你的MVC4的源码里的项目,当然,不止这一个,不然会有很多地方报错的,大致的DLL有 : system.web.razot; system.web.webpages;system.web.webpages.deployment; system.web.webpages.razor; 这里不全没关系,网页上会明确提示少哪个的.  

    如果出现了一个类型转换的错误:

    用户代码未处理 System.InvalidCastException
      HResult=-2147467262
      Message=[A]System.Web.WebPages.Razor.Configuration.HostSection 无法强制转换为 [B]System.Web.WebPages.Razor.Configuration.HostSection。类型 A 源自“System.Web.WebPages.Razor, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35”(在上下文“Default”中的“C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Web.WebPages.Razor\v4.0_2.0.0.0__31bf3856ad364e35\System.Web.WebPages.Razor.dll”位置处)。类型 B 源自“System.Web.WebPages.Razor, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35”(在上下文“Default”中的“C:\Windows\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files\root\49f25bf0\9ce908d5\assembly\dl3\70f2ab4b\b0630cdc_834fce01\System.Web.WebPages.Razor.dll”位置处)。

      Source=System.Web.WebPages.Razor 

    这个错误,就是我为什么要该system.web.webpages的版本好的原因了; 如果出现其他DLL,大家也可以随着改一下;

    之后,就可以在页面中随便加空间,就能看到断点的执行了,好运;

    当然,网上还有个家伙说不用修改源代码,但是要下载SkipStrongNames的一个东西,但是我点了连接,提示我下载已经移除了,不知道怎么回事,要是有搞定了的同学,也请通知我下哈,学习学习;

  • 相关阅读:
    。【自学总结 2】------3ds Max 菜单
    。【自学总结 1】------3ds Max 界面
    。求推荐一个usb集线器的购买网址
    (翻译)Importing models-Models
    (翻译)Importing models-FBX Importer, Rig options
    [游戏开发-学习笔记]菜鸟慢慢飞(18)-迷宫
    [游戏开发-学习笔记]菜鸟慢慢飞(17)- c#-委托简记(匿名方法,Lambda表达式)
    [游戏开发-学习笔记]菜鸟慢慢飞(16)- Unity3D-Android插件问题集锦
    [游戏开发-学习笔记]菜鸟慢慢飞(15)- Unity3D-图片压缩
    [游戏开发-学习笔记]菜鸟慢慢飞(14)- ScrollView刷新
  • 原文地址:https://www.cnblogs.com/davytitan/p/3076104.html
Copyright © 2011-2022 走看看