如何使用 VS2010 Web 部署包包含其他文件? [英] How do you include additional files using VS2010 web deployment packages?

查看:22
本文介绍了如何使用 VS2010 Web 部署包包含其他文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在 Visual Studio 2010 中使用新的 Web 打包功能进行测试,遇到了这样一种情况:我使用预构建事件将所需的 .dll 复制到我的应用程序依赖于 API 调用的 bin 文件夹中.它们不能作为参考包含在内,因为它们不是可用于互操作的 COM dll.

I am testing out using the new web packaging functionality in visual studio 2010 and came across a situation where I use a pre-build event to copy required .dll's into my bin folder that my app relies on for API calls. They cannot be included as a reference since they are not COM dlls that can be used with interop.

当我构建部署包时,当我选择仅包含运行应用程序所需的文件的选项时,这些文件将被排除.有没有办法配置部署设置以包含这些文件?我没有找到任何关于此的好的文档.

When I build my deployment package those files are excluded when I choose the option to only include the files required to run the app. Is there a way to configure the deployment settings to include these files? I have had no luck finding any good documentation on this.

推荐答案

很好的问题.我刚刚在 Web 部署工具 (MSDeploy) : Build Package 上发布了一个非常详细的博客条目包括额外文件或排除特定文件.

Great question. I just posted a very detailed blog entry about this at Web Deployment Tool (MSDeploy) : Build Package including extra files or excluding specific files.

这是概要.包含文件后,我还会展示如何排除文件.

Here is the synopsis. After including files, I show how to exclude files as well.

包括额外文件

在包中包含额外的文件有点困难,但如果您对 MSBuild 感到满意,那么仍然没有什么大不了的,如果您不熟悉,请阅读本文.为了做到这一点,我们需要挂钩收集文件以进行打包的流程部分.我们需要扩展的目标称为 CopyAllFilesToSingleFolder.这个目标有一个依赖属性 PipelinePreDeployCopyAllFilesToOneFolderDependsOn,我们可以利用它并注入我们自己的目标.因此,我们将创建一个名为 CustomCollectFiles 的目标并将其注入到进程中.我们通过以下方式实现这一点(记住在 import 语句之后).

Including extra files into the package is a bit harder but still no bigee if you are comfortable with MSBuild, and if you are not then read this. In order to do this we need to hook into the part of the process that collects the files for packaging. The target we need to extend is called CopyAllFilesToSingleFolder. This target has a dependency property, PipelinePreDeployCopyAllFilesToOneFolderDependsOn, that we can tap into and inject our own target. So we will create a target named CustomCollectFiles and inject that into the process. We achieve this with the following (remember after the import statement).

<PropertyGroup>
  <CopyAllFilesToSingleFolderForPackageDependsOn>
    CustomCollectFiles;
    $(CopyAllFilesToSingleFolderForPackageDependsOn);
  </CopyAllFilesToSingleFolderForPackageDependsOn>

  <CopyAllFilesToSingleFolderForMsdeployDependsOn>
    CustomCollectFiles;
    $(CopyAllFilesToSingleFolderForMsdeployDependsOn);
  </CopyAllFilesToSingleFolderForMsdeployDependsOn>
</PropertyGroup>

这会将我们的目标添加到流程中,现在我们需要定义目标本身.假设您有一个名为 Extra Files 的文件夹,它位于您的 Web 项目上方 1 级.您希望包含所有这些文件.这是 CustomCollectFiles 目标,我们将在此之后讨论.

This will add our target to the process, now we need to define the target itself. Let’s assume that you have a folder named Extra Files that sits 1 level above your web project. You want to include all of those files. Here is the CustomCollectFiles target and we discuss after that.

<Target Name="CustomCollectFiles">
  <ItemGroup>
    <_CustomFiles Include="..Extra Files***" />

    <FilesForPackagingFromProject  Include="%(_CustomFiles.Identity)">
      <DestinationRelativePath>Extra Files\%(RecursiveDir)%(Filename)%(Extension)</DestinationRelativePath>
    </FilesForPackagingFromProject>
  </ItemGroup>
</Target>

在这里我所做的是创建项目 _CustomFiles 并在 Include 属性中告诉它选择该文件夹中的所有文件及其下的任何文件夹.如果您需要从该列表中排除某些内容,请将 Exclude 属性添加到 _CustomFiles.

Here what I did was create the item _CustomFiles and in the Include attribute told it to pick up all the files in that folder and any folder underneath it. If by any chance you need to exclude something from that list, add an Exclude attribute to _CustomFiles.

然后我使用这个项目来填充 FilesForPackagingFromProject 项目.这是 MSDeploy 实际用来添加额外文件的项目.另请注意,我声明了元数据 DestinationRelativePath 值.这将确定它将放置在包中的相对路径.我在这里使用了 Extra Files%(RecursiveDir)%(Filename)%(Extension) 语句.也就是说,将它放在包中与 Extra Files 文件夹下相同的相对位置.

Then I use this item to populate the FilesForPackagingFromProject item. This is the item that MSDeploy actually uses to add extra files. Also notice that I declared the metadata DestinationRelativePath value. This will determine the relative path that it will be placed in the package. I used the statement Extra Files%(RecursiveDir)%(Filename)%(Extension) here. What that is saying is to place it in the same relative location in the package as it is under the Extra Files folder.

排除文件

如果您打开使用 VS 2010 创建的 Web 应用程序的项目文件,您会在其底部找到一行.

If you open the project file of a web application created with VS 2010 towards the bottom of it you will find a line with.

<Import Project="$(MSBuildExtensionsPath32)MicrosoftVisualStudiov10.0WebApplicationsMicrosoft.WebApplication.targets" />

顺便说一句,您可以在 VS 中打开项目文件.右键单击项目选择卸载项目.然后右键单击卸载的项目并选择编辑项目".

BTW you can open the project file inside of VS. Right click on the project pick Unload Project. Then right click on the unloaded project and select Edit Project.

该声明将包括我们需要的所有目标和任务.我们的大部分定制都应该在导入之后,如果您不确定是否在之后!因此,如果您有要排除的文件,则可以使用一个项目名称 ExcludeFromPackageFiles.例如,假设您的 Web 应用程序中包含名为 Sample.Debug.xml 的文件,但您希望从创建的包中排除该文件.您可以将下面的代码片段放在该导入语句之后.

This statement will include all the targets and tasks that we need. Most of our customizations should be after that import, if you are not sure put if after! So if you have files to exclude there is an item name, ExcludeFromPackageFiles, that can be used to do so. For example let’s say that you have file named Sample.Debug.xml which included in your web application but you want that file to be excluded from the created packages. You can place the snippet below after that import statement.

<ItemGroup>
  <ExcludeFromPackageFiles Include="Sample.Debug.xml">
    <FromTarget>Project</FromTarget>
  </ExcludeFromPackageFiles>
</ItemGroup>

通过声明填充此项,文件将被自动排除.请注意此处 FromTarget 元数据的用法.我不会在这里讨论这个,但你应该知道总是指定.

By declaring populating this item, the files will automatically be excluded. Note the usage of the FromTarget metadata here. I will not get into that here, but you should know to always specify that.

这篇关于如何使用 VS2010 Web 部署包包含其他文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆