如何调试asp.net mvc 4源代码?

时间:2012-03-31 03:37:56

标签: .net asp.net-mvc asp.net-mvc-4 visual-studio-debugging

我从这里下载最新的源代码:http://aspnetwebstack.codeplex.com/SourceControl/list/changesets

1)将system.web.mvc项目添加到我的解决方案中,包括system.web.mvc项目所依赖的其他项目。

https://public.blu.livefilestore.com/y1pWkk8-pYVhCxrqVp3WTurqXOI290cw7uGMfrKYoVDARFINGaaYgENPsoj_U1ukH3plg9O29-YiDkxBuSxMv8JWg/1%201.jpg?psid=1

2)将“CollaborativeDesign.WebUI”,“CollaborativeDesign.Domain”,“CollaborativeDesign.UnitTest”项目中的system.web.mvc程序集的引用从GAC one更改为system.web.mvc项目。

https://public.blu.livefilestore.com/y1phd1RsSEDGBZU_w6ke0NNw19sa51cXXsYTPB05yhKiNYPq_Hr1kdllejvrxMdDjGBHR0H94GOglRvt-1MUAA7ng/2.jpg?psid=1

3)更改根Web.config文件,如下所示:

https://public.blu.livefilestore.com/y1pKu-Q0K765sayJazkM8OLmC-r-Kj2lkkq5fs6M0Kl6YwN5CtVvKYFzrmdkyj8oMIboOWPpBnDnt5mabIoAZuhTw/3.jpg?psid=1

https://public.blu.livefilestore.com/y1pi3d9IWgFkCpnornqTMs4OQTBdC2IDL3YL2A51DFdjYE4wFcn_-NYKMjLYtl2PjCYedngHZ5sSblOlFj-zIrnUg/4.jpg?psid=1

4)更改“View”目录中的Web.config文件,如下所示:

<!--<pages validateRequest="false" pageParserFilterType="System.Web.Mvc.ViewTypeParserFilter, System.Web.Mvc, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" pageBaseType="System.Web.Mvc.ViewPage, System.Web.Mvc, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" userControlBaseType="System.Web.Mvc.ViewUserControl, System.Web.Mvc, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35">
  <controls>
    <add assembly="System.Web.Mvc, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" namespace="System.Web.Mvc" tagPrefix="mvc" />
  </controls>
</pages>-->
<pages validateRequest="false" pageParserFilterType="System.Web.Mvc.ViewTypeParserFilter, System.Web.Mvc, Version=4.0.0.0, Culture=neutral, PublicKeyToken=null" pageBaseType="System.Web.Mvc.ViewPage, System.Web.Mvc, Version=4.0.0.0, Culture=neutral, PublicKeyToken=null" userControlBaseType="System.Web.Mvc.ViewUserControl, System.Web.Mvc, Version=4.0.0.0, Culture=neutral, PublicKeyToken=null">
    <controls>
        <add assembly="System.Web.Mvc, Version=4.0.0.0, Culture=neutral, PublicKeyToken=null" namespace="System.Web.Mvc" tagPrefix="mvc" />
    </controls>
</pages>

5)当我运行项目时,它看起来仍然使用GAC system.web.mvc.dll,因为当我在“system.cs”文件中设置断点时,该文件位于“system.web.mvc”中“项目,它表明它没有为文档加载任何符号,而且我也无法进入mvc源代码的方法。

https://public.blu.livefilestore.com/y1pgt_xkjJLw3bPFj6R6z2EAyqxCYC4Yk0cfYUe4RCUEkYT9EQPb56CZ1qKVI8_zGBoRe5VcFcRjmNjnc24hFmyDw/5.jpg?psid=1

如何调试源代码? 我怎么知道加载的system.web.mvc.dll是GAC或本地的?

3 个答案:

答案 0 :(得分:8)

根据@ Rick.Anderson-at-Microsoft.com的评论,我通过以下额外步骤解决了这个问题:

1&gt; 在可视命令行中运行“sn.exe -Vr *,31BF3856AD364E35”

2&gt; 将System.Web.Mvc项目中的CommonAssemblyInfo.cs中的“AssemblyVersion”和“AssemblyFileVersion”从“4.0.0.0”更改为“4.0.0.1”。重建项目。

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

3&gt; 更改根目录中的Web.config文件

<compilation debug="true" targetFramework="4.0">
    <assemblies>
        <add assembly="System.Web.Abstractions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
        <add assembly="System.Web.Helpers, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
        <add assembly="System.Web.Routing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
        <add assembly="System.Web.Mvc, Version=4.0.0.1, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
        <!--<add assembly="System.Web.Mvc, Version=4.0.0.0, Culture=neutral, PublicKeyToken=null" />-->
        <add assembly="System.Web.WebPages, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
        <add assembly="System.Data.Entity, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"/>

<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
    <dependentAssembly>
        <assemblyIdentity name="System.Web.Helpers" publicKeyToken="31bf3856ad364e35" />
        <bindingRedirect oldVersion="1.0.0.0" newVersion="2.0.0.0" />
    </dependentAssembly>
    <dependentAssembly>
        <!--<assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" />-->
        <assemblyIdentity name="System.Web.Mvc" publicKeyToken="31BF3856AD364E35" />
        <bindingRedirect oldVersion="1.0.0.0-3.0.0.0" newVersion="4.0.0.1" />
    </dependentAssembly>
    <dependentAssembly>
        <assemblyIdentity name="System.Web.WebPages" publicKeyToken="31bf3856ad364e35" />
        <bindingRedirect oldVersion="1.0.0.0" newVersion="2.0.0.0" />
    </dependentAssembly>
</assemblyBinding>

4&gt; 更改View目录中的Web.config文件

<system.web.webPages.razor>
<!--<host factoryType="System.Web.Mvc.MvcWebRazorHostFactory, System.Web.Mvc, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />-->
<host factoryType="System.Web.Mvc.MvcWebRazorHostFactory, System.Web.Mvc, Version=4.0.0.1, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
<pages pageBaseType="System.Web.Mvc.WebViewPage">
  <namespaces>
    <add namespace="System.Web.Mvc" />
    <add namespace="System.Web.Mvc.Ajax" />
    <add namespace="System.Web.Mvc.Html" />
    <add namespace="System.Web.Routing" />
    <add namespace="DevTrends.MvcDonutCaching" />
  </namespaces>

<!--<pages validateRequest="false" pageParserFilterType="System.Web.Mvc.ViewTypeParserFilter, System.Web.Mvc, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" pageBaseType="System.Web.Mvc.ViewPage, System.Web.Mvc, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" userControlBaseType="System.Web.Mvc.ViewUserControl, System.Web.Mvc, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35">
   <controls>
     <add assembly="System.Web.Mvc, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" namespace="System.Web.Mvc" tagPrefix="mvc" />
   </controls>
</pages>-->
<pages validateRequest="false" pageParserFilterType="System.Web.Mvc.ViewTypeParserFilter, System.Web.Mvc, Version=4.0.0.1, Culture=neutral, PublicKeyToken=31BF3856AD364E35" pageBaseType="System.Web.Mvc.ViewPage, System.Web.Mvc, Version=4.0.0.1, Culture=neutral, PublicKeyToken=31BF3856AD364E35" userControlBaseType="System.Web.Mvc.ViewUserControl, System.Web.Mvc, Version=4.0.0.1, Culture=neutral, PublicKeyToken=31BF3856AD364E35">
    <controls>
        <add assembly="System.Web.Mvc, Version=4.0.0.1, Culture=neutral, PublicKeyToken=31BF3856AD364E35" namespace="System.Web.Mvc" tagPrefix="mvc" />
    </controls>
</pages>

5&gt; 重新启动Asp.net开发服务器。好的,享受源代码!感谢@ Rick.Anderson-at-Microsoft.com的评论。

debug image

答案 1 :(得分:0)

MVC source code documentation中提供了一种不涉及修改MVC源代码的简单方法。下载附加的SkipStrongNames attachment,解压缩,然后从UAC提升的命令提示符运行它。如果您从GIT(git clone https://git01.codeplex.com/aspnetwebstack.git)中删除最新版本,则可能需要更改views / web.config文件中的引用以使用3.0.0.0而不是2.0.0.0和5.0.0.0而不是4.0.0.0。

答案 2 :(得分:0)

我可以使用SkipStrongNames实用程序调试ASP.NET MVC 4源代码,并修改一些项目设置。有关Debug ASP.NET MVC 4 Source Code

的详细步骤,请参阅我的博客