user1447679
user1447679

Reputation: 3260

I can't get MSBuild to ignore an entire folder

I just started using MSBuild and for whatever reason this seems more complicated than it should be. I'm trying to get the build process to completely ignore "node_modules" folder. I've tried all sorts of ways. Here's my latest:

<ItemGroup>
  <DefaultExclude Include="node_modules\*.*" />
  <!-- tried **\node_modules\** -->
  <!-- tried **node_modules** -->
  <!-- tried node_modules\** -->
  <!-- tried several others combinations -->
</ItemGroup>

<ItemGroup>     
  <InstallInclude Include="**\*.ascx" Exclude="packages\**;@(DefaultExclude)" />
  <InstallInclude Include="**\*.asmx" Exclude="packages\**;@(DefaultExclude)" />
  <InstallInclude Include="**\*.css" Exclude="packages\**;@(DefaultExclude)" />
  <InstallInclude Include="**\*.html" Exclude="packages\**;@(DefaultExclude)" />      
</ItemGroup>

<Copy SourceFiles="@(InstallInclude)" DestinationFolder="$(MSBuildProjectDirectory)\ResourcesZip\%(RecursiveDir)" />
<!-- this resources directory ends up with all the node_modules in it -->

Needless to say, the build process takes forever, and sometimes breaks (inconsistently).

MSBuild is an initial confusing nightmare.

Upvotes: 3

Views: 2225

Answers (2)

JotaBe
JotaBe

Reputation: 39045

You can always set the hidden attribute in the offending folder, for example node_modules and ASPNET_compiler will skip it. I've tested it with grunt and typescript, and it works fine with the hidden folder.

Upvotes: 1

Martin Ullrich
Martin Ullrich

Reputation: 100701

The problem here is that you're expanding items based on your node_modules folder. MSbuild will collect metadata for all items which is what makes it slow. To make sure this process is efficient, use a property instead - similar to what the .net core web sdk does:

<PropertyGroup>
  <DefaultItemExcludes>packages\**</DefaultItemExcludes>    
  <DefaultItemExcludes>$(DefaultItemExcludes);**\node_modules\**;node_modules\**</DefaultItemExcludes>
  <DefaultItemExcludes>$(DefaultItemExcludes);**\jspm_packages\**;jspm_packages\**</DefaultItemExcludes>
  <DefaultItemExcludes>$(DefaultItemExcludes);**\bower_components\**;bower_components\**</DefaultItemExcludes>
</PropertyGroup>

<ItemGroup>     
  <InstallInclude Include="**\*.ascx" Exclude="$(DefaultItemExcludes)" />
  <InstallInclude Include="**\*.asmx" Exclude="$(DefaultItemExcludes)" />
  <InstallInclude Include="**\*.css" Exclude="$(DefaultItemExcludes)" />
  <InstallInclude Include="**\*.html" Exclude="$(DefaultItemExcludes)" />      
</ItemGroup>

An exclude pattern ending in \** will prevent msbuild even enumerating the folder. MSBuild 15 (part of VS 2017) may be required to get the full performance benefit.

Upvotes: 2

Related Questions