title: How to ignore folders during file system publish in Visual Studio (.NET 4.X app)
body: <p>I am attempting to publish a nopCommerce 3.80 build using Visual Studio. I need to use the 'Publish -> File System' method. The problem I am having is that when I attempt to publish to the file system, an error is thrown:</p>
  
  <blockquote>
    <p>The "CollectFilesinFolder" task failed unexpectedly.
    System.IO.PathTooLongException: The specified path, file name, or both are too long. The fully qualified file name must be less than 260 characters, and the directory name must be less than 248 characters.</p>
  </blockquote>
  
  <p>I determined that the problem is that I have a <strong>node_modules</strong> directory in my theme's directory that contains paths well over the 248 character limit.</p>
  
  <p>If I delete the <strong>node_modules</strong> directory first, then I can publish just fine; however, this does not work for me because I run <code>gulp</code> in the <strong>Pre-build Event</strong> and I do not have the time to install the packages each time I go to build the project.</p>
  
  <p>I found some suggestions online that suggest:</p>
  
  <ul>
  <li>Make the <strong>node_modules</strong> directory hidden</li>
  <li>Use <strong>.wpp.targets</strong> file to exclude the directory (<a href="https://www.asp.net/web-forms/overview/deployment/advanced-enterprise-web-deployment/excluding-files-and-folders-from-deployment" rel="nofollow">link</a>)</li>
  <li>Add <code>&lt;ExcludeFoldersFromDeployment&gt;node_modules&lt;/ExcludeFoldersFromDeployment&gt;</code> to the <strong>.csproj</strong> file (<a href="https://blogs.msdn.microsoft.com/webdev/2010/04/22/web-deployment-excluding-files-and-folders-via-the-web-applications-project-file/" rel="nofollow">link</a>)</li>
  </ul>
  
  <p>I have tried all of the above (and then some), and none of these solutions have worked for me. Maybe because I am using the 'Publish -> File System' method (and not 'Web Deploy')? Maybe Visual Studio 2015 requires a different solution?</p>
  
  <p>Can anyone explain (in detail) how I can exclude the <strong>node_modules</strong> directory from 'Publish -> File System' without sabotaging my ability to use Gulp in the <strong>Pre-build Event</strong>?</p>
  
  <p><strong>Note:</strong> This project is not a .NET 4.6 web application (which has NPM and Gulp pre-configured). So there is no <strong>*.json</strong> config file for me to exclude the node directory in...</p>
  
  <p><strong>UPDATE</strong></p>
  
  <p>I think the <strong>.wpp.targets</strong> file would be a great solution. I have tried the following:</p>
  
  <p><strong><em>Nop.Web.wpp.targets</em></strong></p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8" ?&gt;
  &lt;Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"&gt;
      &lt;ItemGroup&gt;
          &lt;ExcludeFromPackageFolders Include="node_modules;bower_components"&gt;
              &lt;FromTarget&gt;Nop.Web.wpp.targets&lt;/FromTarget&gt;
          &lt;/ExcludeFromPackageFolders&gt;
      &lt;/ItemGroup&gt;
  &lt;/Project&gt;
  </code></pre>
  
  <p>But I get the original error plus the following error:</p>
  
  <blockquote>
    <p>The element 'ItemGroup' in namespace '<a href="http://schemas.microsoft.com/developer/msbuild/2003" rel="nofollow">http://schemas.microsoft.com/developer/msbuild/2003</a>' has invalid child element 'ExcludeFromPackageFolders' in namespace '<a href="http://schemas.microsoft.com/developer/msbuild/2003" rel="nofollow">http://schemas.microsoft.com/developer/msbuild/2003</a>'. List of possible elements expected: 'Item, Reference, SDKReference, COMReference, COMFileReference, Xdcmake, Bscmake, ClCompile, ClInclude, Midl, ResourceCompile, PreLinkEvent, CustomBuildStep, Manifest, ProjectConfiguration, ProjectCapability, NativeReference, ProjectReference, Compile, EmbeddedResource, Content, Page, Resource, ApplicationDefinition, None, BaseApplicationManifest, Folder, Import, Service, WebReferences, WebReferenceUrl, FileAssociation, BootstrapperFile, PublishFile, TargetPlatform, Analyzer, CodeAnalysisDependentAssemblyPaths, CodeAnalysisDictionary, CodeAnalysisImport, AppxManifestSchema, StoreManifestSchema, AppxHashUri, PRIResource, AppxSystemBinary, AppxReservedFileName, AppxManifestFileNameQuery, AppxManifestImageFileNameQuery, AppxManifest, StoreAssociationFile, AppxManifestMetadata, PlatformVersionDescription, _AppxBundleContent, _AppxBundleMainPackageMapGeneratedFiles, _AppxBundleMainPackageMapInputs, _AppxBundleResourceFileMaps, _AppxBundleResourcePack, _AppxBundleSplitResourcesGeneratedFiles, _AppxBundleSplitRes....    Nop.Web C:\nopCommerce\src\Presentation\Nop.Web\Nop.Web.wpp.targets 5   </p>
  </blockquote>