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

查看:146
本文介绍了如何使用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):发布包中发布了有关此问题的非常详细的博客条目.包括多余文件或排除特定文件.

这里是提要.包含文件后,我还将展示如何排除文件.

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

包括额外的文件

将额外的文件包含到程序包中会比较困难,但是如果您对MSBuild感到满意的话,那仍然不算什么,如果您不熟悉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属性中告诉它拾取该文件夹及其下的所有文件夹中的所有文件.如果您需要从该列表中排除某些内容,请在_CustomFiles中添加一个Exclude属性.

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)\Microsoft\VisualStudio\v10.0\WebApplications\Microsoft.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,可以使用该名称.例如,假设您有一个名为Sample.Debug.xml的文件,该文件包含在您的Web应用程序中,但您希望将该文件从创建的包中排除.您可以将该代码段放在该import语句之后.

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天全站免登陆