Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

publish empty directories to a web application in VS2010 web project

Often I need to publish a web project preserving a directory tree even if the directories are empty, for example, directories to hold uploaded files. If I publish my app using the VS2010 publish command, the empty directories are not created on the remote filesystem, on the web server.

Is there a way to force VS to create certain folders, albeit empty, on the target directory? thanks!

like image 233
pomarc Avatar asked Nov 23 '10 15:11

pomarc


2 Answers

No this is not possible I'm afraid we had the same problem. You need to create a placeholder.txt file in each empty directory if you want the precompilation tool to generate these empty folders. Failing that you can create a command line app that will create the folders in your post build events (but only if you are using web application project not web site project).

Hope this helps.

like image 196
Exitos Avatar answered Sep 20 '22 16:09

Exitos


I know this question mentions Visual Studio 2010 but I got here looking for the same problem...

I'm using Visual Studio 2012 and found a nice/elegant way to overcome this annoying situation. I think it'll also work in VS 2010 and is better than adding dummy empty files inside the empty folders.

When you create a publish profile with VS 2012 it will generate a MyPublishProfile.pubxml file in the Properties\PublishProfiles folder (My Project\PublishProfiles for VB). These are MSBuild files and one can edit them to customize the publish process. In our case we can inject a target into the publish process, before the publish actually occurs like this:

<?xml version="1.0" encoding="utf-8"?> <Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">   <PropertyGroup>     <AfterAddIisSettingAndFileContentsToSourceManifest>CreateEmptyFolders     </AfterAddIisSettingAndFileContentsToSourceManifest>   </PropertyGroup>   <Target Name="CreateEmptyFolders">     <Message Text="Adding empty folder to hold Files" />     <MakeDir Directories="$(_MSDeployDirPath_FullPath)\Files\MyEmptyFolder"/>   </Target> </Project> 

The property AfterAddIisSettingAndFileContentsToSourceManifest holds the names of targets that will be invoked after the contents for the deployment package has been prepared. This is the perfect time to add additional files or folders to the package.


Code and text mixed from:

How to execute a PowerShell script only before a web deploy Publish task in VS 2012?

Web Deploy : Customizing a deployment package

like image 31
Leniel Maccaferri Avatar answered Sep 23 '22 16:09

Leniel Maccaferri