How to compile a program using .NET Framework comp

2019-08-03 04:51发布

问题:

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).