CZEMacLeod / MSBuild.SDK.SystemWeb

This MSBuild SDK is designed to allow for the easy creation and use of SDK (shortform) projects targeting ASP.NET 4.x using System.Web.
MIT License
151 stars 8 forks source link

node_modules is not ignored #19

Closed mcnallys closed 2 years ago

mcnallys commented 2 years ago

If you have a large project that is doing any kind of globbed includes and you have a large number of node_modules then the sdk project system will consume an inordinate amount of resources- often crashing with an out of memory error. It will also be extremely slow to do any project operations- adding a new file, etc.

Adding this solved the problem for me:

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

I think this should be included to avoid this pitfall.

CZEMacLeod commented 2 years ago

Good idea - I will have a look at this. We will probably put it behind a flag, but I don't see any harm in defaulting it to true. As an alternative, I think DefaultItemExcludes is actually designed for this scenario. Could you try the following instead and see if it is any better or worse? I think it should be better and it won't add the items in the first place then remove them again.

<PropertyGroup>
  <DefaultItemExcludes>$(DefaultItemExcludes);node_modules\**</DefaultItemExcludes>
</PropertyGroup>
mcnallys commented 2 years ago

You are correct about DefaultItemExcludes, I ended up needing a combination of both.

I also had to do this for every glob include I did,

<Content Include="**\*.js" Exclude="$(DefaultItemExcludes)" />
CZEMacLeod commented 2 years ago

@mcnallys I think most people would be including Content\**\*.css or Scripts\**\*.js etc. rather than the open glob, but adding the Exclude="$(DefaultItemExcludes)" obviously works too. In my case, *\.js would grab gulpfile.js. Do you think it is worthwhile adding

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

to the SDK? Or is it something that would be done by the consumer? I feel there might be other folders that would be excluded based on which package manager you were using,

CZEMacLeod commented 2 years ago

Looking at the ASP.NET Core SDK I found the following lines:

    <DefaultItemExcludes>$(DefaultItemExcludes);**\node_modules\**;node_modules\**</DefaultItemExcludes>
    <DefaultItemExcludes>$(DefaultItemExcludes);**\jspm_packages\**;jspm_packages\**</DefaultItemExcludes>
    <DefaultItemExcludes>$(DefaultItemExcludes);**\bower_components\**;bower_components\**</DefaultItemExcludes>
mcnallys commented 2 years ago

Yeah I would add those lines to the sdk, it took me quite a while to figure out what was going on.

CZEMacLeod commented 2 years ago

@mcnallys If you update to Version 4.0.50 these lines will be included by default and you can remove them from your project file.