Skip to content
This repository was archived by the owner on Apr 9, 2021. It is now read-only.

Commit 748eae3

Browse files
authored
Merge pull request #728 from jtattermusch/csharp_tutorial_quickstart_fixes
Update C# quickstart and tutorial
2 parents 64e2058 + 196e36b commit 748eae3

2 files changed

Lines changed: 54 additions & 159 deletions

File tree

docs/quickstart/csharp.md

Lines changed: 26 additions & 132 deletions
Original file line numberDiff line numberDiff line change
@@ -21,30 +21,9 @@ Whether you're using Windows, OS X, or Linux, you can follow this
2121
example by using either an IDE and its build tools,
2222
or by using the the .NET Core SDK command line tools.
2323

24-
Using the .NET Core SDK on Windows, OS X, or Linux, you'll need:
25-
26-
* The .NET Core SDK command line tools.
27-
* The .NET framework 4.5 (for OS X and Linux, the open source .NET Framework implementation, "Mono", at version 4+, is suitable)
28-
* Git (to download the sample code)
29-
30-
On Windows, using Visual Studio, you'll need:
31-
32-
* .NET Framework 4.5+
33-
* Visual Studio 2013 or 2015.
34-
* Git (to download the sample code)
35-
36-
On OS X, using Xamarin Studio, you'll need:
37-
38-
* Mono 4.4.2+ (or Mono 4+ is sufficient if you manually update NuGet to version 2.12+)
39-
* Xamarin Studio 6.0+
40-
* Git (to download the sample code)
41-
42-
On Linux, using the Monodevelop IDE, you'll need:
43-
44-
* Mono 4.4.2+ (or Mono 4+ is sufficient if you manually update nuget to version 2.12+)
45-
* MonoDevelop 5.9+
46-
* A NuGet executable, at version 2.12+ (you'll need to restore NuGet package dependencies from the command line)
47-
* Git (to download the sample code)
24+
First, make sure you have installed the
25+
[gRPC C# prerequisites](https://github.com/grpc/grpc/blob/{{ site.data.config.grpc_release_tag }}/src/csharp/README.md#prerequisites).
26+
You will also need Git to download the sample code.
4827

4928
## Download the example
5029

@@ -59,86 +38,44 @@ $ git clone -b {{ site.data.config.grpc_release_tag }} https://github.com/grpc/g
5938
$ cd grpc
6039
```
6140

62-
#### Using Visual Studio, Xamarin Studio, or Mondevelop IDEs
63-
64-
* The examples are in the directory, `examples/csharp/helloworld`.
41+
This document will walk you through the "Hello World" example.
42+
The projects and source files can be found in the `examples/csharp/Helloworld` directory.
6543

6644
The example in this walkthrough already adds the necessary
6745
dependencies for you (Grpc, Grpc.Tools and Google.Protobuf NuGet packages).
6846

6947
## Build the example
7048

71-
### Using Visual Studio
72-
* Open the solution `Greeter.sln` with Visual Studio.
73-
* Build the solution (this will automatically download NuGet dependencies)
74-
75-
### Using Xamarin Studio
76-
* Open the solution `Greeter.sln` with Xamarin Studio.
77-
* Project->"Restore NuGet Packages"
78-
* Build the solution (this will automatically download NuGet dependencies)
49+
### Using Visual Studio (or Visual Studio for Mac)
50+
* Open the solution `Greeter.sln` with Visual Studio
51+
* Build the solution
7952

8053
### Using .NET Core SDK from the command line
81-
From the `examples/csharp/helloworld-from-cli` directory:
54+
From the `examples/csharp/Helloworld` directory:
8255

8356
```
84-
> dotnet restore
85-
> dotnet build **/project.json
57+
> dotnet build Greeter.sln
8658
```
8759

88-
### Using the Monodevelop IDE
89-
Using the Monodevelop IDE, you can build and edit a solution that uses gRPC
90-
without issues, but unfortunately a workaround is necessary in order to initially restore
91-
a NuGet dependency on C# gRPC.
60+
*NOTE: If you want to use gRPC C# from a project that uses the old-style .csproj files (supported by Visual Studio 2013, 2015 and older versions of Mono), please refer to the
61+
[Greeter using legacy .csproj](https://github.com/grpc/grpc/blob/{{ site.data.config.grpc_release_tag }}/examples/csharp/HelloworldLegacyCsproj/README.md) example.*
9262

93-
The problem is that C# gRPC package currently depends on
94-
System.Interactive.Async 3.0.0, which requires NuGet 2.12+ to install.
95-
The NuGet included on the latest versions of Monodevelop is too old to install gRPC C#.
96-
97-
If you don't want to change the version of NuGet that you're using,
98-
a possible workaround to get these files is to download the NuGet
99-
package and unzip without a NuGet client, as follows.
100-
101-
* Install NuGet 2.12+ so that it's available from the command line.
102-
* From the `examples/csharp/helloworld` directory, run `/path/to/nuget restore`.
103-
* Now that the NuGet dependencies are restored into their proper package folders, build
104-
the solution from the Monodevelop IDE.
105-
10663
## Run a gRPC application
10764

108-
### Using Visual Studio, Xamarin Studio, or Monodevelop IDEs
109-
From the `examples/csharp/helloworld` directory:
110-
111-
* Run the server
112-
113-
```
114-
> cd GreeterServer/bin/Debug
115-
> GreeterServer.exe
116-
```
117-
118-
* In another terminal, run the client
119-
120-
```
121-
> cd GreeterClient/bin/Debug
122-
> GreeterClient.exe
123-
```
124-
125-
You'll need to run the above executables with "mono" if building on Xamarin Studio for OS X.
126-
127-
### Using the .NET Core SDK
65+
From the `examples/csharp/Helloworld` directory:
12866

12967
* Run the server
13068

13169
```
13270
> cd GreeterServer
133-
> dotnet run
71+
> dotnet run -f netcoreapp2.1
13472
```
13573

136-
13774
* In another terminal, run the client
13875

13976
```
14077
> cd GreeterClient
141-
> dotnet run
78+
> dotnet run -f netcoreapp2.1
14279
```
14380

14481
Congratulations! You've just run a client-server application with gRPC.
@@ -206,50 +143,26 @@ The `Grpc.Tools` NuGet package contains the protoc and protobuf C# plugin binari
206143

207144
### Obtaining the Grpc.Tools NuGet package
208145

209-
#### Using Visual Studio
210-
211-
This example project already depends on the `Grpc.Tools.{{ site.data.config.grpc_release_tag | remove_first: "v" }}` NuGet package, so it should be included in `examples/csharp/helloworld/packages` when the `Greeter.sln` solution is built from your IDE,
212-
or when you restore packages via `/path/to/nuget restore` on the command line.
213-
214-
#### If you have a NuGet client that is __not__ at version 2.12
215-
216-
```
217-
$ mkdir packages && cd packages
218-
$ /path/to/nuget install Grpc.Tools
219-
```
220-
221-
#### If you have a NuGet client that is at version 2.12
222-
223-
NuGet 2.12 does not install the files from the `Grpc.Tools` package necessary on Linux and OS X.
224-
Without changing the version of NuGet that you're using, a possible workaround to obtaining the binaries included in the `Grpc.Tools` package
225-
is by simply downloading the NuGet package and unzipping without a NuGet client, as follows.
226-
From your example directory:
227-
228-
```
229-
$ temp_dir=packages/Grpc.Tools.{{ site.data.config.grpc_release_tag | remove_first: "v" }}/tmp
230-
$ curl_url=https://www.nuget.org/api/v2/package/Grpc.Tools/{{ Grpc.Tools.{{ site.data.config.grpc_release_tag | remove_first: "v" }}
231-
$ mkdir -p $temp_dir && cd $temp_dir && curl -sL $curl_url > tmp.zip; unzip tmp.zip && cd .. && cp -r tmp/tools . && rm -rf tmp && cd ../..
232-
```
146+
This example project already depends on the `Grpc.Tools.{{ site.data.config.grpc_release_tag | remove_first: "v" }}` NuGet package
147+
and the package will be downloaded to your local NuGet cache as soon as you restore the nuget packages by clicking "Restore NuGet Packages" in Visual Studio or running `dotnet restore RouteGuide.sln` from the `examples/csharp/RouteGuide` directory.
233148

234149
### Commands to generate the gRPC code
235150
Note that you may have to change the `platform_architecture` directory names (e.g. windows_x86, linux_x64) in the commands below based on your environment.
236151

237-
Note that you may also have to change the permissions of the protoc and protobuf
238-
binaries in the `Grpc.Tools` package under `examples/csharp/helloworld/packages`
239-
to executable in order to run the commands below.
240-
241-
From the `examples/csharp/helloworld` directory:
152+
From the `examples/csharp/Helloworld` directory:
242153

243154
**Windows**
244155

245156
```
246-
> packages\Grpc.Tools.{{ site.data.config.grpc_release_tag | remove_first: "v" }}\tools\windows_x86\protoc.exe -I../../protos --csharp_out Greeter --grpc_out Greeter ../../protos/helloworld.proto --plugin=protoc-gen-grpc=packages/Grpc.Tools.{{ site.data.config.grpc_release_tag | remove_first: "v" }}/tools/windows_x86/grpc_csharp_plugin.exe
157+
@rem Local nuget cache on Windows is located in %UserProfile%\.nuget\packages
158+
> %UserProfile%\.nuget\packages\Grpc.Tools.{{ site.data.config.grpc_release_tag | remove_first: "v" }}\tools\windows_x86\protoc.exe -I../../protos --csharp_out Greeter --grpc_out Greeter ../../protos/helloworld.proto --plugin=protoc-gen-grpc=%UserProfile%\.nuget\packages\packages\Grpc.Tools.{{ site.data.config.grpc_release_tag | remove_first: "v" }}\tools\windows_x86\grpc_csharp_plugin.exe
247159
```
248160

249161
**Linux (or OS X by using macosx_x64 directory)**
250162

251163
```
252-
$ packages/Grpc.Tools.{{ site.data.config.grpc_release_tag | remove_first: "v" }}/tools/linux_x64/protoc -I../../protos --csharp_out Greeter --grpc_out Greeter ../../protos/helloworld.proto --plugin=protoc-gen-grpc=packages/Grpc.Tools.{{ site.data.config.grpc_release_tag | remove_first: "v" }}/tools/linux_x64/grpc_csharp_plugin
164+
# Local nuget cache on Linux and Mac is located in ~/.nuget/packages
165+
$ ~/.nuget/packages/packages/grpc.tools.{{ site.data.config.grpc_release_tag | remove_first: "v" }}/tools/linux_x64/protoc -I../../protos --csharp_out Greeter --grpc_out Greeter ../../protos/helloworld.proto --plugin=protoc-gen-grpc=~/.nuget/packages/grpc.tools.{{ site.data.config.grpc_release_tag | remove_first: "v" }}/tools/linux_x64/grpc_csharp_plugin
253166
```
254167

255168
Running the appropriate command for your OS regenerates the following files in
@@ -319,43 +232,24 @@ public static void Main(string[] args)
319232
### Rebuild the modified example
320233

321234
Rebuild the newly modified example just like we first built the original
322-
example:
323-
324-
* With solution Greeter.sln open from Visual Studio, Monodevelop (on Linux) or Xamarin Studio (on OS X)
325-
* Build the solution
235+
example by running `dotnet build Greeter.sln`.
326236

327237
### Run!
328238

329-
Just like we did before, from the `examples/csharp/helloworld` directory:
330-
331-
* Run the server
332-
333-
```
334-
> cd GreeterServer/bin/Debug
335-
> GreeterServer.exe
336-
```
337-
338-
* In another terminal, run the client
339-
340-
```
341-
> cd GreeterClient/bin/Debug
342-
> GreeterClient.exe
343-
```
344-
345-
Or if using the .NET Core SDK, from the `examples/csharp/helloworld-from-cli` directory:
239+
Just like we did before, from the `examples/csharp/Helloworld` directory:
346240

347241
* Run the server
348242

349243
```
350244
> cd GreeterServer
351-
> dotnet run
245+
> dotnet run -f netcoreapp2.1
352246
```
353247

354248
* In another terminal, run the client
355249

356250
```
357251
> cd GreeterClient
358-
> dotnet run
252+
> dotnet run -f netcoreapp2.1
359253
```
360254

361255
## What's next

docs/tutorials/basic/csharp.md

Lines changed: 28 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,8 @@ updating.
4343
## Example code and setup
4444

4545
The example code for our tutorial is in
46-
[grpc/grpc/examples/csharp/route_guide](https://github.com/grpc/grpc/tree/
47-
{{ site.data.config.grpc_release_tag }}/examples/csharp/route_guide). To
46+
[grpc/grpc/examples/csharp/RouteGuide](https://github.com/grpc/grpc/tree/
47+
{{ site.data.config.grpc_release_tag }}/examples/csharp/RouteGuide). To
4848
download the example, clone the `grpc` repository by running the following
4949
command:
5050

@@ -54,9 +54,9 @@ $ cd grpc
5454
```
5555

5656
All the files for this tutorial are in the directory
57-
`examples/csharp/route_guide`. Open the solution
58-
`examples/csharp/route_guide/RouteGuide.sln` from Visual Studio, Monodevelop or
59-
Xamarin Studio. For additional installation details, see the [How to use
57+
`examples/csharp/RouteGuide`. Open the solution
58+
`examples/csharp/RouteGuide/RouteGuide.sln` from Visual Studio (Windows or Mac) or Visual Studio Code.
59+
For additional installation details, see the [How to use
6060
instructions](https://github.com/grpc/grpc/tree/
6161
{{ site.data.config.grpc_release_tag }}/src/csharp#how-to-use).
6262

@@ -153,23 +153,26 @@ service definition. We do this using the protocol buffer compiler `protoc` with
153153
a special gRPC C# plugin.
154154

155155
If you want to run this yourself, the `Grpc.Tools` NuGet package contains the
156-
binaries you will need to generate the code.
157-
158-
Once that's done, you can generate the C# code:
156+
binaries you will need to generate the code. You can fetch a copy of
157+
the `Grpc.Tools` package into your local nuget cache by clicking
158+
"Restore NuGet Packages" in Visual Studio or running `dotnet restore RouteGuide.sln`
159+
from the `examples/csharp/RouteGuide` directory. Once that's done, you can generate the C# code.
159160

160161
To generate the code, the following command should be run from the
161-
`examples/csharp/route_guide` directory:
162+
`examples/csharp/RouteGuide` directory:
162163

163164
- Windows
164165

165166
```
166-
> packages\Grpc.Tools.{{ site.data.config.grpc_release_tag | remove_first: "v" }}\tools\windows_x86\protoc.exe -I../../protos --csharp_out RouteGuide --grpc_out RouteGuide ../../protos/route_guide.proto --plugin=protoc-gen-grpc=packages\Grpc.Tools.{{ site.data.config.grpc_release_tag | remove_first: "v" }}\tools\windows_x86\grpc_csharp_plugin.exe
167+
@rem Local nuget cache on Windows is located in %UserProfile%\.nuget\packages
168+
> %UserProfile%\.nuget\packages\Grpc.Tools.{{ site.data.config.grpc_release_tag | remove_first: "v" }}\tools\windows_x86\protoc.exe -I../../protos --csharp_out RouteGuide --grpc_out RouteGuide ../../protos/route_guide.proto --plugin=protoc-gen-grpc=%UserProfile%\.nuget\packages\Grpc.Tools.{{ site.data.config.grpc_release_tag | remove_first: "v" }}\tools\windows_x86\grpc_csharp_plugin.exe
167169
```
168170

169171
- Linux (or Mac OS X by using `macosx_x64` directory).
170172

171173
```
172-
$ packages/Grpc.Tools.{{ site.data.config.grpc_release_tag | remove_first: "v" }}/tools/linux_x64/protoc -I../../protos --csharp_out RouteGuide --grpc_out RouteGuide ../../protos/route_guide.proto --plugin=protoc-gen-grpc=packages/Grpc.Tools.{{ site.data.config.grpc_release_tag | remove_first: "v" }}/tools/linux_x64/grpc_csharp_plugin
174+
# Local nuget cache on Linux and Mac is located in ~/.nuget/packages
175+
$ ~/.nuget/packages/grpc.tools.{{ site.data.config.grpc_release_tag | remove_first: "v" }}/tools/linux_x64/protoc -I../../protos --csharp_out RouteGuide --grpc_out RouteGuide ../../protos/route_guide.proto --plugin=protoc-gen-grpc=~/.nuget/packages/grpc.tools.{{ site.data.config.grpc_release_tag | remove_first: "v" }}/tools/linux_x64/grpc_csharp_plugin
173176
```
174177

175178
Running the appropriate command for your OS regenerates the following files in
@@ -202,8 +205,8 @@ There are two parts to making our `RouteGuide` service do its job:
202205
service responses.
203206

204207
You can find our example `RouteGuide` server in
205-
[examples/csharp/route_guide/RouteGuideServer/RouteGuideImpl.cs](https://github.com/grpc/grpc/blob/
206-
{{ site.data.config.grpc_release_tag }}/examples/csharp/route_guide/RouteGuideServer/RouteGuideImpl.cs).
208+
[examples/csharp/RouteGuide/RouteGuideServer/RouteGuideImpl.cs](https://github.com/grpc/grpc/blob/
209+
{{ site.data.config.grpc_release_tag }}/examples/csharp/RouteGuide/RouteGuideServer/RouteGuideImpl.cs).
207210
Let's take a closer look at how it works.
208211

209212
### Implementing RouteGuide
@@ -373,8 +376,8 @@ do this, we:
373376

374377
In this section, we'll look at creating a C# client for our `RouteGuide`
375378
service. You can see our complete example client code in
376-
[examples/csharp/route_guide/RouteGuideClient/Program.cs](https://github.com/grpc/grpc/blob/
377-
{{ site.data.config.grpc_release_tag }}/examples/csharp/route_guide/RouteGuideClient/Program.cs).
379+
[examples/csharp/RouteGuide/RouteGuideClient/Program.cs](https://github.com/grpc/grpc/blob/
380+
{{ site.data.config.grpc_release_tag }}/examples/csharp/RouteGuide/RouteGuideClient/Program.cs).
378381

379382
### Creating a client object
380383

@@ -496,30 +499,28 @@ using (var call = client.RouteChat())
496499

497500
### Build the client and server:
498501

499-
#### Using Visual Studio
502+
#### Using Visual Studio (or Visual Studio For Mac)
500503

501-
- Open the solution `examples/csharp/route_guide/RouteGuide.sln` and select **Build**.
504+
- Open the solution `examples/csharp/RouteGuide/RouteGuide.sln` and select **Build**.
502505

503-
#### Using Xamarin Studio or Monodevelop on OS X or Linux
506+
#### Using "dotnet" command line tool
504507

505-
- See the [quickstart](../../quickstart/csharp.html) for instructions on downloading gRPC
506-
nuget dependencies and building the solution with these IDEs.
508+
- Run `dotnet build RouteGuide.sln` from the `examples/csharp/RouteGuide` directory.
509+
See the [quickstart](../../quickstart/csharp.html) for additional instructions on building
510+
the gRPC example with the `dotnet` command line tool.
507511

508512
Run the server, which will listen on port 50052:
509513

510514
```
511-
> cd RouteGuideServer/bin/Debug
512-
> RouteGuideServer.exe
515+
> cd RouteGuideServer/bin/Debug/netcoreapp2.1
516+
> dotnet exec RouteGuideServer.dll
513517
```
514518

515519
Run the client (in a different terminal):
516520

517521
```
518-
> cd RouteGuideClient/bin/Debug
519-
> RouteGuideClient.exe
522+
> cd RouteGuideClient/bin/Debug/netcoreapp2.1
523+
> dotnet exec RouteGuideClient.dll
520524
```
521525

522526
You can also run the server and client directly from Visual Studio.
523-
524-
On Linux or Mac, use `mono RouteGuideServer.exe` and `mono RouteGuideClient.exe`
525-
to run the server and client.

0 commit comments

Comments
 (0)