C# – Exclude files from web site deployment with msbuild

cmsbuildwebweb-site-project

I have a web site project that I deploy using msbuild. In the project there are some files and folders that are needed for the build (e.g. the web.config part replacement files) but that I don't want to deploy to the target site.

The best I could think of is a post-build target that removes these files, but I'd like to know if there is a way to have these files not copied to the output folder.

Best Answer

Hi Check this blog post out it saved my day,

I was trying to exclude the un-minified version of the javascripts, and use only the minified version when published (I'm removing large javascripts and chirp.config) its only needed for debug.

just put this on the Project file as stated on the link.

<ItemGroup>
    <ExcludeFromPackageFolders Include="Scripts\large">
      <FromTarget>Project</FromTarget>
    </ExcludeFromPackageFolders> 


    <ExcludeFromPackageFiles Include="Scripts\mash.js.chirp.config" />  
    <ExcludeFromPackageFiles Include="Content\mash.js.chirp.config" />
  </ItemGroup>

The published site will not include the following:

  • Scripts\large
  • mash.js.chirp.config