如何获得Visual Studio的“发布”功能,包括后生成事件文件? [英] How to get Visual Studio 'Publish' functionality to include files from post build event?

查看:499
本文介绍了如何获得Visual Studio的“发布”功能,包括后生成事件文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在尝试使用Visual Studio 2010发布和MSDeploy的功能来处理我的网络部署需求,但与问候碰到路障,以定制取决于我的构建配置包。

I am currently attempting to use Visual Studio 2010 'Publish' and MSDeploy functionality to handle my web deployment needs but have run into a roadblock with regards to customizing the package depending on my build configuration.

我开发一个32位环境,但需要为64位环境中创建一个发布包,因此在释放的配置我有一个后生成事件那份第三方的64位版本的DLL注入的bin目录覆盖32位版本。当我使用发布功能,即使正确的64位DLL被​​复制到bin目录中,它不会包括在包中。

I develop in a 32bit environment but need to create a release package for a 64bit environment, so in the 'Release' configuration I have a post build event that copies the 64bit version of a third-party dll into the bin directory overwriting the 32bit version. When I use the 'Publish' functionality, even though the correct 64bit dll is being copied to the bin directory, it doesn't get included in the package.

有没有办法让发布包括一个后生成事件期间已经复制到bin目录中的文件?

Is there a way to get the 'Publish' to include files that have been copied into the bin directory during a post build event?

推荐答案

我在回答类似但不同的问题<一href=\"http://stackoverflow.com/questions/2747081/how-do-you-include-additional-files-using-vs2010-web-deployment-packages\">http://stackoverflow.com/questions/2747081/how-do-you-include-additional-files-using-vs2010-web-deployment-packages.

I answered a similar but different question at http://stackoverflow.com/questions/2747081/how-do-you-include-additional-files-using-vs2010-web-deployment-packages.

在您的情况您使用后生成事件,我会建议下探后生成事件,并使用替代后生成事件你自己的MSBuild目标,实现自己的行为。下面你会发现对方的回答的文本。

In your scenario you are using post build event, I would recommend dropping the post build event and implement your actions using your own MSBuild targets instead of post build event. Below you'll find the text of the other answer.

从:<一href=\"http://stackoverflow.com/questions/2747081/how-do-you-include-additional-files-using-vs2010-web-deployment-packages\">How你使用VS2010 Web部署软件包,包括其他文件?

From: How do you include additional files using VS2010 web deployment packages?

大问题。我刚刚发布了这个一个非常详细的博客条目在<一个href=\"http://sedodream.com/2010/05/01/WebDeploymentToolMSDeployBuildPackageIncludingExtraFilesOrExcludingSpecificFiles.aspx\">Web部署工具(MSDeploy):构建软件包,包括额外的文件或排除特定文件

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.

包括加文件

包括额外的文件放入包是有点困难,但仍没有bigee如果你是舒服的MSBuild,如果你不那么阅读。为了做到这一点,我们需要挂接到收集中的文件进行包装的过程的一部分。我们需要扩大目标被称为CopyAllFilesToSingleFolder。这个目标有一个依赖属性,管道preDeployCopyAllFilesToOneFolderDependsOn,我们可以挖掘到并注入我们自己的目标。因此,我们将创建一个名为目标和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>
</PropertyGroup>

这将我们的目标添加到过程,现在我们需要定义目标本身。让我们假设你有一个文件夹命名,它位于1级Web项目上面附加文件。您要包括所有这些文件。这里是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,并在包括属性告诉它拿起文件夹中的所有文件和它下面的任何文件夹。然后,我用这个项目来填充FilesForPackagingFromProject项目。这是MSDeploy实际使用添加额外的文件的项目。还要注意,我声明了元数据DestinationRelativePath值。这将确定其将被放置在包中的相对路径。我这里使用的声明附加文件%(RecursiveDir)%(文件名)%(分机)。那是什么意思是将其置于相同的相对位置在包中,因为它是多余的文件夹下。

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. 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" />

BTW你可以打开项目文件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.js其中包括Web应用程序,但你想要的文件,从创建的包被排除在外。您可以将低于进口语句后段。

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.js 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.

这篇关于如何获得Visual Studio的“发布”功能,包括后生成事件文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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