Visual Studio keeps showing the bin folder in my project
Asked Answered
B

2

5

I am using Visual Studio 2019 for my C# based solution and I use Git for source control. Yesterday I added two new .NET 2.0 standard SDK projects to my solution and for some reason VS keeps showing the bin folder in the solution explorer for these projects. They have a red icon on them. Does anyone know what that means and how can I get rid of them? enter image description here

Bibliofilm answered 17/8, 2021 at 17:55 Comment(7)
Do you have the bin folders excluded from source control? (Do they show up in git status)?Anomalism
When I run git status in the project folder, it does not show the bin folder in the output. May be I accidentally did something that is causing it. BTW, the .gitignore already has all bin folders excluded. How else can I check what is causing this item to show up in VS Solution explorer or its status in git?Bibliofilm
Do you have the "show all files" icon enabled in the top of the solution explorer? (If I do, it looks different, though). Have you checked whether the projects contain a reference to that folder (other than naming it as the output, of course)?Anomalism
The "show all files" is not selected and the "bin" folder is not referenced in the csproj file either. It must be something to do with git somehow. I just cannot figure out how to check that.Bibliofilm
Git maybe a good catch. Check you .gitignore file(s). They should only exclude bin, not any subfolder of it.Anomalism
I realized the cause of this behavior. It is because I am excluding the output of the project compilation to be included in the nuget package because these are analyzer projects. <None Include="$(OutputPath)\$(AssemblyName).dll" Pack="true" PackagePath="analyzers/dotnet/cs" Visible="false" />Bibliofilm
Weird... you might post the above as answerAnomalism
B
4

I realized the cause of this behavior. It is because I am excluding the output of the project compilation to be included in the nuget package because these are analyzer projects.

<None Include="$(OutputPath)\$(AssemblyName).dll" Pack="true" PackagePath="analyzers/dotnet/cs" Visible="false" />

Bibliofilm answered 15/10, 2021 at 20:33 Comment(2)
I recently noticed this too, and ended up here searching for answers. So is this just the way it is? If you're working on an analyzer, you see the bin folder? Or did you ever discover some way to hide it?Coolth
I think @Pharaz should be the accepted answer now as that resolves it.Siliceous
J
2

You can use TfmSpecificPackageFile instead of <None Include.... This is what the analyzer template of Visual Studio generates and by using it, the bin folder won't be shown in the solution explorer.

<PropertyGroup>
  <TargetsForTfmSpecificContentInPackage>$(TargetsForTfmSpecificContentInPackage);_AddAnalyzersToOutput</TargetsForTfmSpecificContentInPackage>
</PropertyGroup>

<Target Name="_AddAnalyzersToOutput">
  <ItemGroup>
    <TfmSpecificPackageFile Include="$(OutputPath)\$(AssemblyName).dll" PackagePath="analyzers/dotnet/cs" />
  </ItemGroup>
</Target>
Johannesburg answered 20/8, 2023 at 23:38 Comment(1)
Worked for me. If your project is multi targeted you will need to limit the item group to a specific target to avoid multiple copies of the dll to analyzers/dotnet/cs which errors.Siliceous

© 2022 - 2024 — McMap. All rights reserved.