Wednesday, October 21, 2009

How to ensure placeholder folders are created during VS 2010 Web Deployment

During many web deployment scenarios developers want to be able create place holder folders where eventually their log files or runtime generated files like XMLs, Images etc will be stored…

With VS 2010 Web Deployment there will be a small work around required for you to be able to deploy place holder folders…  Before I go about explaining the work around let me call out that if you do not know about VS 2010 Web Deployment features it might be worth while to check out the blog series about VS 2010 Web Deployment at Overview Post for VS 2010 Web Deployment

Anyways, as VS 2010 Web Deployment is completely based on MSBuild based Web Publishing Pipeline (WPP) lot of deployment depends upon the MSBuild constructs…  One of the key features which is also supported using MSBuild based constructs is the ability to exclude Files and Folders from deployment.  I am hoping to write blog posts on both of these topics at some point but currently without going into the details consider following:

There is a file/folder structure like C:\MyWeb\Foo\Bar\myfile.htm…  VS 2010 will allow you to exclude or include myfile.htm or folder “Foo” from Web Deployment… If you now chooses to include myfile.htm but chooses to exclude “Foo” folder then the WPP will get into unwanted complex state for potentially trivial gains…

That is the reason most of the include, exclude, delete etc operations are done at the File level rather than at Folder level… So when you are excluding a folder from deployment  behind the scenes a bunch of files under that folder are getting excluded and the end result is the folder being excluded too… The above explanation is not exactly how it translates into code but is more for understanding purposes…

Anyways, this design decision causes the side effect that if there are no files in a folder then the folder does not get deployed as well… By now I imagine you must have figured out the work around too :-) Ya! just put a place holder file even if it is empty.txt in your place holder folder and it will get deployed too !!

If this causes you a lot of grief then do write back with your scenarios so that we can try to understand and analyze them individually…

Also do note that whether you are creating a web package or doing 1-Click Publish the same rationale applies as ultimately same WPP is executed behind the scenes for both…

-Vishal

2 comments:

KeepingItSimple said...

Hi Vishal,

I have a query unrelated to this post and VS2010 deployment.

On my box I did installed VS2010b2 and later uninstalled and reverted to VS2010b1

I have been getting this error while Deploying.

Any ideas !?

Thank you in advance.


Error 2 The "VSMSDeploy" task failed unexpectedly.
System.TypeLoadException: Could not load type 'Microsoft.Web.Deployment.DeploymentException' from assembly 'Microsoft.Web.Deployment, Version=7.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'.
at Microsoft.Web.Publishing.Tasks.VSMSDeploy.Execute()
at Microsoft.Build.BackEnd.TaskExecutionHost.Microsoft.Build.BackEnd.ITaskExecutionHost.Execute()
at Microsoft.Build.BackEnd.TaskBuilder.ExecuteInstantiatedTask(ITaskExecutionHost taskExecutionHost, TaskLoggingContext taskLoggingContext, TaskHost taskHost, ItemBucket bucket, TaskExecutionMode howToExecuteTask, Boolean& taskResult)

Anonymous said...

How about a simple option on the folders called "Deploy If Empty" True/False. Or "Empty Folder Behavior: Deploy/Do not Deploy/Remove"