在构建事件中使用编译器常量
无论如何,是否可以在 Visual Studio - VB.NET 的构建事件中使用编译器常量? (特别是在构建后事件中)
场景
如果定义了TEST_EDITION=TRUE
,我想在构建后事件期间运行可执行文件,所以如果它是FALSE 然后我会运行别的东西。
这可用于为不同版本创建不同的安装程序。
PS 在有人建议之前:不,我不想使用 nant、msbuild 或类似的东西
Is there anyway to use compiler constants in Build Events in Visual Studio - VB.NET? (especially in Post-Build events)
Scenario
If TEST_EDITION=TRUE
is defined I want to run an executable during the Post-Build event so if it's FALSE
then I'll run something else.
This can be used for creating different installers for different editions.
P.S. Before someone suggests: No I don't want to use nant, msbuild or something like that
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
是的,$(DefineConstants) 宏可用并且可以在构建事件中进行测试。例如,Project + Compile、Advanced Compile Options、Custom Constants = Test 可以这样测试:
更复杂的自定义常量(如 Test=TRUE 或复合常量)需要进行不同的解析。不可否认,我很快就放弃了尝试弄清楚如何使用可怕的 FOR 命令。
Yes, the $(DefineConstants) macro is available and can be tested in a build event. For example, Project + Compile, Advanced Compile Options, Custom constants = Test can be tested like this:
More complicated custom constants like Test=TRUE or compound constants need to be parsed differently. Admittedly I quickly gave up trying to figure out how to use the horrid FOR command.
您尝试过 MsBuild PostEvents 吗?这是 .csproj 的摘录...但这同样适用于 vbproj 文件
您可以将其与 TaskExec 目标,允许您运行批处理文件或可执行文件。
Have you tried the MsBuild PostEvents? this is an extract of a .csproj... but the same applies to vbproj files
You can use it with the TaskExec Target, which allows you to run a batch file or an executable.
不确定 Visual Basic 的语法,但 C++ 可以使用以下技巧:文件 global_inc.bat 读取为:
这可以由在构建后事件中调用的批处理脚本输入。
C++ 代码使用该文件的方式如下:
构建后步骤如下所示:
另一种可能性是预构建步骤生成一个
.vb
文件以及配置构建后步骤中使用的文件。Not sure about Visual Basic's syntax, but the following trick can be used by C++: the file global_inc.bat reads as:
This could be input by a batch script which was called in post-build event.
The C++ code used the file as follows:
The postbuild step looked like this:
Another possibility would be for the prebuild step to generate a
.vb
file, as well as a configuration file used in postbuild step.