Excluding files and folders from your published .Net Core web project

You can exclude files or folders from your published .Net Core project by editing your project file. In Visual Studio, click on the project to open the projectName.csproj file. To exclude the file wwwroot\json\example.json, add the following.

   
  <ItemGroup>    
      <Content Update="wwwroot\json\example.json" CopyToPublishDirectory="Never" />
</ItemGroup> 
       

To exclude all json files in that folder, add:

 <ItemGroup>    
      <Content Update="wwwroot\json\*.json" CopyToPublishDirectory="Never" />
</ItemGroup> 

For each folder you wish to exclude, you must show how deep you want to go in the file structure. It will not recursively search for more folders.

 <ItemGroup>    
      <Content Update="wwwroot\Area1\*\*.*" CopyToPublishDirectory="Never" />

This method has been tested with Visual Studio Community 2019, version 16.8.3.

Leave a Reply

Your email address will not be published. Required fields are marked *