Skip to content

Commit c87bf16

Browse files
author
mikeblome
committed
added cli walkthough back into to dotnet
1 parent 0a6c1ec commit c87bf16

File tree

3 files changed

+100
-23
lines changed

3 files changed

+100
-23
lines changed

.openpublishing.redirection.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -958,6 +958,12 @@
958958
"redirect_url": "cpp/build/reference/visual-cpp-project-types",
959959
"redirect_document_id": false
960960
},
961+
{
962+
"source_path": "docs/ide/walkthrough-compiling-a-cpp-program-that-targets-the-clr-in-visual-studio.md",
963+
"redirect_url": "cpp/dotnet/walkthrough-compiling-a-cpp-program-that-targets-the-clr-in-visual-studio",
964+
"redirect_document_id": false
965+
},
966+
961967
{
962968
"source_path": "docs/ide/web-references-property-page.md",
963969
"redirect_url": "cpp/build/reference/web-references-property-page",

docs/dotnet/TOC.md

Lines changed: 24 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,29 @@
11
# [.NET Programming with C++/CLI](dotnet-programming-with-cpp-cli-visual-cpp.md)
2+
## [Walkthrough: Compile a C++/CLI Program that Targets the CLR](walkthrough-compiling-a-cpp-program-that-targets-the-clr-in-visual-studio.md)
23
## [C++/CLI Tasks](cpp-cli-tasks.md)
34
### [How to: Create CLR Empty Projects](how-to-create-clr-empty-projects.md)
4-
### [How to: Create CLR Console Applications (C++/CLI)](how-to-create-clr-console-applications-cpp-cli.md)
5+
### [How to: Create CLR Console Applications](how-to-create-clr-console-applications-cpp-cli.md)
56
### [How to: Use Tracking References in C++/CLI](how-to-use-tracking-references-in-cpp-cli.md)
67
### [How to: Use Arrays in C++/CLI](how-to-use-arrays-in-cpp-cli.md)
7-
### [How to: Define and Consume Classes and Structs (C++/CLI)](how-to-define-and-consume-classes-and-structs-cpp-cli.md)
8+
### [How to: Define and Consume Classes and Structs](how-to-define-and-consume-classes-and-structs-cpp-cli.md)
89
### [C++ Stack Semantics for Reference Types](cpp-stack-semantics-for-reference-types.md)
9-
### [User-Defined Operators (C++/CLI)](user-defined-operators-cpp-cli.md)
10-
### [User-Defined Conversions (C++/CLI)](user-defined-conversions-cpp-cli.md)
11-
### [initonly (C++/CLI)](initonly-cpp-cli.md)
12-
### [How to: Define and Use Delegates (C++/CLI)](how-to-define-and-use-delegates-cpp-cli.md)
10+
### [User-Defined Operators](user-defined-operators-cpp-cli.md)
11+
### [User-Defined Conversions](user-defined-conversions-cpp-cli.md)
12+
### [initonly](initonly-cpp-cli.md)
13+
### [How to: Define and Use Delegates](how-to-define-and-use-delegates-cpp-cli.md)
1314
### [How to: Define and consume enums in C++/CLI](how-to-define-and-consume-enums-in-cpp-cli.md)
1415
### [How to: Use Events in C++/CLI](how-to-use-events-in-cpp-cli.md)
15-
### [How to: Define an Interface Static Constructor (C++/CLI)](how-to-define-an-interface-static-constructor-cpp-cli.md)
16-
### [How to: Declare Override Specifiers in Native Compilations (C++/CLI)](how-to-declare-override-specifiers-in-native-compilations-cpp-cli.md)
16+
### [How to: Define an Interface Static Constructor](how-to-define-an-interface-static-constructor-cpp-cli.md)
17+
### [How to: Declare Override Specifiers in Native Compilations](how-to-declare-override-specifiers-in-native-compilations-cpp-cli.md)
1718
### [How to: Use Properties in C++/CLI](how-to-use-properties-in-cpp-cli.md)
1819
### [How to: Use safe_cast in C++/CLI](how-to-use-safe-cast-in-cpp-cli.md)
19-
### [Regular Expressions (C++/CLI)](regular-expressions-cpp-cli.md)
20-
### [File Handling and I-O (C++/CLI)](file-handling-and-i-o-cpp-cli.md)
21-
### [Graphics Operations (C++/CLI)](graphics-operations-cpp-cli.md)
22-
### [Windows Operations (C++/CLI)](windows-operations-cpp-cli.md)
23-
### [Data Access Using ADO.NET (C++/CLI)](data-access-using-adonet-cpp-cli.md)
20+
### [Regular Expressions](regular-expressions-cpp-cli.md)
21+
### [File Handling and I-O](file-handling-and-i-o-cpp-cli.md)
22+
### [Graphics Operations](graphics-operations-cpp-cli.md)
23+
### [Windows Operations](windows-operations-cpp-cli.md)
24+
### [Data Access Using ADO.NET](data-access-using-adonet-cpp-cli.md)
2425
## [Native and .NET Interoperability](native-and-dotnet-interoperability.md)
25-
### [Interoperability with Other .NET Languages (C++/CLI)](interoperability-with-other-dotnet-languages-cpp-cli.md)
26+
### [Interoperability with Other .NET Languages](interoperability-with-other-dotnet-languages-cpp-cli.md)
2627
### [Mixed (Native and Managed) Assemblies](mixed-native-and-managed-assemblies.md)
2728
#### [How to: Migrate to -clr](how-to-migrate-to-clr.md)
2829
#### [How to: Compile MFC and ATL Code By Using -clr](how-to-compile-mfc-and-atl-code-by-using-clr.md)
@@ -79,16 +80,16 @@
7980
##### [How to: Use a Native Type in a -clr Compilation](how-to-use-a-native-type-in-a-clr-compilation.md)
8081
##### [How to: Declare Handles in Native Types](how-to-declare-handles-in-native-types.md)
8182
##### [How to: Wrap Native Class for Use by C#](how-to-wrap-native-class-for-use-by-csharp.md)
82-
## [Pure and Verifiable Code (C++/CLI)](pure-and-verifiable-code-cpp-cli.md)
83-
### [How to: Create Verifiable C++ Projects (C++/CLI)](how-to-create-verifiable-cpp-projects-cpp-cli.md)
84-
### [Using Verifiable Assemblies with SQL Server (C++/CLI)](using-verifiable-assemblies-with-sql-server-cpp-cli.md)
83+
## [Pure and Verifiable Code](pure-and-verifiable-code-cpp-cli.md)
84+
### [How to: Create Verifiable C++ Projects](how-to-create-verifiable-cpp-projects-cpp-cli.md)
85+
### [Using Verifiable Assemblies with SQL Server](using-verifiable-assemblies-with-sql-server-cpp-cli.md)
8586
### [Converting Projects from Mixed Mode to Pure Intermediate Language](converting-projects-from-mixed-mode-to-pure-intermediate-language.md)
86-
## [Serialization (C++/CLI)](serialization-cpp-cli.md)
87+
## [Serialization](serialization-cpp-cli.md)
8788
## [Friend Assemblies (C++)](friend-assemblies-cpp.md)
88-
## [Managed Types (C++/CLI)](managed-types-cpp-cli.md)
89-
## [Reflection (C++/CLI)](reflection-cpp-cli.md)
90-
## [Strong Name Assemblies (Assembly Signing) (C++/CLI)](strong-name-assemblies-assembly-signing-cpp-cli.md)
91-
## [Debug Class (C++/CLI)](debug-class-cpp-cli.md)
89+
## [Managed Types](managed-types-cpp-cli.md)
90+
## [Reflection](reflection-cpp-cli.md)
91+
## [Strong Name Assemblies (Assembly Signing)](strong-name-assemblies-assembly-signing-cpp-cli.md)
92+
## [Debug Class](debug-class-cpp-cli.md)
9293
## [STL/CLR Library Reference](stl-clr-library-reference.md)
9394
### [cliext Namespace](cliext-namespace.md)
9495
### [STL/CLR Containers](stl-clr-containers.md)
@@ -142,7 +143,7 @@
142143
### [finally](finally.md)
143144
### [How to: Catch Exceptions in Native Code Thrown from MSIL](how-to-catch-exceptions-in-native-code-thrown-from-msil.md)
144145
### [How to: Define and Install a Global Exception Handler](how-to-define-and-install-a-global-exception-handler.md)
145-
## [Boxing (C++/CLI)](boxing-cpp-cli.md)
146+
## [Boxing](boxing-cpp-cli.md)
146147
### [How to: Explicitly Request Boxing](how-to-explicitly-request-boxing.md)
147148
### [How to: Use gcnew to Create Value Types and Use Implicit Boxing](how-to-use-gcnew-to-create-value-types-and-use-implicit-boxing.md)
148149
### [How to: Unbox](how-to-unbox.md)
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
---
2+
title: "Compile a C++/CLI Program that Targets the CLR"
3+
ms.date: "09/17/2018"
4+
helpviewer_keywords: ["command-line applications [C++], managed code", "compiling programs [C++]", "Visual C++, managed code", "managed code [C++]"]
5+
ms.assetid: 339f89df-a5d2-4040-831a-ddbe25b5dce4
6+
---
7+
# Walkthrough: Compile a C++/CLI Program that Targets the CLR in Visual Studio
8+
9+
By using C++/CLI language extensions you can create C++ programs that use .NET classes and compile them by using the Visual Studio Development Environment.
10+
11+
For this procedure, you can type your own C++ program or use one of the sample programs. The sample program that we use in this procedure creates a text file named textfile.txt, and saves it to the project directory.
12+
13+
## Prerequisites
14+
15+
These topics assume that you understand the fundamentals of the C++ language.
16+
17+
### To create a new project in Visual Studio and add a new source file
18+
19+
1. Create a new project. On the **File** menu, point to **New**, and then click **Project**.
20+
21+
1. From the Visual C++ project types, click **CLR**, and then click **CLR Empty Project**.
22+
23+
> [!NOTE]
24+
> If the **CLR Empty Project** type is missing (Visual Studio 2017 only), select **Open Visual Studio Installer** in the left pane of the **New Project** dialog box. Install the option located under **Desktop development with C++** in the **Optional** components section, named **C++/CLI Support**.<br/>
25+
26+
1. Type a project name.
27+
28+
By default, the solution that contains the project has the same name as the new project, but you can enter a different name. You can enter a different location for the project if you want.
29+
30+
Click **OK** to create the new project.
31+
32+
1. If **Solution Explorer** isn't visible, click **Solution Explorer** on the **View** menu.
33+
34+
1. Add a new source file to the project:
35+
36+
- Right-click the **Source Files** folder in **Solution Explorer**, point to **Add**, and click **New Item**.
37+
38+
- Click **C++ File (.cpp)** and type a file name and then click **Add**.
39+
40+
The **.cpp** file appears in the **Source Files** folder in **Solution Explorer** and a tabbed window appears where you type the code you want in that file.
41+
42+
1. Click in the newly created tab in Visual Studio and type a valid Visual C++ program, or copy and paste one of the sample programs.
43+
44+
For example, you can use the [How to: Write a Text File (C++/CLI)](../dotnet/how-to-write-a-text-file-cpp-cli.md) sample program (in the **File Handling and I/O** node of the Programming Guide).
45+
46+
If you use the sample program, notice that you use the `gcnew` keyword instead of `new` when creating a .NET object, and that `gcnew` returns a handle (`^`) rather than a pointer (`*`):
47+
48+
`StreamWriter^ sw = gcnew StreamWriter(fileName);`
49+
50+
For more information on the new Visual C++ syntax, see [Component Extensions for Runtime Platforms](../windows/component-extensions-for-runtime-platforms.md).
51+
52+
1. On the **Build** menu, click **Build Solution**.
53+
54+
The **Output** window displays information about the compilation progress, such as the location of the build log and a message that indicates the build status.
55+
56+
If you make changes and run the program without doing a build, a dialog box might indicate that the project is out of date. Select the checkbox on this dialog before you click **OK** if you want Visual Studio to always use the current versions of files instead of prompting you each time it builds the application.
57+
58+
1. On the **Debug** menu, click **Start without Debugging**.
59+
60+
1. If you used the sample program, when you run the program a command window is displayed that indicates the text file has been created.
61+
62+
The **textfile.txt** text file is now located in your project directory. You can open this file by using Notepad.
63+
64+
> [!NOTE]
65+
> Choosing the empty CLR project template automatically set the `/clr` compiler option. To verify this, right-click the project in **Solution Explorer** and clicking **Properties**, and then check the **Common Language Runtime support** option in the **General** node of **Configuration Properties**.
66+
67+
## See Also
68+
69+
[C++ Language Reference](../cpp/cpp-language-reference.md)<br/>
70+
[Building C/C++ Programs](../build/building-c-cpp-programs.md)<br/>

0 commit comments

Comments
 (0)