roslyn icon indicating copy to clipboard operation
roslyn copied to clipboard

When executing "Format document" of "Code cleanup" on save, it does not honor editorconfig, if source file build action is set to "None"

Open vsfeedback opened this issue 1 year ago • 0 comments

This issue has been moved from a ticket on Developer Community.


[severity:It's more difficult to complete my work] I have configured the following code fixers in Code Cleanup:

  • Format document
  • Remove unnecessary imports or usings
  • Sort imports or usings

Code Cleanup is also configured to run on save (i.e., when I press Ctrl+S).

This works fine when a C# file is included as a compilation item (i.e. <Compile Include="file.cs" />), but fails, if the build action is set to "None" (i.e. <None Include="file.cs" />).

If used in a file with build action set to None, the file is formatted using Visual Studio default settings e.g. spaces instead of tabs and it's not honoring any other settings in .editorconfig. This does not happen if I use the "Format document" option in the "Edit" menu or "dotnet format whitespace" on the command-line. "None" items remain formatted as I want it.

Another issue with "Remove unnecessary usings" and "Sort usings" is that usings get deleted even though they are required, if the file has its build action set to "None".

What bothers me is that, if I change such a file a bit and then try to save it, Visual Studio butchers the list of usings and the formatting. It is impossible to skip the code cleanup for those files, so I have to copy all my changes, close the file unsaved, then open it in an external editor and replace the old text, with the one from clipboard.

Microsoft Visual Studio Community 2022 Version 17.10.5 VisualStudio.17.Release/17.10.5+35122.118 Microsoft .NET Framework Version 4.8.09037

Installed Version: Community

Visual C++ 2022 00482-90000-00000-AA650 Microsoft Visual C++ 2022

ASP.NET and Web Tools 17.10.344.38934 ASP.NET and Web Tools

Azure App Service Tools v3.0.0 17.10.344.38934 Azure App Service Tools v3.0.0

C# Tools 4.10.0-3.24324.8+04fb39164c99c519832109f21b22630bc9246fce C# components used in the IDE. Depending on your project type and settings, a different version of the compiler may be used.

Cookiecutter 17.0.24064.1 Provides tools for finding, instantiating and customizing templates in cookiecutter format.

Extensibility Message Bus 1.4.39 (main@e8108eb) Provides common messaging-based MEF services for loosely coupled Visual Studio extension components communication and integration.

GitHub Copilot 0.2.894.62884 GitHub Copilot is an AI pair programmer that helps you write code faster and with less work.

Microsoft JVM Debugger 1.0 Provides support for connecting the Visual Studio debugger to JDWP compatible Java Virtual Machines

Mono Debugging for Visual Studio 17.10.11 (c9f079d) Support for debugging Mono processes with Visual Studio.

Node.js Tools 1.5.60329.1 Commit Hash:15fce86a17f9f33e5bd7ca7ccb9b216aff149252 Adds support for developing and debugging Node.js apps in Visual Studio

NuGet Package Manager 6.10.2 NuGet Package Manager in Visual Studio. For more information about NuGet, visit https://docs.nuget.org/

OpenOnGitHub 1.3 Visual Studio Extension for opening files on GitHub.com

Python - Profiling support 17.0.24064.1 Profiling support for Python projects.

Python with Pylance 17.0.24064.1 Provides IntelliSense, projects, templates, debugging, interactive windows, and other support for Python developers.

Razor (ASP.NET Core) 17.10.3.2427201+4f57d1de251e654812adde201c0265a8ca7ca31d Provides languages services for ASP.NET Core Razor.

Test Adapter for Boost.Test 1.0 Enables Visual Studio's testing tools with unit tests written for Boost.Test. The use terms and Third Party Notices are available in the extension installation directory.

Test Adapter for Google Test 1.0 Enables Visual Studio's testing tools with unit tests written for Google Test. The use terms and Third Party Notices are available in the extension installation directory.

TypeScript Tools 17.0.30327.2001 TypeScript Tools for Microsoft Visual Studio

Visual Basic Tools 4.10.0-3.24324.8+04fb39164c99c519832109f21b22630bc9246fce Visual Basic components used in the IDE. Depending on your project type and settings, a different version of the compiler may be used.

Visual F# Tools 17.10.0-beta.24228.1+dd749058c91585e9b5dae62b0f8df892429ee28f Microsoft Visual F# Tools

Visual Studio IntelliCode 2.2 AI-assisted development for Visual Studio.

VisualStudio.DeviceLog 1.0 Information about my package

VisualStudio.Mac 1.0 Mac Extension for Visual Studio

VSPackage Extension 1.0 VSPackage Visual Studio Extension Detailed Info

Xamarin 17.10.0.110 (main@cf2e960) Visual Studio extension to enable development for Xamarin.iOS and Xamarin.Android.

Xamarin Designer 17.10.3.10 (remotes/origin/d17-10@3beef58f89) Visual Studio extension to enable Xamarin Designer tools in Visual Studio.

Xamarin.Android SDK 13.2.2.0 (d17-5/45b0e14) Xamarin.Android Reference Assemblies and MSBuild support. Mono: d9a6e87 Java.Interop: xamarin/java.interop/d17-5@149d70fe SQLite: xamarin/sqlite/3.40.1@68c69d8 Xamarin.Android Tools: xamarin/xamarin-android-tools/d17-5@ca1552d


Original Comments

Feedback Bot on 8/19/2024, 02:38 AM:

(private comment, text removed)


Original Solutions

(no solutions)

vsfeedback avatar Aug 21 '24 15:08 vsfeedback