How to compile a program using .NET Framework compilers at command line.?

久未见 提交于 2019-12-11 07:47:11

问题


i want to compile a c++ program using .NET2.0 compiler. so i navigate to c:\windows\Microsoft.Netframework\2.0.57\ and uses csc compiler to compile.

It shows lot of errors.

But it compiles csharp file. But in visual studio it compiles. so i think that in visual studio c++ copiler installed i think so.

filename test.cpp

using namespace System;

class test

{

   void disp()

   {

      Console::WriteLine("Hello");
   }

 };

 void main()

{

  test *t=new test();

   t->disp();

}

so plz tell me is it possible to compile c++ file using .net framework 2.0 based comiler at command prompt and how?


回答1:


csc is the C# compiler, so you shouldn't be surprised that it doesn't compile C++.

Use cl (the C++ compiler) with the /clr switch to compile C++/CLI code. Alternatively, if you've got a solution/project file, use msbuild.

Note that the C++ compiler doesn't ship with .NET, unlike the C# compiler.




回答2:


It shouldn't be a huge surprise that the C# compiler doesn't like the C++ code; you might as well feed it vb / java / whatever - it isn't going to be legal.

To compile C++, you'll need the C++ compiler, perhaps from C++ Express Edition. Note that for this to compile into mixed/IL it'll been to be managed C++.




回答3:


csc is the compiler for csharp, not C++

The easiest way to compile from the command line is to use msbuild, and pass it the name of your project (or solution file).



来源:https://stackoverflow.com/questions/857355/how-to-compile-a-program-using-net-framework-compilers-at-command-line

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!