在C#代码中重用来自.h文件的define语句 [英] Reuse define statement from .h file in C# code

查看:287
本文介绍了在C#代码中重用来自.h文件的define语句的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有C ++项目(VS2005)包括头文件版本号在#define指令。现在我需要包括完全相同的数字在双C#项目。最好的方法是什么?

I have C++ project (VS2005) which includes header file with version number in #define directive. Now I need to include exactly the same number in twin C# project. What is the best way to do it?

我正在考虑将这个文件作为资源,然后在运行时解析它与regex恢复版本号,但也许有一个更好的方式,你觉得怎么样?

I'm thinking about including this file as a resource, then parse it at a runtime with regex to recover version number, but maybe there's a better way, what do you think?

我不能移动版本.h文件,也构建系统依赖于它,C#项目是一个应该

I cannot move version outside .h file, also build system depends on it and the C# project is one which should be adapted.

推荐答案

您可以通过几个步骤实现所需的功能:

You can achieve what you want in just a few steps:


  1. 创建MSBuild任务 - http:/ /msdn.microsoft.com/en-us/library/t9883dzc.aspx

  2. 更新项目文件以包含对生成之前创建的任务的调用

任务接收一个参数,其中包含您引用的头文件.h文件的位置。然后,它提取版本,并将该版本放在您以前创建的C#占位符文件。

The task receives a parameter with the location of the header .h file you referred. It then extracts the version and put that version in a C# placeholder file you previously have created. Or you can think using AssemblyInfo.cs that normally holds versions if that is ok for you.

如果你需要额外的信息,请随意评论。

If you need extra information please feel free to comment.

这篇关于在C#代码中重用来自.h文件的define语句的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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