C++/CLI has one compiler: the Microsoft C++ compiler (cl), which runs on Windows. Other C++ compilers (GCC, Clang) do not read the extensions, and Mono and the .NET SDK have no C++/CLI compiler.
Quick reference
| Tool | Use |
|---|---|
cl /clr file.cpp | compile a file as C++/CLI; /clr:netcore for .NET Core; /c to compile without linking; /LD for a DLL |
link | link objects into an assembly; the linker options for assemblies are on The /clr options |
| Visual Studio templates | CLR Console App, CLR Class Library, CLR Empty Project, and (in the versions that have it) a Windows Forms template for C++/CLI. They set the project properties that a CLR component needs |
ildasm | shows the IL, metadata and the native stubs of the assembly (IL) |
| ILSpy and other decompilers | show the managed part as C# or IL; the native part of a mixed assembly is machine code that they show as bytes or leave out |
dumpbin /clrheader and the linker option /CLRHEADER | report whether a file is a native or a CLR image and which flags the CLR header has (.NET assembly) |
What the output is
A C++/CLI project builds a .dll or .exe that is a normal .NET assembly with a CLR header and metadata, and, in a mixed-mode build, native code and import tables as well. The PE32 and PE64 pages and the .NET assembly pages describe the file; a type declared public ref class appears in its metadata as a public class and is used by C# and Visual Basic like any other. The native parts are not visible to them.
On this Mac
C++/CLI could not be compiled here: cl runs only on Windows, and the .NET SDK on this Mac (10.0.404) has no C++/CLI compiler. The sample files used to test the viewer were written by hand or taken from published C++/CLI sources, and the assemblies they would build were not made.
Not described
Known, not yet covered
- Reference: the list of Visual Studio templates, the build tools that can be installed without the IDE, and the support for C++/CLI in other editors (IntelliSense is partial for C++/CLI in some releases) were not checked.