How to exclude from VS2017 web publish specific folders? RRS feed

  • Question

  • User1302062155 posted


    In my specific - weird - use case I have some static files on my backend project <g class="gr_ gr_130 gr-alert gr_spell gr_inline_cards gr_run_anim ContextualSpelling" id="130" data-gr-id="130">wwwroot</g>/images subfolder.

    Whenever I web publish I want to ignore my local <g class="gr_ gr_164 gr-alert gr_spell gr_inline_cards gr_run_anim ContextualSpelling" id="164" data-gr-id="164">wwwroot</g>/images folder and avoid deleting/overwriting the existing folder on the web server.

    Basically, I want the images to stay on the server and avoid storing them locally. What's the easiest way to accomplish this?

    Monday, April 15, 2019 9:29 AM

All replies

  • User753101303 posted


    So they are basically "data" ? In this case my personal preference is to store them outside of the site as part of a "data" folder and serving them through a controller.

    In short I always ensure I could delete and deploy a web site without any data loss (AFAIK any trick you could imagine won't prevent to lose those files if doing something wrong).

    Monday, April 15, 2019 11:03 AM
  • User1302062155 posted

    In this <g class="gr_ gr_104 gr-alert gr_gramm gr_inline_cards gr_run_anim Punctuation only-ins replaceWithoutSep" id="104" data-gr-id="104">case</g> my personal preference is to store them outside of the site as part of a "data" folder and serving them through a controller.

    What do you mean with this? You have a folder outside of IIS Sites controlled by an entirely different "solution", which in turn only serves static assets locally to running websites?

    Monday, April 15, 2019 11:49 AM
  • Monday, April 15, 2019 11:53 AM
  • User1302062155 posted

    Hello, thanks for the link.

    I see that it's a specific guide aimed at Windows Forms projects, also kinda dated, it's referring to VS2010. Can I still apply the same solution for different cases? I'm using .NET Core 2.2.

    From what <g class="gr_ gr_12 gr-alert gr_tiny gr_spell gr_inline_cards gr_run_anim ContextualSpelling multiReplace" id="12" data-gr-id="12">i</g> can find on google my bet is editing File Properties?


    I'm looking for the correct, best way to handle this.

    Monday, April 15, 2019 12:38 PM
  • User1302062155 posted

    I found an easy solution:

    <g class="gr_ gr_14 gr-alert gr_gramm gr_inline_cards gr_run_anim Punctuation only-ins replaceWithoutSep" id="14" data-gr-id="14">Right</g> click on the folder/file you want to exclude from the project and select "Exclude From Project". This will update your .csproj file with the correct XML statements in a correct syntax (which is not obvious lol).

    My updated .csproj file:

        <Compile Remove="wwwroot\images\progetti\**" />
        <Content Remove="wwwroot\images\progetti\**" />
        <EmbeddedResource Remove="wwwroot\images\progetti\**" />

    <g class="gr_ gr_15 gr-alert gr_gramm gr_inline_cards gr_run_anim Punctuation only-ins replaceWithoutSep" id="15" data-gr-id="15">Also</g> make sure the setting "Remove additional files at destination" is unchecked if you're using the <g class="gr_ gr_13 gr-alert gr_spell gr_inline_cards gr_run_anim ContextualSpelling" id="13" data-gr-id="13">msdeploy</g> method of publishing.

    This will update the SkipExtraFilesOnServer setting in the publish profile .pubxml file from "False" to ''True" as so:


    Not sure if excluding stuff from the project is the way to go, tho, any advice?

    Monday, April 15, 2019 1:23 PM
  • User753101303 posted

    You don't need another solution. A web site is able to read files stored outside the web site (to serve them through a controller for example).

    My concern is that though it works, it makes easy to forget later about that and have someone to wipe out the site including your data. I prefer to maintain a strict separation between the "program" and its "data".

    It can also help if you later consider to use load balancing etc...

    Or this is just an optimization to avoid publishing them again and again but it's ok to just keep those in your current project if you really need to publish that again? Is this part of your "program" or are those files to be considered as application "data" ???

    Monday, April 15, 2019 4:50 PM
  • User1302062155 posted

    @PatriceSc It's for a custom CMS where the users can upload photos that will be displayed in the frontend. Because uploaded photos are in the wwwroot/images/progetti/** subfolder I wanted to ignore that folder when publishing so files actually uploaded from users don't get overwritten by error when publishing the solution with <g class="gr_ gr_241 gr-alert gr_spell gr_inline_cards gr_run_anim ContextualSpelling" id="241" data-gr-id="241">msdeploy</g>.

    I like your approach tho. You literally created a folder somewhere in your Windows Server that stores data etc.? That would indeed solve lots of problems.

    Tuesday, April 16, 2019 8:00 AM
  • User19976469 posted

    For what it's worth and after several failed attempts at different combinations of things the only thing that worked for me was a combination of both:

    1. Exclude the folder from the project (i.e. right-click > Exclude from project)


    2. Adding the following to my .csproj exactly as it is but changing `wwwroot\\profiles` to be the directory you want to exclude. You also have to repeat the whole snippet for each folder you want to exclude:

    <MsDeploySkipRules Include="CustomSkipFolder">

    Note that this was an ASP.NET Core web project and I was using Web Deploy to a remote server. I was trying to exclude a whole folder under wwwroot from being included in the deployment. </div>

    Thursday, August 22, 2019 2:15 PM