如何在Visual Studio10自定义生成步骤中定义规则 [英] How to define rules in Visual Studio10 custom build step

查看:113
本文介绍了如何在Visual Studio10自定义生成步骤中定义规则的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,



我有以下问题:



我有一个VS10项目有几个文件。实际上,并非所有文件都已存在。 (我已经包含了对它们的引用)



在自定义构建步骤中,foo.exe工具将创建尚不存在的文件,将在编译之前执行。这个工具需要一个文件(所有特定的扩展名,比如.def,只有那里,创建新文件,永远不会被编译)并创建一个新文件。到目前为止一切都那么好。



问题:我有多个项目,我必须完成这个任务,我不想写每个文件我必须创建,foo.exe需要一定的foo2.def来创建某个文件。



有没有办法说Visual Studio,每个文件都有一定的扩展名(这里:.def)必须由工具创建另一个文件?



也许是通过.props文件或类似的东西?我可以包含在所有项目文件(.vcxproj)中。



thx很多任何帮助!

Hi all,

I have the following question:

I have a VS10 project which has several files. Actually, not all files already exist. (i have included references to them)

The files which do not already exist, will be created by a tool, say foo.exe, in a custom-build step, which will be executed before compilation. This tool takes one file (all of a certain extension, say .def, which is only there, to create the new file, it will never be compiled) and creates a new file. So far so good.

Problem: I have multiple projects, for which i have to accomplish this task and i don't want to write for each file i have to create, that foo.exe takes a certain foo2.def to create a certain file.

Is there a way to say Visual Studio, that every file with a certain extension (here: .def) has to be taken by the tool to create another file?

Perhaps by a .props-file or something like this? Which i can include in all project-files (.vcxproj).

thx alot for any help!

推荐答案

使用 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


这篇关于如何在Visual Studio10自定义生成步骤中定义规则的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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