如何始终执行MSBuild中的目标 [英] How to always execute a target in MSBuild

查看:89
本文介绍了如何始终执行MSBuild中的目标的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个MSBuild文件,该文件在编译应用程序之前会处理AssemblyInfo文件.在构建结束时,它将还原AssemblyInfo文件.它是通过备份文件,进行操作,然后在构建时间之后还原文件来实现的.

I have an MSBuild file that manipulates the AssemblyInfo file before the application is compiled. At the end of the build, it restores the AssemblyInfo file. It does this by backing up the file, manipulating it, and then after build time, restoring the file.

这工作得很好,除非在构建过程中发生错误.然后,它不会还原原始文件.有没有一种方法可以告诉MSBuild在构建结束时执行目标,而不管它是成功还是失败?

This works fairly well except when an error occurs during the build. It then does not restore the original file. Is there a way I can tell MSBuild to execute a target at the end of a build no matter if it succeeded or failed?

推荐答案

如何解决问题:

  • 在版本控制中添加一个模板" AssemblyInfo.cs.template,以表示其中带有正则表达式钩子的理想" AssemblyInfo.cs
  • 在构建之前,将模板复制到真实版本并应用正则表达式
  • 为AssemblyInfo.cs添加某种Subversion忽略(我不是svn专家,但是我很确定有一种方法可以告诉它忽略某些文件)
  • 如果您的开发人员需要添加某种通常会出现在AssemblyInfo.cs中的自定义项(例如InternalsVisibleTo),然后让他们将其添加到不同 .cs文件中,已签入.
  • Add a "template" AssemblyInfo.cs.template to version control that represents your "ideal" AssemblyInfo.cs with regex hooks in there
  • Before build, copy the template to the real and apply your regexes
  • Add some kind of subversion ignore for AssemblyInfo.cs (I'm no svn expert, but I'm pretty sure there is a way you can tell it to ignore certain files)
  • In the event that your devs need to add some kind of customization that would normally appear in an AssemblyInfo.cs (eg InternalsVisibleTo), then get them to add it to a different .cs file that IS checked in.

作为进一步的改进,将Sayed的解决方案与我的解决方案相结合,并从实际的AssemblyInfo.cs中删除版本信息,并具有已签入的VersionInfo.cs.template,该模板将在BeforeBuild中创建VersionInfo.cs.

As a further refinement, combine Sayed's solution with mine and remove version info stuff from the actual AssemblyInfo.cs and have a VersionInfo.cs.template that is checked in, that creates a VersionInfo.cs in BeforeBuild.

这篇关于如何始终执行MSBuild中的目标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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