Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I exclude files/folders from a .NET Core/Standard project?

People also ask

What does it mean to exclude a folder?

If you trust a file, file type, folder, or a process that Windows Security has detected as malicious, you can stop Windows Security from alerting you or blocking the program by adding the file to the exclusions list. Caution: Only do this for files that you're confident are safe.

What is exclude file?

If you exclude a file from a Web Site project (not Web Application), Visual Studio will simply add the . exclude extension to that file. If you remove the extension, that file will be included again. It's up to you if you still need those files or not.


There are also a few things you can do in the csproj files to make sure the files aren't picked up:

1) Make sure none of the globbing patterns that look for "project items" pick up the files:

<PropertyGroup>
  <DefaultItemExcludes>$(DefaultItemExcludes);your_nonproj.file;a\**\*.pattern</DefaultItemExcludes>
</PropertyGroup>

2) Remove items explicitly:

<ItemGroup>
  <None Remove="hidden.file" />
  <Content Remove="wwwroot\lib\**\*" />
</ItemGroup>

Note that, on large directories (number of files), using DefaultItemExcludes with the folder\** pattern is a lot faster since msbuild will skip walking the directory entirely. Using a remove for this will still let msbuild spend quite some time discovering files.


Just to be complete, if you're using ItemGroup to exclude folder, then:

<ItemGroup>
  <Content Remove="excluded_folder\**" />
  <Compile Remove="excluded_folder\**" />
  <EmbeddedResource Remove="excluded_folder\**" />
  <None Remove="excluded_folder\**" />
</ItemGroup>

Because, I had an angular project with the node_modules folder which had very long paths and VS kept throwing exceptions. And using <Content Remove="node_modules\**\*" /> didn't work.


Open the project in Visual Studio, and right click the files and folders in Solution Explorer. Choose Exclude from Project.

That's exactly what you do for projects targeting .NET Framework.


In case you want to exclude files from the compilation process but still have them in the solution explorer tree, then

<ItemGroup>
    <Compile Remove="Templates\**" />
    <Content Include="Templates\**" />
</ItemGroup>

Templates are the folder name (in this case) and everything inside it will be ignored