且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在Visual Studio10自定义生成步骤中定义规则

更新时间:2022-12-11 16:59:42

使用 build-events [ ^ ]。请记住,事件本质上是任何命令行调用,因此您可以轻松调用执行所需操作的脚本。您的脚本可以是可以从命令行调用的任何内容(您可以使用python / perl或Windows中本机支持的其他内容)。
Use build-events[^]. Remember that the events are essentially any command line call, so you can easily call a script that does whatever you need. Your script can be anything that can be called from the command line (you can use python/perl or something else that's already natively supported in Windows).


自定义构建和创建的更好方法您自己的步骤将直接使用MSBuild项目文件标准。请参阅:

http:// msdn .microsoft.com / zh-CN / library / wea2sca5%28v = vs.90%29.aspx [ ^ ],

http://msdn.microsoft.com/en-us/library/7z253716.aspx [ ^ ]。



您可以创建您自己的自定义步骤代码,它不能比应用程序或批处理脚本更好地作为单独的进程启动。更好的方法是使用MSBuild API开发自定义任务程序集。此程序集从构建过程和项目(选项,文件名,参数)中获取所有必需信息,并可以对其进行操作,并期望生成集成到构建过程中的输出。这是一种设计精良,集成度高且功能强大的方法,所有元素都高度标准化。同时,您可以轻松集成第三方构建代码,甚至是第三方构建应用程序,而无需源代码(我不喜欢)。它正确地适用于时间戳,增量构建和重建,清理,所有这些。请从这里开始:

http:// msdn.microsoft.com/en-us/library/ms171466%28v=vs.90%29.aspx [ ^ ],

http://msdn.microsoft.com/en-us/library/7z253716.aspx [ ^ ]。



请注意您可以轻松地组织构建以在其他步骤之前编译自定义任务程序集,然后在构建中使用,因此您不需要任何可执行文件,只需要纯源代码。这对于良好的维护来说要好得多。



为了解决更简单的问题,你可以使用解决方案1中解释的方法。但是基于这种方法的自定义步骤外观和行为就像外国元素,并且不具备可维护性。



-SA
The better way to customize build and create your own steps would be using the MSBuild project file standard directly. Please see:
http://msdn.microsoft.com/en-us/library/wea2sca5%28v=vs.90%29.aspx[^],
http://msdn.microsoft.com/en-us/library/7z253716.aspx[^].

You can create your own code for a custom step, which cannot be something better than the application or a batch script to be launched as a separate process. The better approach is to develop the custom Task assembly using MSBuild API. This assembly gets all required information from the build process and the project (options, file names, parameters) and can manipulate them and is expected to produce output integrated into the build process. This is a very well-designed, well-integrated and robust approach, with all elements highly standardized. At the same time, you can easily integrate 3rd-party build code, and even 3rd-party build applications without source code (which I would not prefer). It correctly works with time stamps, incremental build and rebuild, cleaning, all that. Please start here:
http://msdn.microsoft.com/en-us/library/ms171466%28v=vs.90%29.aspx[^],
http://msdn.microsoft.com/en-us/library/7z253716.aspx[^].

Note that you can easily organize the build to have your custom Task assemblies compiled before other steps and then used in the build, so you don't need to have any executable, only pure source code. This is much better for good maintenance.

In a pinch, for solving simpler problems you can use the approach explained in Solution 1. But the custom steps based on such approach look and behave like "foreign" elements and are not as good for maintainability.

—SA