Skip to content

Commit 1df4c01

Browse files
committed
Update hello world fully to .NET 5.0
1 parent cec0520 commit 1df4c01

File tree

13 files changed

+52
-79
lines changed

13 files changed

+52
-79
lines changed

docfx_project/articles/tutorials/connect-nightly/index.md

Lines changed: 13 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ title: "Connect to nightly builds"
88
99

1010
# Connect to the nightly builds and use it in your project
11-
Connect to the latest version of Gmod.NET to use the newest features and work with the `.NET 5.0`.
11+
Connect to the latest version of Gmod.NET to use the newest features (`main` for `.NET 5.0`) or to test the `.NET 6.0 Preview` version on the `net6` branch.
1212

1313
We'll create a project to test if we've got the latest version.
1414

@@ -18,30 +18,21 @@ We'll create a project to test if we've got the latest version.
1818
* Ensure at least these individual components are installed:
1919
* .NET SDK
2020
* NuGet Package manager
21+
* `.NET 5.0` if you want to use the nightly `main` branch
22+
* The `.NET 6.0 Preview` [(link)](https://dotnet.microsoft.com/download/dotnet/6.0) if you want to use the nightly `net6` branch.
2123
* Windows 10 (For more see the [Visual Studio requirements](https://docs.microsoft.com/en-us/visualstudio/releases/2019/system-requirements#visual-studio-2019-system-requirements))
2224
* An internet connection
2325

24-
## Preparations
25-
26-
The current nightly builds require at least .NET 5.0.
27-
28-
**Install the `.NET 5.0 Runtime` component for Visual Studio 2019:**
29-
* Start the Visual Studio Installer through `[Start Menu] > [All Programs] > Visual Studio 2019 > Visual Studio Installer`
30-
* Modify your installation:
31-
![Modify installation](images/vs-installer-modify.png)
32-
* Go to Individual Components
33-
* Search for `.NET 5.0 Runtime`
34-
![.NET 5.0 component](images/vs-installer-net-5.png)
35-
* Click Modify in the bottom right
36-
37-
## Start a .NET 5.0 project
26+
## Start a .NET project
3827

3928
To test if we've got a working nightly version we'll create a test project.
4029

4130
1. Start Visual Studio 2019
4231
2. Create a new project and solution
43-
3. When asked to pick a framework choose `.NET 5.0`
44-
![.NET 5.0 project](images/project-net-5.png)
32+
3. When asked to pick a framework choose:
33+
* For the `net6` branches choose `.NET 6.0`
34+
* In our case we'll go for the `main` branch which is built for `.NET 5.0`
35+
![.NET 5.0 project](../hello-world/images/project-net-5.png)
4536

4637
## Adding the nightly builds to NuGet
4738

@@ -63,8 +54,6 @@ To test if we've got a working nightly version we'll create a test project.
6354
10. Ensure *Include prerelease* is selected
6455
11. Click GmodNET.API and install the version you'd like to use.
6556

66-
**Currently the .main branch uses .NET 5.0.**
67-
6857
## Test installation
6958

7059
1. Implement the IModule interface. (Add `: IModule` behind the class name)
@@ -75,9 +64,10 @@ To test if we've got a working nightly version we'll create a test project.
7564

7665
## Install the module in Garry's Mod
7766

67+
To use our module we need to install the same built version of Gmod.NET to Garry's Mod.
68+
7869
1. Go to [https://nightly.gmodnet.xyz/](https://nightly.gmodnet.xyz/)
79-
2. Download the same version you selected in NuGet earlier
80-
3. Install it in Garry's Mod
81-
**Note:** Unlike the 0.6.0 release, the latest nightly builds need no Lua files. You should only require("dotnet") somewhere you want to use it.
70+
2. Download the pre-built version of Gmod.NET that you selected in NuGet earlier
71+
3. Install it in Garry's Mod `lua/bin`
8272

83-
**You can now install your module and load it in Garry's Mod**
73+
**You can now install your own .NET modules to `lua/bin/Modules` and load them in Garry's Mod**

docfx_project/articles/tutorials/hello-world-detailed/index.md

Lines changed: 23 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -57,15 +57,10 @@ Follow [the instructions in the README](https://github.com/GmodNET/GmodDotNet#in
5757
3. Confirm your `garrysmod/lua/bin/` directory contains at least these files and folders:
5858
![binary folder structure](../hello-world/images/bin-folder-structure.png)
5959

60-
4. You have copied `gmod-dot-net-lua-server.X.Y.Z.lua` to `garrysmod/lua/autorun/server/`
61-
62-
5. You have copied `gmod-dot-net-lua-client.X.Y.Z.lua` to `garrysmod/lua/autorun/client/`
63-
64-
6560

6661
## Tutorial Overview
6762

68-
In this tutorial we'll take you through the process of creating a simple 'Hello World!' module. It will simply print 'Hello World!' to the console. The great thing about that is that you will have learnt the basics of creating a Gmod.NET module. We'll use **Visual Studio 2019**, **C#** (pronounce: C-Sharp) and the **.NET Core** (pronounce: dot net core) framework.
63+
In this tutorial we'll take you through the process of creating a simple 'Hello World!' module. It will simply print 'Hello World!' to the console. The great thing about that is that you will have learnt the basics of creating a Gmod.NET module. We'll use **Visual Studio 2019**, **C#** (pronounce: C-Sharp) and the **.NET 5.0** (pronounce: dot net 5) framework.
6964

7065
These are the subjects we will be discussing:
7166

@@ -111,9 +106,7 @@ Let's make sure we really have ALL required components.
111106
* **.NET SDK**
112107
* **NuGet Package manager**
113108
* **C# and Visual Basic**
114-
* **.NET Core 3.1 Runtime (LTS)**
115-
116-
![Install individual components](../hello-world/images/visual-studio-indiv-components.png)
109+
* **.NET 5.0 Runtime**
117110

118111
4. Now click **Install** at the bottom of the installer.
119112

@@ -160,11 +153,10 @@ The solution name is the same as the project name by default. This is fine. We'l
160153

161154
8. Click Next
162155

163-
Visual Studio now asks which framework you wish to target. Gmod.NET requires **at least .NET Core 3.1**
156+
Visual Studio now asks which framework you wish to target. Gmod.NET requires **at least .NET 5.0**
164157

165-
9. As the Target Framework choose:
166-
* If you're using a release like `0.6.0` use at least: **.NET Core 3.1 (Long-term support)**
167-
* If you're using a nightly build use at least: **.NET 5.0**
158+
9. As the Target Framework choose **.NET 5.0**
159+
![.NET 5.0 project](../hello-world/images/project-net-5.png)
168160

169161
Visual Studio will generate a Class Library (.NET Core) project for us. When it's done you will see this screen:
170162

@@ -254,7 +246,7 @@ The suggestion to add `using GmodNET.API;` added that same line of code to the t
254246

255247
**Additionally we've now got 4 new errors. Yay! Information:**
256248

257-
![next errors](../hello-world/images/next-errors.png)
249+
![next errors](../hello-world/images/interface-errors.png)
258250

259251
**IModule is an "interface". An interface forces us to add certain functionalities to our class.** IModule forces us to add functionalities explaining how the module must start and stop.
260252

@@ -300,16 +292,18 @@ If we skim the rest of the code we see (amongst a lot of other code) the words L
300292

301293
Methods sometimes get input and they sometimes return output. We can see that the Load and Unload methods don't return any output from the keyword `void` in front of the Method name.
302294

303-
We can see from the () behind the Unload method that it does not expect any arguments and therefor has no input.
295+
We can see from the `(ILua lua)` behind the Unload method that it only expects a single argument/input.
304296

305-
**Load is called when our module is loaded.** We will fill it with code in the next chapter.
297+
**Load is called by Gmod.NET when our module is loaded.** We will fill it with code in the next chapter.
306298

307-
**Unload is called when our module needs to clean up after itself.** Unload is irrelevant for our Hello World example.
299+
**Unload is called by Gmod.NET when our module needs to clean up after itself.** Unload is irrelevant for our Hello World example.
308300

309301
13. Remove `throw new NotImplementedException();` from both the Load and Unload methods:
310302

311303
![empty methods](../hello-world/images/methods-empty.png)
312304

305+
`NotImplementedException` is a runtime error that helps us programmers remember to write some code. In C# we call runtime errors `Exceptions`. The `throw` keyword helps us raise such errors.
306+
313307
**To summarize what we've learnt:**
314308

315309
* Errors help us identify problems
@@ -319,13 +313,11 @@ We can see from the () behind the Unload method that it does not expect any argu
319313
* Visual Studio can help us generate the functionalities IModule requires: implementing the IModule interface
320314
* Properties describe a class
321315
* Methods explain in what sequence code needs to be executed
322-
323-
316+
* Runtime errors in C# are called Exceptions
324317

325318
**That's it! We've setup our code and are ready to get to the main subject of today: making our module print 'Hello World!'.**
326319

327320

328-
329321
## 4. Writing module code
330322

331323
After all those instructions we finally get to the most important part of this module: actually printing 'Hello World!' to the Garry's Mod console. Hilariously this will be the shortest chapter of all.
@@ -374,7 +366,6 @@ We can see that the Load method receives a few arguments of input:
374366
* A bool is short for boolean. It can contain only `true` or `false`.
375367
* We often use booleans for yes/no or on/off questions.
376368
* This argument is true if the module was loaded serverside.
377-
* `GetILuaFromLuaStatePointer lua_extructor` - Irrelevant for beginners, ignore it for now.
378369
* `ModuleAssemblyLoadContext assembly_context` - Irrelevant for beginners, ignore it for now.
379370

380371

@@ -442,7 +433,7 @@ We've written the code to explain what our module wants to happen: *when loading
442433

443434
![entire-solution](../hello-world/images/entire-solution.png)
444435

445-
4. Inside your solution navigate to where the module was built: `<your solution location>\GmodHelloWorld\bin\Debug\netcoreapp3.1\`
436+
4. Inside your solution navigate to where the module was built: `<your solution location>\GmodHelloWorld\bin\Debug\net5.0\`
446437

447438
5. If your module built successfully you'll have the following files. We'll call these "*the built module files*".
448439

@@ -464,21 +455,25 @@ We've written the code to explain what our module wants to happen: *when loading
464455

465456

466457

467-
### Testing
458+
### Running & Testing
468459

469460
1. Start Garry's Mod
470461

471462
2. Start a singleplayer game
472463

473-
3. Check the console. Because we're loading the module in Singleplayer it's loaded clientside, our "Hello World!" message will appear in a yellow color:
464+
3. Open the Developer Console
465+
466+
4. In order to load our module execute this Lua function: `dotnet.load` for example: `lua_run dotnet.load("GmodHelloWorld")`
467+
468+
5. Check the console. Because we're loading the module on the server (using `lua_run`), our "Hello World!" message will appear in a blue color:
474469

475470
![console-output](../hello-world/images/console-output.png)
476471

477472
**🎉 Yay! Success!** We've created a .NET module for Garry's Mod.
478473

479474

480475

481-
### Testing
476+
### Making changes
482477

483478
You'll have to rebuild and reinstall the module when you make changes in C#.
484479

@@ -487,23 +482,12 @@ You'll have to rebuild and reinstall the module when you make changes in C#.
487482
![file-in-use](../hello-world/images/file-in-use.png)
488483

489484
2. Unload the module:
490-
* To unload the module use `gmod_net_unload_all` for the server
491-
* In our case we yse `gmod_net_unload_all_cl` to unload the module clientside (because we're in singleplayer)
485+
* To unload the module execute this lua function: `dotnet.unload("GmodHelloWorld")`
486+
* In our case we use `lua_run dotnet.unload("GmodHelloWorld")` to unload the module serverside (because we loaded it with `lua_run` on the server before)
492487

493488
![unload-all](../hello-world/images/unload-all.png)
494489

495490
3. Now that the module is unloaded you can overwrite it with the new files.
496-
4. Reload it with `gmod_net_load_all` or `gmod_net_load_all_cl` for server and client respectively.
497-
498-
499-
500-
501-
## 6. Recap and further reading
502-
503-
TODO: We still have to write this
504491

505-
* What is a *Visual Studio Solution* and how does it relate to a *Project*?
506-
* Where can we learn more on writing C# code?
507-
* What exactly is a *NuGet Package* and how can it help us?
508-
* Other tutorials on Gmod.NET
492+
4. Reload the module the same way we loaded it before (with `dotnet.load("GmodHelloWorld")`)
509493

15 KB
Loading
196 KB
Loading
-1.29 KB
Loading
33.7 KB
Loading
23.2 KB
Loading
-2.9 KB
Loading
Binary file not shown.

docfx_project/articles/tutorials/connect-nightly/images/project-net-5.png renamed to docfx_project/articles/tutorials/hello-world/images/project-net-5.png

File renamed without changes.

0 commit comments

Comments
 (0)