将空目录发布到 VS2010 Web 项目中的 Web 应用程序
我经常需要发布一个保留目录树的 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
不,这是不可能的,恐怕我们也遇到了同样的问题。如果您希望预编译工具生成这些空文件夹,则需要在每个空目录中创建一个 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.
我知道这个问题提到了 Visual Studio 2010,但我来这里寻找同样的问题...
我正在使用 Visual Studio 2012 并找到了一种很好/优雅的方法来克服这种令人烦恼的情况。我认为它也适用于 VS 2010,并且比在空文件夹中添加虚拟空文件更好。
当您使用
VS 2012
创建发布配置文件时,它将在Properties\PublishProfiles
文件夹(我的项目)中生成一个
)。这些是MyPublishProfile.pubxml
文件VB 的 \PublishProfilesMSBuild
文件,人们可以编辑它们以自定义发布过程。在我们的例子中,我们可以在发布实际发生之前将目标注入到发布过程中,如下所示:属性
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 inVS 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 aMyPublishProfile.pubxml
file in theProperties\PublishProfiles
folder (My Project\PublishProfiles
for VB). These areMSBuild
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: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
微软向微软提交了一份关于此问题的错误报告,他们表示不会修复它。
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.
这对我有用:
编辑 Visual Studio 生成的发布 pubxml 文件,就像 Leniel Macaferi 提到的那样,然后添加以下内容:
Visual Studio 已经生成了一个像
本节中
那样的属性,所以我像这样使用它:
添加到部分:
并且还添加了:
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
in the
section, so I've used it like this:
Added to section:
And also added:
在空文件夹中添加 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.