将空目录发布到 VS2010 Web 项目中的 Web 应用程序

发布于 2024-10-04 17:12:47 字数 149 浏览 0 评论 0原文

我经常需要发布一个保留目录树的 Web 项目,即使目录是空的,例如保存上传文件的目录。 如果我使用 VS2010 发布命令发布我的应用程序,则不会在 Web 服务器上的远程文件系统上创建空目录。

有没有办法强制 VS 在目标目录上创建某些文件夹(尽管是空的)? 谢谢!

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!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

不美如何 2024-10-11 17:12:47

不,这是不可能的,恐怕我们也遇到了同样的问题。如果您希望预编译工具生成这些空文件夹,则需要在每个空目录中创建一个 placeholder.txt 文件。如果失败,您可以创建一个命令行应用程序,它将在构建后事件中创建文件夹(但前提是您使用的是 Web 应用程序项目而不是网站项目)。

希望这有帮助。

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.

﹏半生如梦愿梦如真 2024-10-11 17:12:47

我知道这个问题提到了 Visual Studio 2010,但我来这里寻找同样的问题...

我正在使用 Visual Studio 2012 并找到了一种很好/优雅的方法来克服这种令人烦恼的情况。我认为它也适用于 VS 2010,并且比在空文件夹中添加虚拟空文件更好。

当您使用VS 2012创建发布配置文件时,它将在Properties\PublishProfiles文件夹(我的项目)中生成一个MyPublishProfile.pubxml文件VB 的 \PublishProfiles)。这些是 MSBuild 文件,人们可以编辑它们以自定义发布过程。在我们的例子中,我们可以在发布实际发生之前将目标注入到发布过程中,如下所示:

<?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>

属性 AfterAddIisSettingAndFileContentsToSourceManifest 保存在准备好部署包内容后将调用的目标名称。这是向包中添加其他文件或文件夹的最佳时机。


代码和文本混合来自:

如何仅在 VS 2012 中的 Web 部署发布任务之前执行 PowerShell 脚本?

Web 部署:自定义部署包

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

梦魇绽荼蘼 2024-10-11 17:12:47

微软向微软提交了一份关于此问题的错误报告,他们表示不会修复它。
http://connect.microsoft .com/VisualStudio/feedback/details/546356/publish-deploy-does-not-deploy-empty-folders

太糟糕了。因为它曾经在 Visual Studio 2008 中工作。

请注意,没有必要实际部署虚拟文件。它只需要作为构建环境中项目的一部分存在。

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.

对你的占有欲 2024-10-11 17:12:47

这对我有用:

编辑 Visual Studio 生成的发布 pubxml 文件,就像 Leniel Macaferi 提到的那样,然后添加以下内容:
Visual Studio 已经生成了一个像

<publishUrl>f:\publish_web</publishUrl>

本节中

<PropertyGroup>    

那样的属性,所以我像这样使用它:
添加到部分:

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

并且还添加了:

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

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>
小鸟爱天空丶 2024-10-11 17:12:47

在空文件夹中添加 Default.aspx 文件。您可以将其留空,然后它将在预编译版本中创建该文件夹。

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文