MSBuild 目标 _CopyWebApplication 不会将所有必需的文件复制到 bin 文件夹

发布于 2024-08-27 15:37:08 字数 796 浏览 8 评论 0 原文

在 Web 上的其他地方,您可以找到有关使用类似方法从命令行模拟 VS 2005-2008 IDE 中的发布功能的建议(我希望我没有弄乱语法!):

msbuild /t:ResolveReferences;_CopyWebApplication /p:BuildingProject=true;OutDir=C:\inetpub\wwwroot\ blah.csproj

现在,它看起来像.dll 的副本很好。但是,应用程序需要将某些配置文件和模板文件复制到 bin 文件夹才能运行。例如,NHibernate 配置文件在 blah.csproj 中显示为:

<None Include="blah.cfg.xml">
  <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>

在 IDE 中使用 Publish 时,会按应有的方式复制此文件,但上述 _CopyWebApplication 目标不会。我需要在构建脚本中复制该文件。这是 _CopyWebApplication 所需的行为吗?关于如何解决这个问题有什么建议吗?

编辑 4/21/2010:

让我澄清一下,我们(目前)仅限于 VS 2005 和 VS 2008 项目,并且我们的构建脚本是为 MSBuild 3.x 编写的。我们还没有准备好迁移到 VS 2010。

我还要指出的是,我们正在寻找一种可从命令行使用的解决方案,以便我们可以自动化类似发布的命令以及自定义构建选项,并可能自动化部署路。

Elsewhere on the Web, you can find recommendations on using something like this to simulate the Publish feature in the VS 2005-2008 IDE from a command-line (I hope I did not goof up the syntax!):

msbuild /t:ResolveReferences;_CopyWebApplication /p:BuildingProject=true;OutDir=C:\inetpub\wwwroot\ blah.csproj

Now, it looks like the .dll's copy fine. However, there are certain configuration files and template files that are copied to the bin folder which are needed for the app to work. For example, an NHibernate configuration file shows up in blah.csproj as:

<None Include="blah.cfg.xml">
  <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>

While using Publish from within the IDE copies this file as it should, the aforementioned _CopyWebApplication target does not. I need this file to be copied in the build script. Is this desired behavior for _CopyWebApplication? Any recommendations on how to fix this?

EDIT 4/21/2010:

Let me clarify that we are limited (for now) to VS 2005 and VS 2008 projects, and that our build scripts are written for MSBuild 3.x. We are not yet ready to move to VS 2010.

Let me also specify that we are looking for a solution available from within a command line so that we can automate a Publish-like command along with custom build options, and possibly automate deployments down the road.

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

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

发布评论

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

评论(3

尐偏执 2024-09-03 15:37:08

这只是一个解决方法。

在用于发布网站的构建脚本中,在 Web 项目本身上运行 MSBuild 来发布它 (Targets="ResolveReferences;_CopyWebApplication") 后,我添加了一个复制操作:

<Copy SourceFiles="@(ProjectBinFiles)" DestinationFolder="$(StageBin)\%(ProjectBinFiles.RecursiveDir)" />

其中 ProjectBinFiles 是一个 Item,表示源目录,StageBin 是一个属性,表示已发布站点目录中的 bin 文件夹。到目前为止,它似乎有效。

This is just a workaround.

In the build script for publishing Web sites, after running MSBuild on the Web project itself to publish it (Targets="ResolveReferences;_CopyWebApplication"), I added a copy operation:

<Copy SourceFiles="@(ProjectBinFiles)" DestinationFolder="$(StageBin)\%(ProjectBinFiles.RecursiveDir)" />

where ProjectBinFiles is an Item representing the files in the bin directory in the source directory, and StageBin is a Property representing the bin folder in the published site's directory. So far, it seems to work.

孤者何惧 2024-09-03 15:37:08

我也有类似的问题。我认为答案是使用 MSDeploy。现在正在调查它,但可能提供所需的功能......

I was having a similar issue as well. I think the answer is using MSDeploy. Investigating it now, but may provide functionality required...

帅冕 2024-09-03 15:37:08

我在 VS 2012 中遇到了同样的问题,并最终通过对需要复制的任何文件执行以下操作来修复它:

  • 将“复制到输出”文件属性设置为“如果较新则复制”
  • 将“构建操作”文件属性设置为“内容”(如果该文件则“编译”)需要编译)

I had this same issue in VS 2012 and eventually fixed it by doing the following to any files which needed to be copied:

  • Set the Copy to Output file property to Copy if newer
  • Set the Build Action file property to Content (or Compile if the file needs to be compiled)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文