C# DebuggerDisplayAttribute在VS 2017中无效
在Visual Studio 2017(15.9.4)和Resharper 2018.2.3中,C# DebuggerDisplayAttribute在VS 2017中无效,c#,visual-studio-2017,resharper,debuggerdisplay,C#,Visual Studio 2017,Resharper,Debuggerdisplay,在Visual Studio 2017(15.9.4)和Resharper 2018.2.3中,DebuggerDisplayAttribute似乎没有任何效果 将属性放置在AssemblyInfo.cs或Program.cs中不会产生明显的效果 我的目标是.NETFramework 4.7.2。更改框架版本也没有明显的效果 我已经在工具->选项->调试->常规中验证了“在变量窗口中显示对象的原始结构”未选中。我甚至检查了它,关闭了VS,重新打开了VS,并取消了它,只是为了确定。没有效果
DebuggerDisplayAttribute
似乎没有任何效果
- 将属性放置在AssemblyInfo.cs或Program.cs中不会产生明显的效果李>
- 我的目标是.NETFramework 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}
。如果我使用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>
我已根据您提供的来源构建了该项目,无法重现该问题: 这意味着在新安装的VS 2017上,该功能必须工作。因此,您的Visual Studio安装一定在某种程度上已损坏
在评论中调查之后,我建议进行安装修复,它应该可以解决问题。我认为问题在于目标类型(
DateTime
)是在不同的程序集中定义的(这是有意义的)。但是:实际上,我已经测试并设置了程序集级别的属性,即使对于int
也有效。VS 2017 15.9.7.哦,我没有安装Resharper。也许这就是区别?好吧,这很奇怪。你能把测试应用程序源文件夹上传到某个地方吗?我无法用你发布的源代码重现这个问题。我想补充一点,重新安装我的扩展,包括Resharper,不会再次发生这种情况。不确定到底是什么,但修复我的VS安装成功了。
<?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>
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.7.2" />
</startup>
</configuration>
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")]