Exclude files from web site deployment with msbuild

走远了吗. 提交于 2019-12-03 16:09:06

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.

bherto39

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

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

DotNetInfo

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

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

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.)

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!