开发者

publish empty directories to a web application in VS2010 web project

开发者 https://www.devze.com 2023-01-26 07:06 出处:网络
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.

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开发者_如何学Go 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!


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.


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


There was a bug report to Microsoft about this and they said that they would not fix it. http://connect.microsoft.com/VisualStudio/feedback/details/546356/publish-deploy-does-not-deploy-empty-folders

Too bad. Because it used to work in Visual Studio 2008.

Note that it is not necessary to actually deploy the dummy file. It only needs to exist as part of the project in the build environment.


This one worked for me:

Edit your publish pubxml file that visual studio generates, like Leniel Macaferi mentioned, then add this: Visual studio already generated a property like

<publishUrl>f:\publish_web</publishUrl>

in the

<PropertyGroup>    

section, so I've used it like this: Added to section:

 <PipelineDependsOn>
      CustomBeforePublish;
      $(PipelineDependsOn);
    </PipelineDependsOn>  

And also added:

<Target Name="CustomBeforePublish">
    <Message Text="CustomBeforePublish task:"/>
    <MakeDir Directories="$(publishUrl)\MyFolder\MyFolder2"/>
  </Target>


Inside the Empty Folder Add a Default.aspx file. You can leave it empty, It will then create the folder in the PreCompiled version.

0

精彩评论

暂无评论...
验证码 换一张
取 消