如何获取 Visual Studio“发布”包含来自构建后事件的文件的功能?

发布于 2024-09-07 09:17:18 字数 282 浏览 13 评论 0原文

我目前正在尝试使用 Visual Studio 2010“发布”和 MSDeploy 功能来处理我的 Web 部署需求,但在根据我的构建配置自定义包方面遇到了障碍。

我在 32 位环境中开发,但需要为 64 位环境创建发布包,因此在“发布”配置中,我有一个构建后事件,它将第三方 dll 的 64 位版本复制到 bin 目录中,覆盖 32 位版本。当我使用“发布”功能时,即使正确的 64 位 dll 被复制到 bin 目录,它也不会包含在包中。

有没有办法让“发布”包含在构建后事件期间复制到 bin 目录中的文件?

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.

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.

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

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

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

发布评论

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

评论(7

娇妻 2024-09-14 09:19:39

我有同样的问题。
解决方法是在 .csproj 中使用 CopyToPublishDirectory

 <Content Include="Data\Reports\Статистика по пользователям\lib.dll">
        <CopyToOutputDirectory>Always</CopyToOutputDirectory>
          <CopyToPublishDirectory>Always</CopyToPublishDirectory>
      </Content>

I had same problem.
resolve was a use CopyToPublishDirectory in .csproj

 <Content Include="Data\Reports\Статистика по пользователям\lib.dll">
        <CopyToOutputDirectory>Always</CopyToOutputDirectory>
          <CopyToPublishDirectory>Always</CopyToPublishDirectory>
      </Content>
甜是你 2024-09-14 09:19:34

我知道这是一个古老的对话,但我在尝试做同样的事情时遇到了它,我认为添加我在这里找到的内容会很有帮助。

几乎所有有关在出版物中包含额外文件的文章都使用这种在 PropertyGroup 中添加 CopyAllFilesToSingleFolderForPackageDependsOnCopyAllFilesToSingleFolderForMSDeployDependsOn 项的方法,它们都具有相同的内容就像“我将其添加到文件末尾......”

这就是我所做的,花了一个下午试图找出为什么没有发生任何事情,直到我意识到顶部已经有一个 PropertyGroup 部分文件的。当我将 CopyAllFilesToSingleFolderForPackageDependsOn 放入该部分时,它工作正常。

希望有一天这可以节省某人的时间

I know this is an old conversation but I came upon it while trying to do the same thing and I thought it would be helpful to add what I found here.

Nearly all the articles about including extra files in your publication use this method of adding the CopyAllFilesToSingleFolderForPackageDependsOn or CopyAllFilesToSingleFolderForMSDeployDependsOn items in the PropertyGroup and they all same something like "I added this to the end of the file ..."

This is what I did and spent an afternoon trying to find why nothing was happening until I realised there was already a PropertyGroup section at the top of the file. When I put my CopyAllFilesToSingleFolderForPackageDependsOn into that section it worked fine.

Hope this saves someone time some day

沫雨熙 2024-09-14 09:19:29

将 bin 文件夹(及其内容)添加到项目导致文件被复制到发布输出目录。

对我来说,我的问题是我需要将专有软件许可证文件放置在 bin/ 文件夹中,但不想在每次部署时手动复制它。

这是使用 Visual Studio 2015 Professional

Adding the bin folder (and it's contents) to the project caused the files to be copied to the publish output directory.

For me, my issue was that I needed to place a proprietary software license file in the bin/ folder, but did not want to copy it manually each deployment.

This was using Visual Studio 2015 Professional

∝单色的世界 2024-09-14 09:19:24

我知道这是一个老问题,但这些都不适合我。

在 2017 VS 中,我只需右键单击要发布的额外文件夹,然后选择发布即可。

示例:

在此处输入图像描述

I know its a old question but none of these worked for me .

In 2017 VS I just right clicked on the extra folder to be published and select publish it worked.

Example:

enter image description here

指尖微凉心微凉 2024-09-14 09:19:17

选择文件或文件夹,然后从属性窗口将构建操作更改为内容。

Select your files or folders and Change Build action as Content from Properties Window.

不知所踪 2024-09-14 09:19:05

我通过使用项目文件中的 ExcludeFilesFromDeployment 元素找到了解决该问题的方法。我的想法来自 Web部署:排除文件和文件夹

所以如果你需要打包成功构建和关联的构建后步骤后,项目文件存在于项目目录中,然后执行以下操作。

  1. 编辑“打包/发布 Web”项目设置并
    选择要部署的项目为“此项目文件夹中的所有文件”

  2. 卸载项目

  3. 右键单击卸载的项目并选择编辑项目配置

  4. 找到与配置设置(例如“Release”)关联的 PropertyGroup 元素

  5. PropertyGroup 元素中添加以下元素并排除您不需要的文件和文件夹包

    *.cs;**\.svn\**\*.*;Web.*.config;*.csproj*;
    .svn;控制器;BootstrapperTasks;属性
    
  6. 保存并重新加载项目

这暂时解决了我的问题,但如果有更好的解决方案,请告诉我,因为由于涉及黑客行为,这并不理想,但话又说回来,也许这是一个不常见的部署场景?

I found a workaround for the problem by using the ExcludeFilesFromDeployment element within the project file. I got the idea from Web Deployment: Excluding Files and Folders

So if you need to package project files as they exist in your project directory after a successful build and associated post build steps then do the following.

  1. Edit "Package/Publish Web" project settings and
    select Items to deploy to be "All files in this project folder"

  2. Unload the project

  3. Right click on the unloaded project and select to edit the project config

  4. Locate the PropertyGroup element associated to the configuration setting e.g. "Release"

  5. Within the PropertyGroup element add in the following elements and exclude files and folders you don't want in the package

    <ExcludeFilesFromDeployment>*.cs;**\.svn\**\*.*;Web.*.config;*.csproj*</ExcludeFilesFromDeployment>
    <ExcludeFoldersFromDeployment>.svn;Controllers;BootstrapperTasks;Properties</ExcludeFoldersFromDeployment>
    
  6. Save and reload your project

This solves my problem for the time being but if there is a better solution then please let me know, as this is not ideal due to the hackery involved, but then again perhaps this is an uncommon deployment scenario?

仙女 2024-09-14 09:18:41

我在 How do您使用 VS2010 Web 部署包包含其他文件吗?

在您使用构建后事件的场景中,我建议删除构建后事件并使用您自己的 MSBuild 目标而不是构建后事件来实施您的操作。您将在下面找到另一个答案的文本。


来自:如何包含额外的文件使用 VS2010 Web 部署包?


好问题。我刚刚在 Web 部署工具 (MSDeploy) :构建包中发布了一篇非常详细的博客文章包括额外文件或排除特定文件

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

包含额外文件

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

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

这会将我们的目标添加到流程中,现在我们需要定义目标本身。假设您有一个名为 Extra Files 的文件夹,位于 Web 项目的上一级。您想要包含所有这些文件。这是 CustomCollectFiles 目标,我们随后进行讨论。

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

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

在这里,我所做的是创建项目 _CustomFiles 并在 Include 属性中告诉它拾取该文件夹及其下面的任何文件夹中的所有文件。然后我使用此项来填充 FilesForPackagingFromProject 项。这是 MSDeploy 实际用来添加额外文件的项目。另请注意,我声明了元数据 DestinationRelativePath 值。这将确定它将被放置在包中的相对路径。我在这里使用了 Extra Files%(RecursiveDir)%(Filename)%(Extension) 语句。也就是说,将其放置在包中与 Extra Files 文件夹下相同的相对位置。

排除文件

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

<Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v10.0\WebApplications\Microsoft.WebApplication.targets" />

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

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

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

通过声明填充此项,文件将自动被排除。请注意此处 FromTarget 元数据的用法。我不会在这里讨论这一点,但您应该知道始终要指定这一点。

I answered a similar but different question at How do you include additional files using VS2010 web deployment packages?.

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.


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


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.

Including Extra Files

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>

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>

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.

Excluding files

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

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>

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.

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