Shoe
Shoe

Reputation: 76240

Exclude folder in ASP.NET Core 2

How can I exclude my X folder from the build?

If I remove it manually and dotnet build and dotnet run it takes along the lines of 20 seconds to run both commands and get me a working server.

On the other hand if I include it manually it takes something like 2 minutes to run both commands.

I've tried adding:

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

to my .csproj file, but that doesn't seem to solve the issue.

So how can I instruct dotnet to ignore that folder completely?

Upvotes: 6

Views: 3283

Answers (1)

Martin Ullrich
Martin Ullrich

Reputation: 100581

To exclude large folders to speed up the build, the items need to be excluded from the "default" items (the pattern searched by default) since the most time is spent searching the folder (though MSBuild 15.5 will contain optimisations for that).

Add this to the project file to exclude large folders that should never be searched in the first place:

<PropertyGroup>
  <DefaultItemExcludes>$(DefaultItemExcludes);my_large_folder\**</DefaultItemExcludes>
</PropertyGroup>

Upvotes: 15

Related Questions