Exclude files from web site deployment with msbuild
Asked Answered
P

5

8

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.

Pasture answered 15/6, 2011 at 13:42 Comment(0)
P
8

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
Petroleum answered 18/10, 2012 at 10:47 Comment(0)
N
7

You can select the files and set their "Build Action" to "ExcludeFromPackageFiles". That way visual studio will edit the csproj xml and you don't have to.

Northwards answered 29/10, 2012 at 15:31 Comment(2)
My Visual Studio 2012 has lots of options but NOT "ExcludeFromPackageFiles."Luzluzader
Like Pete said, not an option. Also if you are compiling the files, eg BuildAction is TypeScriptCompile, i can't really change it.Marthena
F
3

in the properties explorer for the files change the option "copy to output directory to "do not copy"

enter image description here

Fluviatile answered 15/6, 2011 at 13:44 Comment(1)
This is a web site project, not a web application. I would need a way to do that from the msbuild file.Pasture
K
3

You can use MSDeploy with Web Publishing Pipeline to exclude files to be included in the package creation. You can use something like this if you want to exclude for example App_Data folder from the deployed package

<Target Name="ExcludeApp_Data" DependsOnTarget="$(ExcludeApp_DataDependsOn)" Condition="$(ExcludeApp_Data)" > 
  <ItemGroup>
    <ExcludeFromPackageFolders Include="App_Data">
      <FromTarget>ExcludeApp_Data</FromTarget>
    </ExcludeFromPackageFolders>
  </ItemGroup>
</Target>

Somehow editor doesn't display the code properly. The above gets generated inside the proj file when you configure the Package/Publish web. You can add your own target to get it done.

For example, if you want to exclude Scripts\jquery files from your build, create seperate ExcludeScriptFiles.wpp.targets file as below

<ItemGroup> 
  <ExcludeFromPackageFolders Include="Internal">
    <FromTarget>ExcludeScriptFiles.wpp.targets</FromTarget>         
  </ExcludeFromPackageFolders>
  <ExcludeFromPackageFiles Include="Scripts\jquery.js;xyz.js">
    <FromTarget>ExcludeScriptFiles.wpp.targets </FromTarget> 
  </ExcludeFromPackageFiles>
</ItemGroup>

This is just a simple example to write your own target.

Hope this helps

Karlenekarlens answered 16/6, 2011 at 2:41 Comment(2)
thanks for the tip, I'll try it asap. To answer your (now edited away) question, you can format XML properly in SO, you just have to distribute it across multiple lines.Pasture
@Paolo Thanks for the formatting tip. When I tried to distribute across multiple lines, the formatting was not coming through after I press enter. Am I missing anything?. I am also currently going through a task for generating config files for different environments (test/stage/production) at one go and creating a deployment package.Karlenekarlens
L
0

I'm using Visual Studio 2012 with Jenkins and the only thing that worked for me was changing "Build Action" to "None:"

enter image description here

Internally this sets the XML tag in the PROJECT.csproj file from "Content" to "None:"

<None Include="form.coffee" />

I closed the project then manually edited the file using another editor to exclude all my coffee files en mass.

(All my coffee files are still transcompiled to js files.)

Luzluzader answered 28/3, 2018 at 14:18 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.