Friday, July 31, 2009

Exclude App_Data Folder from Deployment

SQL Server Express is a development time database and it is not recommended to use it on your production server.  The rationale for providing SQL Express edition was to ensure that development can be done without having to install a licensed copy of SQL Server on your development machine…

Additionally most of the hosters do not support SQL Server Express on their shared web servers and enterprises are typically running on full SQL Server in their Staging/Production environment.

When you are developing a Web Project using Visual Studio then your SQL Express MDF file is put inside App_Data folder.  VS also ensures that App_Data folder is set up with the correct read/write access so that your application can then write to the Database files in it… 

When it comes time to deploy your application you should ensure that your MDF files do not get deployed with the rest of your application.  To help with this VS provides option to exclude the content of App_Data folder.

Web Application Projects (VS 2005/ VS 2008)

If you are using Web Application Projects in VS 2005/VS 2008 then when your right click on your project and hit “Publish” then the option to Exclude the content of App_Data is available as a checkbox as shown below:

Publish WAP

Web Application Projects (VS 2010)

In VS 2010 web deployment is hugely improved… As part of the clean up this option is now moved to project properties as shown below:


When project properties window opens then navigate to Package/Publish tab… In this tab there is a checkbox which allows you to exclude “App_Data” content while publishing…Check the box as shown below:


With this setting Visual Studio 2010 will make sure that your Web Deployment does not includes content of App_Data folder… If you would like to learn more, check out the rest of the properties of Package/Publish tab

After setting this property it will get respected automatically while creating a web package or while using 1-Click Publish

Are there scenarios to not exclude App_Data folder all the time?

Sometimes I have been asked why to give a specific option to Exclude App_Data folder and not exclude it all the time by default.

Well people also put bunch of other files in App_Data folder for e.g. XML files which your web updates or other flat file DBs that your web might potentially use…  In this scenario excluding App_Data would exclude those files too and you would ideally want to avoid that, hence there is an explicit option to leave out the content of App_Data folder…

Hope this helps!!



James said...

Hello Vishal:

Can you help me solve this problem?
When I tried to post the error message here, I received the following message: "Your HTML cannot be accepted: PHP, ASP, and other server-side scripting is not allowed."
Because of that, please see the error message at URL


Vishal R Joshi said...

James, I am seeing a different error on the above URL, I did not notice "Your HTML cannot be accepted" message... Nevertheless can you verify whether this blog post covers your issue?
Also can you confirm whether you have checked "Allow untrusted certificates" checked for your deployment...
Finally JFYI "Exclude App_Data folder" as described in the above blog post has possibly some issues which we are trying to debug, can you try the scenario by unchecking "Exclude App_Data folder" in Package/Publish tab of your project properties...
Let me know how it goes...

James said...

Hello Vishal:

Currently I cannot modify my database in the DiscountASP server due to some problem at your end, correct?
I checked and unchecked the "Exclude App_Data folder" check box.
Please see the result of my test at URL

Anyway, I want to post a message at URL but I forgot my password.
Trying to recover my password from URL
I have asked the system to send my password to my e-mail address, but I have not received the e-mail yet.
Can you help me on this issue?


Vishal R Joshi said...

Hi Jamesh, you should be able to modify your database in DiscountASP, there is no problem with that as far as I know...

The Exclude_AppData check box is simply to exclude the files from your App_Data folder, there should not be any issue if keep it unchecked..

Can you describe the steps that you have followed and the issues that you are facing so that we can try to troubleshoot what is wrong...

Vishal R Joshi said...

Also for your password issue can you send me an email at and I will try to follow up on the same...

James said...

Hello Vishal:

I just sent you an e-mail.


Anonymous said...

one.beat.customer said...

I have a related question. In my situation we use File System deployment for Publish, and need to use the "Delete Files First" option when deploying to production.

I wanted to know if there is a way to exclude App_Data from the deletion process, because our web application requires certain permissions set on App_Data that have to be reapplied if it is deleted and then recreated.

Interestingly enough, when you select the "Exclude App_Data" check box, the folder is still deleted - it doesn't exclude it entirely (leave it completely alone) from the publishing process.

Any thoughts? Please help.

Vishal R Joshi said...

Hi One.beat.customer,
I do not think there is a straight forward way of achieving this although if you can send me an email at then I can try to see if we can get some solution.
Also I am assuming that you are not using Web Deploy for your publishing and using File System Publish can you please confirm that it is the case.