如何强制不优化 ASP.NET Core 5 源代码 [英] How to force ASP.NET Core 5 source code to not be optimized

查看:25
本文介绍了如何强制不优化 ASP.NET Core 5 源代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试调试 ASP.NET Core 5 框架中的 Antiforgery 代码.

我已经使用

如何强制不优化代码?

我使用的是 Visual Studio Enterprise 2019 v16.8.3.

解决方案

在将 Antiforgery 源代码项目添加到我的解决方案后,我没有添加对 .csproj 文件的项目引用,而是必须引用 中的 dllC:\aspnetcore\artifacts\bin\Microsoft.AspNetCore.Antiforgery\Debug\net5.0.

我现在可以在 Watch 窗口中查看本地变量的值.

I'm trying to debug the Antiforgery code in the ASP.NET Core 5 framework.

I have built the code successfully using the instructions in https://github.com/dotnet/aspnetcore/blob/master/docs/BuildFromSource.md using the Debug configuration.

I have added the source code project to my test project and referenced it.

I've checked that the Configuration is set to Debug.

I've made sure that "Suppress JIT Optimizations" has been checked.

"Optimize Code" in Project Properties -> Build, is unchecked for both projects.

"Debug Info" dropdown has been set to "Full" in the Advanced Options (Under Build tab) for both projects.

However when I hit the breakpoint in DefaultAntiforgeryTokenSerializer.Serialize(), it gives me this error when viewing the method's local vars in the Watch window:

Cannot obtain value of local or argument as it is not available at this instruction pointer, possibly because it has been optimized away

How can I force the code to not be optimized?

I'm using Visual Studio Enterprise 2019 v16.8.3.

解决方案

After adding the Antiforgery source code project to my solution, rather than add a project reference to the .csproj file, I had to reference the dll in C:\aspnetcore\artifacts\bin\Microsoft.AspNetCore.Antiforgery\Debug\net5.0.

I can now view the values of local vars in the Watch window.

这篇关于如何强制不优化 ASP.NET Core 5 源代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆