|
1 | 1 | ---
|
2 | 2 | title: "How to: Create CLR Console Applications (C++/CLI)"
|
3 |
| -ms.date: "11/04/2016" |
| 3 | +description: "Learn how to create CLR Console App projects to use C++/CLI in Visual Studio." |
| 4 | +ms.date: 12/08/2020 |
4 | 5 | helpviewer_keywords: ["console applications, templates", "CLR console applications, project template"]
|
5 |
| -ms.assetid: e89bce3c-706f-4ae0-8a90-cb1a0f674e70 |
6 | 6 | ---
|
7 | 7 | # How to: Create CLR Console Applications (C++/CLI)
|
8 | 8 |
|
9 |
| -You can use the Console Application template to create a console app project that already has essential project references and files. |
| 9 | +::: moniker range="msvc-140" |
10 | 10 |
|
11 |
| -Typically, a console app is compiled into a stand-alone executable file but doesn't have a graphical user interface. A user runs the console app at a command prompt and uses the command prompt to issue instructions to the running app. Also at the command prompt, the app provides output information. The immediacy of a console app makes it a great way to learn programming techniques without concern for implementing a user interface. |
| 11 | +You can use the **CLR Console Application** template in the **New Project** dialog to create a console app project that already has essential project references and files. |
12 | 12 |
|
13 |
| -When you use the Console Application template to create a project, it automatically adds these references and files: |
| 13 | +::: moniker-end |
| 14 | +::: moniker range="msvc-150" |
| 15 | + |
| 16 | +You can use the **CLR Console App** template in the **New Project** dialog to create a console app project that already has essential project references and files. |
| 17 | + |
| 18 | +C++/CLI support isn't installed by default when you install a Visual Studio C++ workload. If you don't see a CLR heading under Visual C++ in the **New Project** dialog, you may need to install C++/CLI support. For more information, see [.NET programming with C++/CLI](../dotnet/dotnet-programming-with-cpp-cli-visual-cpp.md). |
| 19 | + |
| 20 | +::: moniker-end |
| 21 | +::: moniker range="msvc-160" |
| 22 | + |
| 23 | +You can use the **CLR Console App (.NET Framework)** template in the **Create a new project** dialog to create a console app project that already has essential project references and files. |
| 24 | + |
| 25 | +C++/CLI support isn't installed by default when you install a Visual Studio C++ workload. If you don't see CLR project templates in the **Create a new project** dialog, you may need to install C++/CLI support. For more information, see [.NET programming with C++/CLI](../dotnet/dotnet-programming-with-cpp-cli-visual-cpp.md). |
| 26 | + |
| 27 | +::: moniker-end |
| 28 | + |
| 29 | +Typically, a console app is compiled into a stand-alone executable file but doesn't have a graphical user interface. Users run the console app at a command prompt. They can use the command line to issue instructions to the running app. The app provides output information as text in the command window. The immediate feedback of a console app makes it a great way to learn programming. You don't need to worry about how to implement a graphical user interface. |
| 30 | + |
| 31 | +::: moniker range="msvc-140" |
| 32 | + |
| 33 | +When you use the CLR Console Application template to create a project, it automatically adds these references and files: |
14 | 34 |
|
15 | 35 | - References to these .NET Framework namespaces:
|
16 | 36 |
|
17 |
| - - <xref:System.AppDomainManager>—Contains fundamental classes and base classes that define commonly used values and reference data types, events and event handlers, interfaces, attributes, and processing exceptions. |
| 37 | + - <xref:System>, <xref:System.Data>, <xref:System.Xml>: These references contain the fundamental classes that define commonly used types, events, interfaces, attributes, and exceptions. |
18 | 38 |
|
19 |
| - - mscorlib—The assembly DLL that supports .NET Framework development. |
| 39 | + - *`mscorlib.dll`*: The assembly DLL that supports .NET Framework development. |
20 | 40 |
|
21 | 41 | - Source files:
|
22 | 42 |
|
23 |
| - - Console (.cpp file)—The main source file and entry point into the app that you just created. It identifies the project .dll file and the project namespace. Provide your own code in this file. |
| 43 | + - *`ConsoleApplicationName.cpp`*: The main source file and entry point into the app. This file has the base name you specified for your project. It identifies the project DLL file and the project namespace. Provide your own code in this file. |
24 | 44 |
|
25 |
| - - AssemblyInfo.cpp—Contains attributes, files, resources, types, versioning information, signing information, and so on that you can use to modify the project's assembly metadata. For more information, see [Assembly Contents](/dotnet/framework/app-domains/assembly-contents). |
| 45 | + - *`AssemblyInfo.cpp`*: Contains attributes and settings that you can use to modify the project's assembly metadata. For more information, see [Assembly contents](/dotnet/framework/app-domains/assembly-contents). |
26 | 46 |
|
27 |
| - - Stdafx.cpp—Used to build a precompiled header file that's named Win32.pch and a precompiled types file that's named StdAfx.obj. |
| 47 | + - *`stdafx.cpp`*: Used to build a precompiled header file that's named *`ConsoleApplicationName.pch`* and a precompiled types file that's named *`stdafx.obj`*. |
28 | 48 |
|
29 | 49 | - Header files:
|
30 | 50 |
|
31 |
| - - Stdafx.h—Used to build a precompiled header file that's named Win32.pch and a precompiled types file that's named StdAfx.obj. |
| 51 | + - *`stdafx.h`*: Used to build a precompiled header file that's named *`ConsoleApplicationName.pch`* and a precompiled types file that's named *`stdafx.obj`*. |
32 | 52 |
|
33 |
| - - resource.h—A generated include file for app.rc. |
| 53 | + - *`resource.h`*: A generated include file for *`app.rc`*. |
34 | 54 |
|
35 | 55 | - Resource files:
|
36 | 56 |
|
37 |
| - - app.rc—The resource script file of a program. |
| 57 | + - *`app.rc`*: The resource script file of a program. |
38 | 58 |
|
39 |
| - - app.ico—The icon file of a program. |
| 59 | + - *`app.ico`*: The icon file of a program. |
40 | 60 |
|
41 |
| -- ReadMe.txt—Describes the files in the project. |
| 61 | +- *`ReadMe.txt`*: Describes the files in the project. |
42 | 62 |
|
43 |
| -## To create a common language runtime (CLR) console app project |
| 63 | +::: moniker-end |
| 64 | +::: moniker range=">=msvc-150" |
| 65 | + |
| 66 | +When you use the CLR Console App template to create a project, it automatically adds these references and files: |
| 67 | + |
| 68 | +- References to these .NET Framework namespaces: |
44 | 69 |
|
45 |
| -1. On the menu bar, choose **File**, **New**, **Project**. |
| 70 | + - <xref:System>, <xref:System.Data>, <xref:System.Xml>: These references contain the fundamental classes that define commonly used types, events, interfaces, attributes, and exceptions. |
46 | 71 |
|
47 |
| -1. In the **New Project** dialog box, under **Installed Templates**, select the **Visual C++** node, select the **CLR** node, and then select the Console Application template. |
| 72 | + - *`mscorlib.dll`*: The assembly DLL that supports .NET Framework development. |
| 73 | + |
| 74 | +- Source files: |
| 75 | + |
| 76 | + - *`ConsoleApplicationName.cpp`*: The main source file and entry point into the app. This file has the base name you specified for your project. It identifies the project DLL file and the project namespace. Provide your own code in this file. |
| 77 | + |
| 78 | + - *`AssemblyInfo.cpp`*: Contains attributes and settings that you can use to modify the project's assembly metadata. For more information, see [Assembly contents](/dotnet/framework/app-domains/assembly-contents). |
| 79 | + |
| 80 | + - *`pch.cpp`*: Used to build a precompiled header file that's named *`ConsoleApplicationName.pch`* and a precompiled types file that's named *`pch.obj`*. |
| 81 | + |
| 82 | +- Header files: |
| 83 | + |
| 84 | + - *`pch.h`*: Used to build a precompiled header file that's named *`ConsoleApplicationName.pch`* and a precompiled types file that's named *`pch.obj`*. |
| 85 | + |
| 86 | + - *`Resource.h`*: A generated include file for *`app.rc`*. |
| 87 | + |
| 88 | +- Resource files: |
| 89 | + |
| 90 | + - *`app.rc`*: The resource script file of a program. |
| 91 | + |
| 92 | + - *`app.ico`*: The icon file of a program. |
| 93 | + |
| 94 | +::: moniker-end |
| 95 | + |
| 96 | +## To create a CLR console app project |
| 97 | + |
| 98 | +::: moniker range="msvc-140" |
| 99 | + |
| 100 | +1. On the menu bar, choose **File** > **New** > **Project**. |
| 101 | + |
| 102 | +1. In the **New Project** dialog box, select the **Installed** > **Templates** > **Visual C++** > **CLR** node, and then select the **CLR Console Application** template. |
| 103 | + |
| 104 | +1. In the **Name** box, enter a unique name for your application. |
| 105 | + |
| 106 | + You can specify other project and solution settings, but they're not required. |
| 107 | + |
| 108 | +1. Choose the **OK** button to generate the project and source files. |
| 109 | + |
| 110 | +::: moniker-end |
| 111 | +::: moniker range="msvc-150" |
| 112 | + |
| 113 | +1. On the menu bar, choose **File** > **New** > **Project**. |
| 114 | + |
| 115 | +1. In the **New Project** dialog box, select the **Installed** > **Visual C++** > **CLR** node, and then select the **CLR Console App** template. |
48 | 116 |
|
49 | 117 | 1. In the **Name** box, enter a unique name for your application.
|
50 | 118 |
|
51 |
| - You can specify other project and solution settings, but they are not required. |
| 119 | + You can specify other project and solution settings, but they're not required. |
| 120 | + |
| 121 | +1. Choose the **OK** button to generate the project and source files. |
| 122 | + |
| 123 | +::: moniker-end |
| 124 | +::: moniker range="msvc-160" |
| 125 | + |
| 126 | +1. On the menu bar, choose **File** > **New** > **Project**. |
| 127 | + |
| 128 | +1. In the **Create a new project** dialog box, enter "clr console" in the search box. Select the **CLR Console App (.NET Framework)** template, and then choose **Next**. |
| 129 | + |
| 130 | +1. In the **Name** box, enter a unique name for your application. |
| 131 | + |
| 132 | + You can specify other project and solution settings, but they're not required. |
| 133 | + |
| 134 | +1. Choose the **Create** button to generate the project and source files. |
52 | 135 |
|
53 |
| -1. Choose the **OK** button. |
| 136 | +::: moniker-end |
54 | 137 |
|
55 | 138 | ## See also
|
56 | 139 |
|
57 |
| -[CLR Projects](../build/reference/files-created-for-clr-projects.md) |
| 140 | +[CLR projects](../build/reference/files-created-for-clr-projects.md) |
0 commit comments