簡體   English   中英

DebuggerDisplayAttribute在VS 2017中無效

[英]DebuggerDisplayAttribute has no effect in VS 2017

看起來DebuggerDisplayAttribute在帶有Resharper 2018.2.3的Visual Studio 2017(15.9.4)中沒有任何作用。

  • 將屬性放在AssemblyInfo.cs或Program.cs中沒有明顯的作用。
  • 我的目標是.Net Framework 4.7.2。 更改框架版本也沒有明顯的效果。
  • 我已經驗證了在“工具”->“選項”->“調試”->“常規”中未選中 “在變量窗口中顯示對象的原始結構”。 為了確定,我什至檢查了它,關閉了VS,重新打開了VS,然后取消選中了它。 沒有效果。

在此處輸入圖片說明

  • 將屬性放在自定義類上確實有效果。 似乎該屬性僅在裝配級時才被忽略。
  • 這可以在VS 2015中正常運行(使用相同版本的Resharper)。
  • 以安全模式啟動VS 2017(使用devenv.exe /safemode )無效。
  • 更新VS 15.9.4-> 15.9.7無效。

這是一個非常基本的控制台應用程序。 盡管具有此屬性,但dt變量在我的監視窗口中顯示為{2/14/2019 10:35:38 AM}
在此處輸入圖片說明

[assembly: DebuggerDisplay("Foo", Target = typeof(DateTime))]

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            var dt = DateTime.Now;
            Debugger.Break();
        }
    }
}

如果使用ILSpy來反編譯控制台應用程序,則可以看到以下屬性:

[assembly: Debuggable(
    DebuggableAttribute.DebuggingModes.Default | 
    DebuggableAttribute.DebuggingModes.DisableOptimizations | 
    DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | 
    DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: DebuggerDisplay("Foo", Target = typeof(DateTime))]

為什么屬性不做任何事情? 我什至如何開始調試呢?

編輯:根據要求完成源文件。

ConsoleApp1.csproj

<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
  <PropertyGroup>
    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
    <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
    <ProjectGuid>{EBBA72C6-5087-4D8E-9F2C-B968ABD59EAA}</ProjectGuid>
    <OutputType>Exe</OutputType>
    <RootNamespace>ConsoleApp1</RootNamespace>
    <AssemblyName>ConsoleApp1</AssemblyName>
    <TargetFrameworkVersion>v4.7.2</TargetFrameworkVersion>
    <FileAlignment>512</FileAlignment>
    <AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
    <Deterministic>true</Deterministic>
  </PropertyGroup>
  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
    <PlatformTarget>AnyCPU</PlatformTarget>
    <DebugSymbols>true</DebugSymbols>
    <DebugType>full</DebugType>
    <Optimize>false</Optimize>
    <OutputPath>bin\Debug\</OutputPath>
    <DefineConstants>DEBUG;TRACE</DefineConstants>
    <ErrorReport>prompt</ErrorReport>
    <WarningLevel>4</WarningLevel>
  </PropertyGroup>
  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
    <PlatformTarget>AnyCPU</PlatformTarget>
    <DebugType>pdbonly</DebugType>
    <Optimize>true</Optimize>
    <OutputPath>bin\Release\</OutputPath>
    <DefineConstants>TRACE</DefineConstants>
    <ErrorReport>prompt</ErrorReport>
    <WarningLevel>4</WarningLevel>
  </PropertyGroup>
  <ItemGroup>
    <Reference Include="System" />
    <Reference Include="System.Core" />
    <Reference Include="System.Xml.Linq" />
    <Reference Include="System.Data.DataSetExtensions" />
    <Reference Include="Microsoft.CSharp" />
    <Reference Include="System.Data" />
    <Reference Include="System.Net.Http" />
    <Reference Include="System.Xml" />
  </ItemGroup>
  <ItemGroup>
    <Compile Include="Program.cs" />
    <Compile Include="Properties\AssemblyInfo.cs" />
  </ItemGroup>
  <ItemGroup>
    <None Include="App.config" />
  </ItemGroup>
  <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>

的app.config:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
    <startup> 
        <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.7.2" />
    </startup>
</configuration>

AssemblyInfo.cs中:

using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
[assembly: AssemblyTitle("ConsoleApp1")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("ConsoleApp1")]
[assembly: AssemblyCopyright("Copyright ©  2019")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
[assembly: ComVisible(false)]
[assembly: Guid("ebba72c6-5087-4d8e-9f2c-b968abd59eaa")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]

我已經從您提供的來源構建了項目,但是無法重現該問題:

調試器顯示

這意味着在全新安裝的VS 2017上,該功能必須正常工作。 因此,您的Visual Studio安裝必須以某種方式損壞。

經過評論中的調查后,我建議您進行安裝維修,它應該可以解決問題。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM