How do I prevent Visual Studio from automatically adding unneeded includes in VB modules

David McDivitt 221 Reputation points
2023-01-17T20:10:10.8+00:00

I often copy modules from one project to another and often times Visual Studio will add several includes at the top of the class. When surveying through source code I find unnecessary includes have been added. If an include is needed I want compilation to fail rather than have it added automatically. How do I turn this off?

Visual Studio
Visual Studio
A family of Microsoft suites of integrated development tools for building applications for Windows, the web and mobile devices.
5,447 questions
VB
VB
An object-oriented programming language developed by Microsoft that is implemented on the .NET Framework. Previously known as Visual Basic .NET.
2,793 questions
0 comments No comments
{count} vote

Accepted answer
  1. Jiachen Li-MSFT 33,701 Reputation points Microsoft External Staff
    2023-01-18T01:57:49.3133333+00:00

    Hi @David McDivitt , You can uncheck Add missing imports on paste.

    It is available in Options→Text Editor→ Visual Basic→Advanced→ Import Directives.

    Best Regards.
    Jiachen Li
    ----------
    If the answer is helpful, please click "Accept Answer" and upvote it.
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    2 people found this answer helpful.
    0 comments No comments

1 additional answer

Sort by: Most helpful
  1. Dirk Seynaeve 0 Reputation points
    2025-03-04T11:42:37.5133333+00:00

    Even with the option (Options→Text Editor→ Visual Basic→Advanced→ Import Directives.) switched off, and after restarting Visual Studio, it continues to adding Imports to my code.

    My version is Microsoft Visual Studio Community 2022 (64-bit) - Version 17.13.2

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.