简体   繁体   English

将C代码编译为C#

[英]Compile c code as c#

Hi this may be a strange question but I have some c++ code that I would like to compile as c# code using Visual Studio 2012. 嗨,这可能是一个奇怪的问题,但是我有一些C ++代码,我想使用Visual Studio 2012编译为c#代码。

The code its self is completely compatible and will compile with both compilers. 该代码本身完全兼容,并且可以与两个编译器一起编译。

What I would like to do is have the c# compiler treat the .c files as .cs files and compile them as c#, the reason for this is I still need this particular c++ file for an old library but dont want to have two copies of the code when I update something. 我想做的是让C#编译器将.c文件视为.cs文件并将其编译为c#,原因是我仍然需要旧库的特定c ++文件,但不想有两个副本我更新某些东西时的代码。

Currently I have a batch file that copies the .c code from the c++ project within a solution to the c# project within the same solution and it then uses a pre processor and compiles it however I obviously loose breakpoints, etc and it is a bit of a problem. 目前,我有一个批处理文件,它将.c代码从解决方案中的c ++项目复制到同一解决方案中的c#项目,然后使用预处理器进行编译,但是我显然松开了断点,等等,这有点一个问题。

The file Extension is not relevant just set the Build Action to Compile in the Properties of the file. 文件扩展名无关紧要,只需在文件属性中将“生成操作”设置为“编译”即可。 Syntax Highlighting might have some problems with that but not the compiler. 语法高亮可能与此有关,但编译器没有问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM