publish empty directories to a web application in VS2010 web project

前端 未结 5 1964
长发绾君心
长发绾君心 2020-12-15 16:08

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 usi

相关标签:
5条回答
  • 2020-12-15 16:36

    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.

    0 讨论(0)
  • 2020-12-15 16:38

    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 讨论(0)
  • 2020-12-15 16:49

    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>
    
    0 讨论(0)
  • 2020-12-15 16:50

    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

    0 讨论(0)
  • 2020-12-15 16:51

    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.

    0 讨论(0)
提交回复
热议问题