Skip to content

Commit cee85cb

Browse files
update grpc-start to .NET 9 (#34603)
* archive grpc-start .NET 8 * update grpc-start article to .NET 9 * add grpc-start .NET 9 sample * correct code highlighting lines * Update aspnetcore/tutorials/grpc/grpc-start.md Updated to 9.0 for framework selection in VS * Update gRPC tutorial ms.date * Update tutorial date in grpc-start.md --------- Co-authored-by: Wade Pickett <[email protected]>
1 parent 42c465a commit cee85cb

File tree

13 files changed

+536
-57
lines changed

13 files changed

+536
-57
lines changed

aspnetcore/includes/run-the-app9.0.md

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# [Visual Studio](#tab/visual-studio)
2+
3+
* Press Ctrl+F5 to run without the debugger.
4+
5+
[!INCLUDE[](~/includes/trustCertVS.md)]
6+
7+
Visual Studio:
8+
9+
* Starts [Kestrel](xref:fundamentals/servers/index#kestrel) server.
10+
* Launches a browser.
11+
* Navigates to `http://localhost:port`, such as `http://localhost:7042`.
12+
* *port*: A randomly assigned port number for the app.
13+
* `localhost`: The standard hostname for the local computer. Localhost only serves web requests from the local computer.
14+
15+
# [Visual Studio Code](#tab/visual-studio-code)
16+
17+
[!INCLUDE[](~/includes/trustCertVSC.md)]
18+
19+
* Press **Ctrl-F5** to run without the debugger.
20+
21+
Visual Studio Code:
22+
23+
* Starts [Kestrel](xref:fundamentals/servers/index#kestrel) server.
24+
* Launches a browser.
25+
* Navigates to `http://localhost:port`, such as `http://localhost:7042`.
26+
* *port*: A randomly assigned port number for the app.
27+
* `localhost`: The standard hostname for the local computer. Localhost only serves web requests from the local computer.
28+
29+
---

aspnetcore/tutorials/grpc/grpc-start.md

+21-57
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@ author: jamesnk
44
description: This tutorial shows how to create a gRPC Service and gRPC client on ASP.NET Core. Learn how to create a gRPC Service project, edit a proto file, and add a duplex streaming call.
55
monikerRange: '>= aspnetcore-3.0'
66
ms.author: wpickett
7-
ms.date: 08/30/2023
7+
ms.date: 01/30/2025
88
uid: tutorials/grpc/grpc-start
99
---
1010
# Tutorial: Create a gRPC client and server in ASP.NET Core
1111

12-
:::moniker range=">= aspnetcore-8.0"
12+
:::moniker range=">= aspnetcore-9.0"
1313
This tutorial shows how to create a .NET Core [gRPC](xref:grpc/index) client and an ASP.NET Core gRPC Server. At the end, you'll have a gRPC client that communicates with the gRPC Greeter service.
1414

1515
In this tutorial, you:
@@ -23,15 +23,11 @@ In this tutorial, you:
2323

2424
# [Visual Studio](#tab/visual-studio)
2525

26-
[!INCLUDE[](~/includes/net-prereqs-vs-8.0.md)]
26+
[!INCLUDE[](~/includes/net-prereqs-vs-9.0.md)]
2727

2828
# [Visual Studio Code](#tab/visual-studio-code)
2929

30-
[!INCLUDE[](~/includes/net-prereqs-vsc-8.0.md)]
31-
32-
# [Visual Studio for Mac](#tab/visual-studio-mac)
33-
34-
[!INCLUDE[](~/includes/net-prereqs-mac-8.0.md)]
30+
[!INCLUDE[](~/includes/net-prereqs-vsc-9.0.md)]
3531

3632
---
3733

@@ -43,13 +39,13 @@ In this tutorial, you:
4339
* In the **Create a new project** dialog, search for `gRPC`. Select **ASP.NET Core gRPC Service** and select **Next**.
4440
* In the **Configure your new project** dialog, enter `GrpcGreeter` for **Project name**. It's important to name the project *GrpcGreeter* so the namespaces match when you copy and paste code.
4541
* Select **Next**.
46-
* In the **Additional information** dialog, select **.NET 8.0 (Long Term Support)** and then select **Create**.
42+
* In the **Additional information** dialog, select **.NET 9.0 (Standard Term Support)** and then select **Create**.
4743

4844
# [Visual Studio Code](#tab/visual-studio-code)
4945

5046
The tutorial assumes familiarity with VS Code. For more information, see [Getting started with VS Code](https://code.visualstudio.com/docs).
5147

52-
* Select **New Terminal** from the **Terminal** menu to open the [integrated terminal](https://code.visualstudio.com/docs/editor/integrated-terminal).
48+
* Select **New Terminal** from the **Terminal** menu to open the [integrated terminal](https://code.visualstudio.com/docs/terminal/basics).
5349
* Change to the directory (`cd`) that will contain the project.
5450
* Run the following commands:
5551

@@ -64,19 +60,11 @@ The tutorial assumes familiarity with VS Code. For more information, see [Gettin
6460

6561
[!INCLUDE[](~/includes/vscode-trust-authors-add-assets.md)]
6662

67-
# [Visual Studio for Mac](#tab/visual-studio-mac)
68-
69-
* Start Visual Studio 2022 for Mac and select **File** > **New Project**.
70-
* In the **Choose a template for your new project** dialog, select **Web and Console** > **App** > **gRPC Service** and select **Continue**.
71-
* Select **.NET 8.0** for the target framework and select **Continue**.
72-
* Name the project **GrpcGreeter**. It's important to name the project *GrpcGreeter* so the namespaces match when you copy and paste code.
73-
* Select **Continue**.
74-
7563
---
7664

7765
### Run the service
7866

79-
[!INCLUDE[](~/includes/run-the-app6.0.md)]
67+
[!INCLUDE[](~/includes/run-the-app9.0.md)]
8068

8169
The logs show the service listening on `https://localhost:<port>`, where `<port>` is the localhost port number randomly assigned when the project is created and set in `Properties/launchSettings.json`.
8270

@@ -110,11 +98,11 @@ info: Microsoft.Hosting.Lifetime[0]
11098
* Open a second instance of Visual Studio and select **New Project**.
11199
* In the **Create a new project** dialog, select **Console App**, and select **Next**.
112100
* In the **Project name** text box, enter **GrpcGreeterClient** and select **Next**.
113-
* In the **Additional information** dialog, select **.NET 8.0 (Long Term Support)** and then select **Create**.
101+
* In the **Additional information** dialog, select **.NET 9.0 (Standard Term Support)** and then select **Create**.
114102

115103
# [Visual Studio Code](#tab/visual-studio-code)
116104

117-
* Open the [integrated terminal](https://code.visualstudio.com/docs/editor/integrated-terminal).
105+
* Open the [integrated terminal](https://code.visualstudio.com/docs/terminal/basics).
118106
* Change directories (`cd`) to a folder for the project.
119107
* Run the following commands:
120108

@@ -125,14 +113,6 @@ info: Microsoft.Hosting.Lifetime[0]
125113

126114
[!INCLUDE[](~/includes/vscode-trust-authors-add-assets.md)]
127115

128-
# [Visual Studio for Mac](#tab/visual-studio-mac)
129-
130-
* In Visual Studio 2022 for Mac select **File** > **Add** > **Project...**.
131-
* In the **Choose a template for your new project** dialog, select **Web and Console** > **App** > **Console Application**, and select **Continue**.
132-
* Select **.NET 8.0** for the target framework, and select **Continue**.
133-
* Name the project **GrpcGreeterClient**. It's important to name the project *GrpcGreeterClient* so the namespaces match when you copy and paste code.
134-
* Select **Continue**.
135-
136116
---
137117

138118
### Add required NuGet packages
@@ -177,15 +157,6 @@ dotnet add GrpcGreeterClient.csproj package Google.Protobuf
177157
dotnet add GrpcGreeterClient.csproj package Grpc.Tools
178158
```
179159

180-
# [Visual Studio for Mac](#tab/visual-studio-mac)
181-
182-
* Right-click **GrpcGreeterClient** project in the **Solution Pad** and select **Manage NuGet Packages**.
183-
* Enter **Grpc.Net.Client** in the search box.
184-
* Select the **Grpc.Net.Client** package from the results pane and select **Add Package**.
185-
* In **Select Projects** select **OK**.
186-
* If the **License Acceptance** dialog appears, select **Accept** if you agree to the license terms.
187-
* Repeat for `Google.Protobuf` and `Grpc.Tools`.
188-
189160
---
190161

191162
### Add greet.proto
@@ -208,10 +179,6 @@ dotnet add GrpcGreeterClient.csproj package Grpc.Tools
208179

209180
Select the `GrpcGreeterClient.csproj` file.
210181

211-
# [Visual Studio for Mac](#tab/visual-studio-mac)
212-
213-
Right-click the project and select **Edit Project File**.
214-
215182
---
216183

217184
* Add an item group with a `<Protobuf>` element that refers to the *greet.proto* file:
@@ -236,7 +203,7 @@ dotnet add GrpcGreeterClient.csproj package Grpc.Tools
236203
237204
* Update the gRPC client `Program.cs` file with the following code.
238205

239-
[!code-csharp[](~/tutorials/grpc/grpc-start/sample/sample8/GrpcGreeterClient/Program.cs?name=snippet2&highlight=6)]
206+
[!code-csharp[](~/tutorials/grpc/grpc-start/sample/sample9/GrpcGreeterClient/Program.cs?name=snippet2&highlight=5)]
240207

241208
* In the preceding highlighted code, replace the localhost port number `7042` with the `HTTPS` port number specified in `Properties/launchSettings.json` within the `GrpcGreeter` service project.
242209

@@ -247,33 +214,28 @@ The Greeter client is created by:
247214
* Instantiating a `GrpcChannel` containing the information for creating the connection to the gRPC service.
248215
* Using the `GrpcChannel` to construct the Greeter client:
249216

250-
[!code-csharp[](~/tutorials/grpc/grpc-start/sample/sample8/GrpcGreeterClient/Program.cs?name=snippet&highlight=1-3)]
217+
[!code-csharp[](~/tutorials/grpc/grpc-start/sample/sample9/GrpcGreeterClient/Program.cs?name=snippet&highlight=1-3)]
251218

252219
The Greeter client calls the asynchronous `SayHello` method. The result of the `SayHello` call is displayed:
253220

254-
[!code-csharp[](~/tutorials/grpc/grpc-start/sample/sample8/GrpcGreeterClient/Program.cs?name=snippet&highlight=4-7)]
221+
[!code-csharp[](~/tutorials/grpc/grpc-start/sample/sample9/GrpcGreeterClient/Program.cs?name=snippet&highlight=4-6)]
255222

256223
## Test the gRPC client with the gRPC Greeter service
257224

258225
Update the `appsettings.Development.json` file by adding the following highlighted lines:
259226

260-
[!code-csharp[](~/tutorials/grpc/grpc-start/sample/sample8/GrpcGreeter/appsettings.Development.json?highlight=6-7)]
227+
[!code-csharp[](~/tutorials/grpc/grpc-start/sample/sample9/GrpcGreeter/appsettings.Development.json?highlight=6-7)]
261228

262229
# [Visual Studio](#tab/visual-studio)
263230

264-
* In the Greeter service, press `Ctrl+F5` to start the server without the debugger.
265-
* In the `GrpcGreeterClient` project, press `Ctrl+F5` to start the client without the debugger.
231+
* In the `GrpcGreeter` service project, press `Ctrl+F5` to start the server without the debugger.
232+
* In the `GrpcGreeterClient` console project, press `Ctrl+F5` to start the client without the debugger.
266233

267234
# [Visual Studio Code](#tab/visual-studio-code)
268235

269236
* Start the Greeter service.
270237
* Start the client.
271238

272-
# [Visual Studio for Mac](#tab/visual-studio-mac)
273-
274-
* Start the Greeter service.
275-
* Start the client.
276-
277239
---
278240

279241
The client sends a greeting to the service with a message containing its name, *GreeterClient*. The service sends the message "Hello GreeterClient" as a response. The "Hello GreeterClient" response is displayed in the command prompt:
@@ -295,13 +257,13 @@ info: Microsoft.Hosting.Lifetime[0]
295257
info: Microsoft.Hosting.Lifetime[0]
296258
Content root path: C:\GH\aspnet\docs\4\Docs\aspnetcore\tutorials\grpc\grpc-start\sample\GrpcGreeter
297259
info: Microsoft.AspNetCore.Hosting.Diagnostics[1]
298-
Request starting HTTP/2 POST https://localhost:<port>/Greet.Greeter/SayHello application/grpc
260+
Request starting HTTP/2 POST https://localhost:<port>/greet.Greeter/SayHello application/grpc
299261
info: Microsoft.AspNetCore.Routing.EndpointMiddleware[0]
300-
Executing endpoint 'gRPC - /Greet.Greeter/SayHello'
262+
Executing endpoint 'gRPC - /greet.Greeter/SayHello'
301263
info: Microsoft.AspNetCore.Routing.EndpointMiddleware[1]
302-
Executed endpoint 'gRPC - /Greet.Greeter/SayHello'
264+
Executed endpoint 'gRPC - /greet.Greeter/SayHello'
303265
info: Microsoft.AspNetCore.Hosting.Diagnostics[2]
304-
Request finished in 78.32260000000001ms 200 application/grpc
266+
Request finished HTTP/2 POST https://localhost:7042/greet.Greeter/SayHello - 200 - application/grpc 40.4615ms
305267
```
306268

307269
> [!NOTE]
@@ -316,6 +278,8 @@ info: Microsoft.AspNetCore.Hosting.Diagnostics[2]
316278

317279
:::moniker-end
318280

281+
[!INCLUDE[](~/tutorials/grpc/grpc-start/includes/grpc-start8.md)]
282+
319283
[!INCLUDE[](~/tutorials/grpc/grpc-start/includes/grpc-start7.md)]
320284

321285
[!INCLUDE[](~/tutorials/grpc/grpc-start/includes/grpc-start6.md)]

0 commit comments

Comments
 (0)