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

前端 未结 3 2193
我寻月下人不归
我寻月下人不归 2020-12-13 17:41

In .NET Core and .NET Standard projects, if you put files and folders within the project directory, they are automatically picked up by Visual Studio; essentially they are p

相关标签:
3条回答
  • 2020-12-13 18:03

    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.

    0 讨论(0)
  • 2020-12-13 18:03

    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.

    0 讨论(0)
  • 2020-12-13 18:12

    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.

    0 讨论(0)
提交回复
热议问题