29

Is it possible to hide files/folders in .net core csproj without excluding them from build? I have a folder containing generated files which I would rather see they are not visible inside Solution Explorer in Visual Studio.

2 Answers 2

52

You can set the Visible="false" attribute on the items.

For an SDK-based project (.net core / asp.net core templates), you could add e.g.:

<ItemGroup> <Content Update="**/*.css" Visible="false" /> </ItemGroup> 

Depending on your project type (=> defaults), you might have to replace Content with None for the particular type, or even Compile for generated code files.

Sign up to request clarification or add additional context in comments.

7 Comments

Is it possible to hide folder too? This hides all files in folder Generated, but the empty folder is still visible... <Compile Update="Generated\**" Visible="false" />
To my knowledge, this is not possible. Many new tools try to autogenerate into obj ($(BaseIntermediateOutputPath)) and include the items during the build and not as static ("root level") items using the Link metadata... But yes I also have stray dist / css folders etc.
Is this supposed to work with .Net Core projects? I added the Visible tag and the file still shows in solution explorer.
For NetCore and NetStandard It would not work for me unless I used None. <None Remove="**/*.asmdef" Visible="false"/>
By me it isn't available as attribute only as an element <Visible>False</visible>
|
0

Thanks to Martin answer, I found a way to apply it to a whole folder using **\**. For example for an ASP.NET Core wwwroot\Scripts folder which contains files compiled by TypeScript (TypeScriptCompile):

 <ItemGroup> <TypeScriptCompile Update="wwwroot\Scripts\**\**" Visible="False" /> <Content Update="wwwroot\Scripts\**\**" Visible="False" /> </ItemGroup> 

As his answer noted, you can add more type in there like None.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.