在构建事件中使用编译器常量

发布于 2024-08-23 08:03:51 字数 293 浏览 4 评论 0原文

无论如何,是否可以在 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 技术交流群。

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

发布评论

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

评论(3

寻找一个思念的角度 2024-08-30 08:03:51

是的,$(DefineConstants) 宏可用并且可以在构建事件中进行测试。例如,Project + Compile、Advanced Compile Options、Custom Constants = Test 可以这样测试:

if /i "$(DefineConstants)" NEQ "TEST" goto skiptest
echo Setting up for test environment
:skiptest

更复杂的自定义常量(如 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:

if /i "$(DefineConstants)" NEQ "TEST" goto skiptest
echo Setting up for test environment
:skiptest

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.

遗弃M 2024-08-30 08:03:51

您尝试过 MsBuild PostEvents 吗?这是 .csproj 的摘录...但这同样适用于 vbproj 文件

  <!-- To modify your build process, add your task inside one of the targets below and uncomment it. 
       Other similar extension points exist, see Microsoft.Common.targets.
  <Target Name="BeforeBuild">
  </Target>
  <Target Name="AfterBuild">
  </Target>
  -->
  <Target Name="BeforeBuild">
  </Target>
  <Target Name="AfterBuild">
    <Copy SourceFiles="$(OutputPath)$(AssemblyName).dll" DestinationFolder="$(BinariesFolder)" ContinueOnError="true" />
  </Target>

您可以将其与 TaskExec 目标,允许您运行批处理文件或可执行文件。

<Target Name="DoSomething">
    <Exec Command="D:\DoSomething.exe"/>
</Target>

Have you tried the MsBuild PostEvents? this is an extract of a .csproj... but the same applies to vbproj files

  <!-- To modify your build process, add your task inside one of the targets below and uncomment it. 
       Other similar extension points exist, see Microsoft.Common.targets.
  <Target Name="BeforeBuild">
  </Target>
  <Target Name="AfterBuild">
  </Target>
  -->
  <Target Name="BeforeBuild">
  </Target>
  <Target Name="AfterBuild">
    <Copy SourceFiles="$(OutputPath)$(AssemblyName).dll" DestinationFolder="$(BinariesFolder)" ContinueOnError="true" />
  </Target>

You can use it with the TaskExec Target, which allows you to run a batch file or an executable.

<Target Name="DoSomething">
    <Exec Command="D:\DoSomething.exe"/>
</Target>
乖乖哒 2024-08-30 08:03:51

不确定 Visual Basic 的语法,但 C++ 可以使用以下技巧:文件 global_inc.bat 读取为:

SET PARAMETER=TRUE

这可以由在构建后事件中调用的批处理脚本输入。
C++ 代码使用该文件的方式如下:

#define PARAMETER const int parameter
#define SET /**/
#include "global_inc.bat"
;
#undef PARAMETER

构建后步骤如下所示:

call global_inc.bat
if "%PARAMETER%" == "TRUE" echo True

另一种可能性是预构建步骤生成一个 .vb 文件以及配置构建后步骤中使用的文件。

Not sure about Visual Basic's syntax, but the following trick can be used by C++: the file global_inc.bat reads as:

SET PARAMETER=TRUE

This could be input by a batch script which was called in post-build event.
The C++ code used the file as follows:

#define PARAMETER const int parameter
#define SET /**/
#include "global_inc.bat"
;
#undef PARAMETER

The postbuild step looked like this:

call global_inc.bat
if "%PARAMETER%" == "TRUE" echo True

Another possibility would be for the prebuild step to generate a .vb file, as well as a configuration file used in postbuild step.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文