【问题标题】:Autoformatting with Visual Studio 2010使用 Visual Studio 2010 自动格式化
【发布时间】:2011-11-04 20:50:55
【问题描述】:

我刚从 Visual Studio 2008 切换到 Visual Studio 2010,还安装了 ReSharper 6。

在 switch 语句中将行粘贴到 case 块中时,这些行不会像在 Visual Studio 2008 中那样自动缩进。我已经尝试了在 Visual Studio 和 ReSharper 中可以找到的所有设置,但没有成功。我可能错过了什么设置?

我已经尝试过智能和块缩进,并且选中了“粘贴时自动格式化”。

我还卸载了 ReSharper,但它仍然无法正常工作。这是 Visual Studio 2010 中的内容。

switch 语句块内的示例:

光标不在第一列时粘贴一行代码

dockPanelFilters.Visibility = DockVisibility.Visible;
dockPanelFilters.Dock = DockingStyle.Left;
dockPanelFilters.Dock = DockingStyle.Left;

我希望看到的是:

dockPanelFilters.Visibility = DockVisibility.Visible;
dockPanelFilters.Dock = DockingStyle.Left;
dockPanelFilters.Dock = DockingStyle.Left;

脑残简单的东西,它在 Visual Studio 2008 中工作。

当前设置:

  • 工具/选项/文本编辑器/C#/Tabs = smart, 4, 插入空格

  • 工具/选项/文本编辑器/C#/Formatting = 全部选中

  • Tools/Options/Text Editor/C#/Indentation = 全部选中,除了 Indent 开括号和闭括号

  • 工具/选项/文本编辑器/C#/新行 = 全部选中

  • 工具/选项/文本编辑器/C#/Spacing = 仅选中第一个框

  • 工具/选项/文本编辑器/C#/Wrapping = 仅检查第一个块

 

<UserSettings>
    <ApplicationIdentity version="10.0"/>
    <ToolsOptions>
        <ToolsOptionsCategory name="TextEditor" RegisteredName="TextEditor">
            <ToolsOptionsSubCategory name="CSharp" RegisteredName="CSharp" PackageName="Text Management Package">
                <PropertyValue name="TabSize">4</PropertyValue>
                <PropertyValue name="AutoListMembers">false</PropertyValue>
                <PropertyValue name="IndentStyle">2</PropertyValue>
                <PropertyValue name="HideAdvancedMembers">true</PropertyValue>
                <PropertyValue name="ShowNavigationBar">true</PropertyValue>
                <PropertyValue name="VirtualSpace">false</PropertyValue>
                <PropertyValue name="InsertTabs">false</PropertyValue>
                <PropertyValue name="WordWrapGlyphs">true</PropertyValue>
                <PropertyValue name="EnableLeftClickForURLs">true</PropertyValue>
                <PropertyValue name="ShowLineNumbers">false</PropertyValue>
                <PropertyValue name="WordWrap">false</PropertyValue>
                <PropertyValue name="IndentSize">4</PropertyValue>
                <PropertyValue name="CutCopyBlankLines">true</PropertyValue>
                <PropertyValue name="AutoListParams">false</PropertyValue>
            </ToolsOptionsSubCategory>
            <ToolsOptionsSubCategory name="CSharp-Specific" RegisteredName="CSharp-Specific" PackageName="Visual C# Language Service Package">
                <PropertyValue name="NewLines_QueryExpression_EachClause">1</PropertyValue>
                <PropertyValue name="Space_Normalize">0</PropertyValue>
                <PropertyValue name="Space_AroundBinaryOperator">1</PropertyValue>
                <PropertyValue name="Formatting_TriggerOnPaste">1</PropertyValue>
                <PropertyValue name="UnboundItem_ExactMatches">5</PropertyValue>
                <PropertyValue name="GenerateConstructorSmartTagEnabled">1</PropertyValue>
                <PropertyValue name="CompleteOnSpace">1</PropertyValue>
                <PropertyValue name="WarnWhenMembersCauseCompilerGeneratedReferences">1</PropertyValue>
                <PropertyValue name="CollapseInactiveBlocksOnOpen">1</PropertyValue>
                <PropertyValue name="Watson_MaxExceptionsToReport">1</PropertyValue>
                <PropertyValue name="EditAndContinueReportEnterBreakStateFailure">1</PropertyValue>
                <PropertyValue name="TrackMostRecentlyUsed">1</PropertyValue>
                <PropertyValue name="FilterKeywordsContextually">1</PropertyValue>
                <PropertyValue name="BringUpOnSpace">1</PropertyValue>
                <PropertyValue name="Rename_Preview">1</PropertyValue>
                <PropertyValue name="EncapsulateField_PreviewReferenceChanges">1</PropertyValue>
                <PropertyValue name="DelayBeforeShowingErrors">1500</PropertyValue>
                <PropertyValue name="CollapseRegionBlocksOnOpen">1</PropertyValue>
                <PropertyValue name="NewLines_Braces_Method">1</PropertyValue>
                <PropertyValue name="HighlightReferences">0</PropertyValue>
                <PropertyValue name="RefactorNotifyRenameEnabled">1</PropertyValue>
                <PropertyValue name="OnlyScanFirstTypeInFileForDesignerAttribute">0</PropertyValue>
                <PropertyValue name="Indent_CaseLabels">1</PropertyValue>
                <PropertyValue name="Formatting_TriggerOnBlockCompletion">1</PropertyValue>
                <PropertyValue name="CompletionCommitCharacters">{}[]().,:;+-*/%&amp;|^!~=&lt;&gt;?@#'"\</PropertyValue>
                <PropertyValue name="EditAndContinueEnabled">1</PropertyValue>
                <PropertyValue name="InsertNewlineOnEnterWithWholeWord">0</PropertyValue>
                <PropertyValue name="BringUpOnOverride">1</PropertyValue>
                <PropertyValue name="CodeDefinitionWindow_DocumentationComment_IndentOffset">2</PropertyValue>
                <PropertyValue name="Rename_Comments">0</PropertyValue>
                <PropertyValue name="Squiggles_SemanticAnalysis">0</PropertyValue>
                <PropertyValue name="NewLines_Braces_ControlFlow">1</PropertyValue>
                <PropertyValue name="NewLines_Braces_AnonymousMethod">1</PropertyValue>
                <PropertyValue name="Space_WithinOtherParentheses">0</PropertyValue>
                <PropertyValue name="BringUpOnIdentifier">1</PropertyValue>
                <PropertyValue name="RemoveParameters_PreviewReferenceChanges">1</PropertyValue>
                <PropertyValue name="Wrapping_KeepStatementsOnSingleLine">0</PropertyValue>
                <PropertyValue name="Space_AfterBasesColon">1</PropertyValue>
                <PropertyValue name="Indent_Braces">0</PropertyValue>
                <PropertyValue name="CompleteOnNewline">1</PropertyValue>
                <PropertyValue name="EncapsulateField_UpdateAllReferences">0</PropertyValue>
                <PropertyValue name="Wrapping_IgnoreSpacesAroundVariableDeclaration">0</PropertyValue>
                <PropertyValue name="Space_WithinMethodCallParentheses">0</PropertyValue>
                <PropertyValue name="Space_AfterCast">0</PropertyValue>
                <PropertyValue name="Colorize">1</PropertyValue>
                <PropertyValue name="EditAndContinueReportOpenScopeFailure">0</PropertyValue>
                <PropertyValue name="FilterToAllowableTypes">1</PropertyValue>
                <PropertyValue name="SortUsings_PlaceSystemFirst">1</PropertyValue>
                <PropertyValue name="NewLines_Braces_CollectionInitializer">0</PropertyValue>
                <PropertyValue name="Watson_DeferSendingUntilLater">0</PropertyValue>
                <PropertyValue name="ShowKeywords">1</PropertyValue>
                <PropertyValue name="ShowSnippets">1</PropertyValue>
                <PropertyValue name="BraceMatchingRectangle">1</PropertyValue>
                <PropertyValue name="NewLines_AnonymousTypeInitializer_EachMember">1</PropertyValue>
                <PropertyValue name="NewLines_Keywords_Catch">1</PropertyValue>
                <PropertyValue name="NewLines_Braces_ObjectInitializer">1</PropertyValue>
                <PropertyValue name="NewLines_Braces_ArrayInitializer">0</PropertyValue>
                <PropertyValue name="Space_WithinExpressionParentheses">0</PropertyValue>
                <PropertyValue name="Space_InControlFlowConstruct">1</PropertyValue>
                <PropertyValue name="Formatting_TriggerOnStatementCompletion">1</PropertyValue>
                <PropertyValue name="CodeDefinitionWindow_DocumentationComment_WrapLength">80</PropertyValue>
                <PropertyValue name="NewLines_Keywords_Finally">1</PropertyValue>
                <PropertyValue name="Space_BetweenEmptyMethodDeclarationParentheses">0</PropertyValue>
                <PropertyValue name="Indent_UnindentLabels">1</PropertyValue>
                <PropertyValue name="SmartTagEnabled">1</PropertyValue>
                <PropertyValue name="SortUsings">1</PropertyValue>
                <PropertyValue name="Rename_Strings">0</PropertyValue>
                <PropertyValue name="NewLines_ObjectInitializer_EachMember">1</PropertyValue>
                <PropertyValue name="NewLines_Keywords_Else">1</PropertyValue>
                <PropertyValue name="TimeSliceForQuickSearchCaching">50</PropertyValue>
                <PropertyValue name="EnableProgressDialogOnWaitForBackground">1</PropertyValue>
                <PropertyValue name="Space_WithinMethodDeclarationParentheses">0</PropertyValue>
                <PropertyValue name="Space_BetweenEmptyMethodCallParentheses">0</PropertyValue>
                <PropertyValue name="Space_BeforeSemicolonsInForStatement">0</PropertyValue>
                <PropertyValue name="Space_BeforeComma">0</PropertyValue>
                <PropertyValue name="Space_AfterMethodCallName">0</PropertyValue>
                <PropertyValue name="Space_AfterComma">1</PropertyValue>
                <PropertyValue name="ExtractInterface_SelectAll">0</PropertyValue>
                <PropertyValue name="ReorderParameters_PreviewReferenceChanges">1</PropertyValue>
                <PropertyValue name="Wrapping_IgnoreSpacesAroundBinaryOperators">0</PropertyValue>
                <PropertyValue name="Space_BeforeBasesColon">1</PropertyValue>
                <PropertyValue name="Space_AfterMethodDeclarationName">0</PropertyValue>
                <PropertyValue name="Space_AfterDot">0</PropertyValue>
                <PropertyValue name="UnboundItemSmartTagEnabled">1</PropertyValue>
                <PropertyValue name="AutoComment">1</PropertyValue>
                <PropertyValue name="NewLines_Braces_Type">1</PropertyValue>
                <PropertyValue name="Space_AfterLambdaArrow">1</PropertyValue>
                <PropertyValue name="ImplementInterfaceSmartTagEnabled">1</PropertyValue>
                <PropertyValue name="BringUpOnPartial">1</PropertyValue>
                <PropertyValue name="CodeDefinitionWindow_DocumentationComment_IndentBase">1</PropertyValue>
                <PropertyValue name="EncapsulateField_SearchInStrings">0</PropertyValue>
                <PropertyValue name="TimeSliceForQuickSearchSearching">50</PropertyValue>
                <PropertyValue name="EnterOutliningModeOnOpen">0</PropertyValue>
                <PropertyValue name="NewLines_Braces_LambdaExpressionBody">1</PropertyValue>
                <PropertyValue name="Space_WithinSquares">0</PropertyValue>
                <PropertyValue name="Space_BeforeLambdaArrow">1</PropertyValue>
                <PropertyValue name="ShowHiddenItems">0</PropertyValue>
                <PropertyValue name="Squiggles">0</PropertyValue>
                <PropertyValue name="NewLines_Braces_AnonymousTypeInitializer">1</PropertyValue>
                <PropertyValue name="Space_WithinCastParentheses">0</PropertyValue>
                <PropertyValue name="Space_AfterSemicolonsInForStatement">1</PropertyValue>
                <PropertyValue name="Indent_CaseContents">1</PropertyValue>
                <PropertyValue name="Indent_FlushLabelsLeft">0</PropertyValue>
                <PropertyValue name="Watson_ReportExceptions">1</PropertyValue>
                <PropertyValue name="GenerateStubSmartTagEnabled">1</PropertyValue>
                <PropertyValue name="BringUpOnEventHookup">1</PropertyValue>
                <PropertyValue name="ImplementInterface_InsertRegionTags">0</PropertyValue>
                <PropertyValue name="Wrapping_PreserveSingleLine">1</PropertyValue>
                <PropertyValue name="Space_BetweenEmptySquares">0</PropertyValue>
                <PropertyValue name="Space_BeforeOpenSquare">0</PropertyValue>
                <PropertyValue name="Space_BeforeDot">0</PropertyValue>
                <PropertyValue name="Indent_BlockContents">1</PropertyValue>
                <PropertyValue name="RenameSmartTagEnabled">1</PropertyValue>
                <PropertyValue name="ColorizeBoundTypes">1</PropertyValue>
                <PropertyValue name="RemoveUnusedUsings">1</PropertyValue>
                <PropertyValue name="Rename_Overloads">0</PropertyValue>
                <PropertyValue name="EncapsulateField_SearchInComments">0</PropertyValue>
                <PropertyValue name="Refactoring_Verification_Enabled">0</PropertyValue>
                <PropertyValue name="ProgressDialogDelaySeconds">2</PropertyValue>
            </ToolsOptionsSubCategory>
        </ToolsOptionsCategory>
    </ToolsOptions>
</UserSettings>

【问题讨论】:

    标签: .net visual-studio-2010 visual-studio resharper-6.0


    【解决方案1】:

    其他人指出,如果文件中有语法错误,自动格式化将不起作用,所以我认为这不是你的问题。

    您是否尝试过重置 VS 设置或从已知的良好配置导入设置?对于那些不知道的人,您可以通过Tools 菜单中的Import and Export Settings Wizard 导入/导出/重置环境设置。如果不出意外,这将有助于排除环境设置的问题。

    我已导出我的 C# Editor 设置(包括高级、格式化和 IntelliSense 节点下的设置),因此您可以导入它们或根据需要进行比较:

    (如果您想尝试导入这些设置,请使用.vssettings 扩展名保存以下内容并通过向导导入)

    <UserSettings>
        <ApplicationIdentity version="10.0"/>
        <ToolsOptions>
            <ToolsOptionsCategory name="TextEditor" RegisteredName="TextEditor">
                <ToolsOptionsSubCategory name="CSharp-Specific" RegisteredName="CSharp-Specific" PackageName="Visual C# Language Service Package">
                    <PropertyValue name="NewLines_QueryExpression_EachClause">1</PropertyValue>
                    <PropertyValue name="Space_Normalize">0</PropertyValue>
                    <PropertyValue name="Space_AroundBinaryOperator">1</PropertyValue>
                    <PropertyValue name="Formatting_TriggerOnPaste">1</PropertyValue>
                    <PropertyValue name="UnboundItem_ExactMatches">5</PropertyValue>
                    <PropertyValue name="GenerateConstructorSmartTagEnabled">1</PropertyValue>
                    <PropertyValue name="CompleteOnSpace">1</PropertyValue>
                    <PropertyValue name="WarnWhenMembersCauseCompilerGeneratedReferences">1</PropertyValue>
                    <PropertyValue name="CollapseInactiveBlocksOnOpen">1</PropertyValue>
                    <PropertyValue name="Watson_MaxExceptionsToReport">1</PropertyValue>
                    <PropertyValue name="EditAndContinueReportEnterBreakStateFailure">1</PropertyValue>
                    <PropertyValue name="TrackMostRecentlyUsed">1</PropertyValue>
                    <PropertyValue name="FilterKeywordsContextually">1</PropertyValue>
                    <PropertyValue name="BringUpOnSpace">1</PropertyValue>
                    <PropertyValue name="Rename_Preview">0</PropertyValue>
                    <PropertyValue name="EncapsulateField_PreviewReferenceChanges">1</PropertyValue>
                    <PropertyValue name="DelayBeforeShowingErrors">1500</PropertyValue>
                    <PropertyValue name="CollapseRegionBlocksOnOpen">1</PropertyValue>
                    <PropertyValue name="NewLines_Braces_Method">1</PropertyValue>
                    <PropertyValue name="HighlightReferences">1</PropertyValue>
                    <PropertyValue name="RefactorNotifyRenameEnabled">1</PropertyValue>
                    <PropertyValue name="OnlyScanFirstTypeInFileForDesignerAttribute">0</PropertyValue>
                    <PropertyValue name="Indent_CaseLabels">1</PropertyValue>
                    <PropertyValue name="Formatting_TriggerOnBlockCompletion">1</PropertyValue>
                    <PropertyValue name="CompletionCommitCharacters">{}[]().,:;+-*/%&amp;|^!~=&lt;&gt;?@#'"\</PropertyValue>
                    <PropertyValue name="EditAndContinueEnabled">1</PropertyValue>
                    <PropertyValue name="InsertNewlineOnEnterWithWholeWord">0</PropertyValue>
                    <PropertyValue name="BringUpOnOverride">1</PropertyValue>
                    <PropertyValue name="CodeDefinitionWindow_DocumentationComment_IndentOffset">2</PropertyValue>
                    <PropertyValue name="Rename_Comments">0</PropertyValue>
                    <PropertyValue name="Squiggles_SemanticAnalysis">1</PropertyValue>
                    <PropertyValue name="NewLines_Braces_ControlFlow">1</PropertyValue>
                    <PropertyValue name="NewLines_Braces_AnonymousMethod">1</PropertyValue>
                    <PropertyValue name="Space_WithinOtherParentheses">0</PropertyValue>
                    <PropertyValue name="BringUpOnIdentifier">1</PropertyValue>
                    <PropertyValue name="RemoveParameters_PreviewReferenceChanges">1</PropertyValue>
                    <PropertyValue name="Wrapping_KeepStatementsOnSingleLine">1</PropertyValue>
                    <PropertyValue name="Space_AfterBasesColon">1</PropertyValue>
                    <PropertyValue name="Indent_Braces">0</PropertyValue>
                    <PropertyValue name="CompleteOnNewline">1</PropertyValue>
                    <PropertyValue name="EncapsulateField_UpdateAllReferences">0</PropertyValue>
                    <PropertyValue name="Wrapping_IgnoreSpacesAroundVariableDeclaration">0</PropertyValue>
                    <PropertyValue name="Space_WithinMethodCallParentheses">0</PropertyValue>
                    <PropertyValue name="Space_AfterCast">0</PropertyValue>
                    <PropertyValue name="Colorize">1</PropertyValue>
                    <PropertyValue name="EditAndContinueReportOpenScopeFailure">0</PropertyValue>
                    <PropertyValue name="FilterToAllowableTypes">1</PropertyValue>
                    <PropertyValue name="SortUsings_PlaceSystemFirst">1</PropertyValue>
                    <PropertyValue name="NewLines_Braces_CollectionInitializer">0</PropertyValue>
                    <PropertyValue name="Watson_DeferSendingUntilLater">0</PropertyValue>
                    <PropertyValue name="ShowKeywords">1</PropertyValue>
                    <PropertyValue name="ShowSnippets">1</PropertyValue>
                    <PropertyValue name="BraceMatchingRectangle">1</PropertyValue>
                    <PropertyValue name="NewLines_AnonymousTypeInitializer_EachMember">1</PropertyValue>
                    <PropertyValue name="NewLines_Keywords_Catch">1</PropertyValue>
                    <PropertyValue name="NewLines_Braces_ObjectInitializer">1</PropertyValue>
                    <PropertyValue name="NewLines_Braces_ArrayInitializer">0</PropertyValue>
                    <PropertyValue name="Space_WithinExpressionParentheses">0</PropertyValue>
                    <PropertyValue name="Space_InControlFlowConstruct">1</PropertyValue>
                    <PropertyValue name="Formatting_TriggerOnStatementCompletion">1</PropertyValue>
                    <PropertyValue name="CodeDefinitionWindow_DocumentationComment_WrapLength">80</PropertyValue>
                    <PropertyValue name="NewLines_Keywords_Finally">1</PropertyValue>
                    <PropertyValue name="Space_BetweenEmptyMethodDeclarationParentheses">0</PropertyValue>
                    <PropertyValue name="Indent_UnindentLabels">1</PropertyValue>
                    <PropertyValue name="SmartTagEnabled">1</PropertyValue>
                    <PropertyValue name="SortUsings">1</PropertyValue>
                    <PropertyValue name="Rename_Strings">0</PropertyValue>
                    <PropertyValue name="NewLines_ObjectInitializer_EachMember">1</PropertyValue>
                    <PropertyValue name="NewLines_Keywords_Else">1</PropertyValue>
                    <PropertyValue name="TimeSliceForQuickSearchCaching">50</PropertyValue>
                    <PropertyValue name="EnableProgressDialogOnWaitForBackground">1</PropertyValue>
                    <PropertyValue name="Space_WithinMethodDeclarationParentheses">0</PropertyValue>
                    <PropertyValue name="Space_BetweenEmptyMethodCallParentheses">0</PropertyValue>
                    <PropertyValue name="Space_BeforeSemicolonsInForStatement">0</PropertyValue>
                    <PropertyValue name="Space_BeforeComma">0</PropertyValue>
                    <PropertyValue name="Space_AfterMethodCallName">0</PropertyValue>
                    <PropertyValue name="Space_AfterComma">1</PropertyValue>
                    <PropertyValue name="ExtractInterface_SelectAll">0</PropertyValue>
                    <PropertyValue name="ReorderParameters_PreviewReferenceChanges">1</PropertyValue>
                    <PropertyValue name="Wrapping_IgnoreSpacesAroundBinaryOperators">0</PropertyValue>
                    <PropertyValue name="Space_BeforeBasesColon">1</PropertyValue>
                    <PropertyValue name="Space_AfterMethodDeclarationName">0</PropertyValue>
                    <PropertyValue name="Space_AfterDot">0</PropertyValue>
                    <PropertyValue name="UnboundItemSmartTagEnabled">1</PropertyValue>
                    <PropertyValue name="AutoComment">1</PropertyValue>
                    <PropertyValue name="NewLines_Braces_Type">1</PropertyValue>
                    <PropertyValue name="Space_AfterLambdaArrow">1</PropertyValue>
                    <PropertyValue name="ImplementInterfaceSmartTagEnabled">1</PropertyValue>
                    <PropertyValue name="BringUpOnPartial">1</PropertyValue>
                    <PropertyValue name="CodeDefinitionWindow_DocumentationComment_IndentBase">1</PropertyValue>
                    <PropertyValue name="EncapsulateField_SearchInStrings">0</PropertyValue>
                    <PropertyValue name="TimeSliceForQuickSearchSearching">50</PropertyValue>
                    <PropertyValue name="EnterOutliningModeOnOpen">1</PropertyValue>
                    <PropertyValue name="NewLines_Braces_LambdaExpressionBody">1</PropertyValue>
                    <PropertyValue name="Space_WithinSquares">0</PropertyValue>
                    <PropertyValue name="Space_BeforeLambdaArrow">1</PropertyValue>
                    <PropertyValue name="ShowHiddenItems">0</PropertyValue>
                    <PropertyValue name="Squiggles">1</PropertyValue>
                    <PropertyValue name="NewLines_Braces_AnonymousTypeInitializer">1</PropertyValue>
                    <PropertyValue name="Space_WithinCastParentheses">0</PropertyValue>
                    <PropertyValue name="Space_AfterSemicolonsInForStatement">1</PropertyValue>
                    <PropertyValue name="Indent_CaseContents">1</PropertyValue>
                    <PropertyValue name="Indent_FlushLabelsLeft">0</PropertyValue>
                    <PropertyValue name="Watson_ReportExceptions">1</PropertyValue>
                    <PropertyValue name="GenerateStubSmartTagEnabled">1</PropertyValue>
                    <PropertyValue name="BringUpOnEventHookup">1</PropertyValue>
                    <PropertyValue name="ImplementInterface_InsertRegionTags">0</PropertyValue>
                    <PropertyValue name="Wrapping_PreserveSingleLine">1</PropertyValue>
                    <PropertyValue name="Space_BetweenEmptySquares">0</PropertyValue>
                    <PropertyValue name="Space_BeforeOpenSquare">0</PropertyValue>
                    <PropertyValue name="Space_BeforeDot">0</PropertyValue>
                    <PropertyValue name="Indent_BlockContents">1</PropertyValue>
                    <PropertyValue name="RenameSmartTagEnabled">1</PropertyValue>
                    <PropertyValue name="ColorizeBoundTypes">1</PropertyValue>
                    <PropertyValue name="RemoveUnusedUsings">1</PropertyValue>
                    <PropertyValue name="Rename_Overloads">0</PropertyValue>
                    <PropertyValue name="EncapsulateField_SearchInComments">0</PropertyValue>
                    <PropertyValue name="Refactoring_Verification_Enabled">0</PropertyValue>
                    <PropertyValue name="ProgressDialogDelaySeconds">2</PropertyValue>
                </ToolsOptionsSubCategory>
            </ToolsOptionsCategory>
        </ToolsOptions>
        <Category name="Database Tools" RegisteredName="Database Tools"/>
    </UserSettings>
    

    【讨论】:

      【解决方案2】:

      我可以与您分享这种经验。粘贴后的缩进问题,至少对我来说是一个常见的问题。不过,没有解决方案不是问题。

      我选择我不想缩进的实际代码,然后快捷键 CTRL+K+F。一个简单的 remove 'n re-type 末端支架也可以修复标识。不是自动格式化粘贴,但仍然不需要手动缩进。

      【讨论】:

        【解决方案3】:

        您可以尝试设置“缩进大小写内容”。它在 Options -> Text Editor -> C# -> Formatting -> Indentation em>。

        顺便说一句,您可以在粘贴后随时按 Ctrl + KD 来正确格式化粘贴的代码。

        【讨论】:

        • 你安装了 resharper 6 吗?缩进设置对我不起作用。我可能只是卸载 resharper 6 看看它做了什么,应该已经这样做了。
        【解决方案4】:

        如果有任何语法错误,自动格式化将不起作用。粘贴代码后,请确保没有语法错误。如果有,请修复它们,然后这应该可以工作。

        刚刚测试了您的代码,它在 Visual Studio 2010 上运行良好。以下是我的设置

        Tools -> Options -> Text Editor -> C# -> Formatting -> General
        

        你说...

        工具/选项/文本编辑器/C#/Spacing = 仅选中第一个框

        工具/选项/文本编辑器/C#/Wrapping = 仅检查第一个块

        我有不同的间距和环绕设置。您的设置中可能有问题,因为这对我来说非常适合。

        我认为粘贴代码后会出现错误。在这种情况下,我可以复制您的问题。请记住,自动格式化仅在没有错误时才有效。

        我刚刚导入了您的设置并尝试了。如果您将代码粘贴在案例中的大括号内,它会自动正确格式化。如果没有大括号,则无法正确自动格式化。

        switch (taskNumber)
        {
            case 1:
            {
                // If you paste your code here. Within curly brackets, it automatically formats correctly.
            }
        }
        
        switch (taskNumber)
        {
            case 1:
                // If you paste your code here. Without curly brackets for the case, it does not automatically formats correctly.
        }
        

        【讨论】:

        • 你安装了 resharper 6 吗?我已经尝试了您的设置,但它们不起作用。
        • 我已经安装了 Resharper 5.1。但此功能来自 Visual Studio IDE。将此代码粘贴到案例中后确定没有任何错误吗?
        • 因个人喜好无法使用间距设置。我已经完成了vs2010的修复安装,没有帮助。我已经重置了设置并加载了已知的好设置。代码在粘贴前后没有错误。我已经使用 vs 版本至少 15 年了,所以我或多或少知道会发生什么。这个问题很奇怪。
        • @Paul:这是否仅在 Resharper 6 激活时才会发生?您是否尝试过不使用 Resharper 6?我的机器上没有安装 Resharper6。但是,AFAIK resharper 对自动格式化没有任何作用,但可能存在中断 VS 自动格式化的错误?
        • 是的,我卸载了 resharper6,没有任何变化。我还查看了我的其他扩展和附加组件。唯一的扩展是 nuget,而 testdriven 和 gallio 是唯一的附加组件。我害怕卸载所有东西并重新安装 vs2010 的想法,但可能不得不尝试一下。
        猜你喜欢
        • 1970-01-01
        • 2013-04-18
        • 2012-01-03
        • 1970-01-01
        • 2011-05-23
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多