Microsoft has shipped two syntaxes for writing .NET code in C++, and a third place to run it. A file is told apart by its words, not by a version number: nothing in the text names a version.
The versions
| Name | Compiler | Marks in a file | Page |
|---|---|---|---|
| Managed Extensions for C++ (Managed C++) | Visual Studio .NET 2002 and 2003; compiled today only with the old-syntax option of the versions that still have it | double-underscore keywords: __gc, __value, __nogc, __property, __delegate, __box, __pin, __try_cast; pointers (*) to managed objects; S"…" string literals | Managed Extensions |
| C++/CLI | Visual Studio 2005 and later; defined by the Ecma standard ECMA-372, first edition, December 2005 | ref class, value class, handles ^, gcnew, property, generic, for each | the other pages of this section |
| C++/CLI on .NET Core | Visual Studio 2019 version 16.4 and later, with /clr:netcore | the same language; the difference is in the options and the project, not in the text | The /clr options |
What changed, in order
- Managed Extensions for C++. The first version used C++ syntax with keywords marked by two underscores, so that they could not clash with the names of a program. Managed objects were reached through ordinary pointers (
Foo*), which was the main source of confusion, because a pointer to a managed object is not a pointer. - C++/CLI. Visual Studio 2005 replaced the syntax: new types with spaced keywords instead of attributes on classes, handles instead of managed pointers,
gcnewinstead of overloadingnew, first-class properties, events and delegates, generics, stack semantics and a clean difference between a destructor and a finalizer. The Managed Extensions could be compiled in that release with/clr:oldSyntax. The release also added/clr:pureand/clr:safe. - The standard. Ecma International published ECMA-372, the C++/CLI Language Specification, first edition, in December 2005, with the text of the extensions as a separate standard on top of ISO C++.
- Removal of pure and safe. Microsoft deprecated
/clr:pureand/clr:safeand removed them in Visual Studio 2017: code that must be pure or verifiable MSIL should be ported to C#. - .NET Core.
/clr:netcore, available from Visual Studio 2019 version 16.4, makes the compiler write metadata and code for the cross-platform .NET instead of the .NET Framework.
The language did not take the later features of C# (for example nullable reference types, records or async methods) as keywords; C++/CLI has not been extended since the first edition of the standard, as far as the pages read here say, and Microsoft’s own advice for new .NET code is C#, keeping C++/CLI for the layer that joins .NET to native code.
How the viewer tells a version
- A
__gc,__value,__nogc,__pin,__box,__try_cast,__property,__delegate,__abstractor__sealedword, with no strong C++/CLI mark in the file: Managed Extensions for C++. - A strong mark of C++/CLI (a
ref class,gcnew,#usingand so on): C++/CLI. When both sets of words are present, the file is read as Managed Extensions only if it has the double-underscore class words. - The .NET Core version has no difference in the text.
Not described
Known, not yet covered
- Reference: a table of which Visual Studio release added or removed each keyword and option was not built; of the dates, only the ones on the Microsoft pages that were read (the
/clroptions page) and the date of the first edition of the standard are given. The history of the later editions of ECMA-372 and the features that .NET Core does not support in C++/CLI were not read. - Reference: the sentence about the language not growing is a reading of the Microsoft pages and not a statement of the standard.