Visual Studio 2022- File Ignored always ignore when adding to class libraray

Dani_S 5,561 Reputation points
2025-12-11T17:39:46.8933333+00:00

Hi,

Please see the following screenshot, why adding a new new file I always need to

use Git/Add ignore file (right click on the file) ?

It happened in class library as follow: TargetFramework>netstandard2.0</TargetFramework>

Thanks in advance,

User's image

Developer technologies | Visual Studio | Extensions
{count} votes

2 answers

Sort by: Most helpful
  1. Surya Amrutha Vaishnavi Lanka (INFOSYS LIMITED) 1,725 Reputation points Microsoft External Staff
    2025-12-12T12:19:23.12+00:00

    Thanks for reaching out!

    Here are some steps to fix the issue

    1. Check Your .gitignore File: Make sure you don't have patterns in your .gitignore file that are matching the new files you are trying to add. You can find this file in your project's root directory. If it's not there, maybe create one to customize which files should be ignored
    2. Create or Modify the .tfignore File: If you are using Team Foundation Version Control (TFVC), you can also utilize a .tfignore file. This file works similarly to .gitignore. Place it in your project directory to specify which files should be ignored by source control.
    3. Check Local Workspace Settings: In some cases, certain file types might be automatically excluded based on your workspace settings. Review the settings to ensure your new files' types are not inadvertently excluded.
    4. Visual Studio Integration: If it's a specific file type that you want to work with and you've previously ignored it, you can right-click on the file in the Git Changes window and select Ignore this local item to update your .gitignore file accordingly. This will help in managing ignored files more effectively.
    5. Keep It Updated: Ensure your installed packages and updates to Visual Studio are current. Bugs are often fixed in newer updates that may address your issue.

  2. Varsha Dundigalla(INFOSYS LIMITED) 4,325 Reputation points Microsoft External Staff
    2025-12-22T13:00:30.6266667+00:00

    Thank you got reaching out.

    This behavior is not a Visual Studio issue and it is not caused by using netstandard2.0 or netstandard2.1.

    Git decides whether a file is ignored, not Visual Studio. Visual Studio only shows the file status that Git reports.

    We reached this conclusion based on these clear facts:

    • The problem happens only in the Class Library project, but not in the Console, WPF, or Test projects.
    • All projects are in the same solution, using the same Visual Studio 2022, the same Git repository, and the same Git settings.
    • If this were a Visual Studio defect or a .NET target‑framework issue, all projects would show the same behavior. They do not.
    • The .gitignore file you shared is a standard Visual Studio template and does not ignore .cs files.

    Git ignore rules can be folder‑specific. This means a rule can apply only to a certain directory path.
    Because only the Class Library project folder is affected, the ignore rule must be scoped to that folder path.

    That ignore rule can come from:

    • a nested .gitignore file inside or above the Class Library folder,
    • the local repository exclude file (.git/info/exclude),
    • or a global Git ignore file on the machine.

    This explains why:

    • new .cs files in the Class Library appear as ignored,
    • you must manually use Git → Add,
    • but other project types work normally.

    Conclusion:

    Git is applying a path‑specific ignore rule that affects only the Class Library folder.
    Visual Studio is correctly reflecting Git’s decision.
    The behavior is expected Git behavior and not a Visual Studio bug or a .NET framework issue.

    Once that ignore rule is identified and corrected, newly added .cs files in the Class Library will be tracked automatically, just like in the other projects.

    Please let us know if you require any further assistance, we’re happy to help. If you found this information useful, kindly mark this as "Accept Answer". So that others in the community facing similar issues can easily find the solution. Your contribution is highly appreciated.


Your answer

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