diff --git a/Home.md b/Home.md index 8984cf3..d4b3f7e 100644 --- a/Home.md +++ b/Home.md @@ -69,6 +69,7 @@ Because it is port of this project, its wiki focuses on how to **use** it as a N - [NuGet Home](NuGet-Home) - [Console.Waterworks Overview](Console.Waterworks-Overview) - [Adding Console.Waterworks to Your Project](Adding-Console.Waterworks-to-Your-Project) +- [Wiring Console.Waterworks into Your Project](Wiring-Console.Waterworks-into-Your-Project) - [Overview of Command-Methods](Overview-of-Command-Methods) - [Writing Command-Methods](Writing-Command-Methods) - [Using the Help Attributes](Using-the-Help-Attributes) diff --git a/NuGet-Home.md b/NuGet-Home.md index f96fc4a..314df78 100644 --- a/NuGet-Home.md +++ b/NuGet-Home.md @@ -13,6 +13,7 @@ If you are wanting to work with the .Net Core version or use C.W. with F#, use t - [Console.Waterworks Overview](Console.Waterworks-Overview) - [Adding Console.Waterworks to Your Project](Adding-Console.Waterworks-to-Your-Project) +- [Wiring Console.Waterworks into Your Project](Wiring-Console.Waterworks-into-Your-Project) - [Overview of Command-Methods](Overview-of-Command-Methods) - [Writing Command-Methods](Writing-Command-Methods) - [Using the Help Attributes](Using-the-Help-Attributes) diff --git a/Wiring-Console.Waterworks-into-Your-Project.md b/Wiring-Console.Waterworks-into-Your-Project.md new file mode 100644 index 0000000..bdec6f5 --- /dev/null +++ b/Wiring-Console.Waterworks-into-Your-Project.md @@ -0,0 +1,93 @@ +This section assumes you have already added Console.Waterworks (C.W.) to your project. If you have not, please review the following page: + +- [Adding Console.Waterworks to Your Project](Adding-Console.Waterworks-to-Your-Project) + +Once you have added C.W. to your console project, you can begin using it. One thing to note with C.W. is how invasive it is. Because it has taken a lot out of your hands, it requires your project to look a certain way. The first thing you need to do is create a file called "ConsoleCommands.cs". When you have done that, make a note of the file/classes name-space -- you will need it in a little bit. When you have done that, head over to the `Main` method in "Program.cs" and enter the following code into it, + +```c# +// Do not forget change the ConsoleCommands name-space in Run. +var liaison = new CW_Liaison(); +liaison.Run("YOUR CONSOLECOMMADS.CS NAME-SPACE GOES HERE.", true); +``` + +After you have done that, Visual Studio should start complaining about *using statement* This means you will need to add the following line of code with your other using statements, + +```c# +// Place with your other using statements in Program.cs. +using Console.Waterworks +``` + +Overall, your Program.cs should look similar to the code below, + +```c# +using Console.Waterworks; +using System; + +namespace CW_Console // This will differ in your project. +{ + class Program + { + static void Main(string[] args) + { + var liaison = new CW_Liaison(); + liaison.Run("CW_Console", true); + } + } +} +``` + +**You might need to decorate you `Main` function with the `[STAThread]` attribute. If Visual Studio starts complaining about "single-threaded/async. problems", add the `[STAThread]` attribute above your `Main` method.That should fix the problem.** + +When that is done, head back to ConsoleCommands.cs and you can begin adding your first command-method. I will not go into too much detail about command-methods just yet. The focus of this page is to get you set-up. + +The first thing you need to do is make sure the `ConsoleCommands` class is marked as `public` and `static`. After that, enter the following method to your class, + +```c# +public static string Test() +{ + return "Test complete." +} +``` + +When you have done that, your ConsoleCommands.cs file should look similar to the following code snippet, + +```c# +using System; +using Console.Waterworks; + +namespace CW_Console // This will be different to yours. +{ + public static class ConsoleCommands + { + public static string Test() + { + return "Test complete." + } + } +} +``` + +If all has gone well, your program should run (press F5) and when you enter "Test" into the console, you should see something similar to the image below. + +![successful c.w. set-up screenshot](attachments/method-mapping.gif) + +Within the `Main` function is a method called `Run`, which takes two arguments. The first is the name-space of the `ConsoleCommands` class and the second one is a `bool`. In the example above, I have used `true` but I could have used `false` if I wanted. The reason I used `true` is because I prefer my console programs to display its assembly information when I run it. If you prefer just the prompt, change the `true` variable to `false`. If all has gone well, you should see something similar to the screenshots below. + +**Console program, displaying its assembly information.** + +![assembly info screenshot](attachments/assembly-info-screenshot.png) + +**Console program, displaying just the prompt.** + +![no assembly info screenshot](attachments/no-assembly-info-screenshot.png) + +I will not go into too much detail about changing a project's assembly information because there is already an amble amount of information on the subject. Instead, I will provide the following links to get to started: + +- [Setting Assembly Attributes](https://docs.microsoft.com/en-us/dotnet/framework/app-domains/set-assembly-attributes): This applies to the traditional and Core versions of .Net. It provides information on what resides in Assembly Information manifests and files. +- [How to Target a version of .Net](https://docs.microsoft.com/en-us/visualstudio/ide/how-to-target-a-version-of-the-dotnet-framework?view=vs-2019): This provides extra context on the Properties page in Visual Studio and how it fits the Assembly Information dialog box into it -- from a traditional .Net angle. + +The easiest way to get to the Assembly Information dialog box is as follows: + +1. In "Solution Explorer", open the *right-click* menu on the project (I.E. your console project) you want to change, and then choose "Properties". +2. In the left column of the "Properties" window, *left-click* the "Application" tab. +3. *Left-click* the button labelled "Assembly Information". diff --git a/_Sidebar.md b/_Sidebar.md index 70957bf..e35e6d3 100644 --- a/_Sidebar.md +++ b/_Sidebar.md @@ -37,6 +37,7 @@ - [NuGet Home](NuGet-Home) - [Console.Waterworks Overview](Console.Waterworks-Overview) - [Adding Console.Waterworks to Your Project](Adding-Console.Waterworks-to-Your-Project) +- [Wiring Console.Waterworks into Your Project](Wiring-Console.Waterworks-into-Your-Project) - [Overview of Command-Methods](Overview-of-Command-Methods) - [Writing Command-Methods](Writing-Command-Methods) - [Using the Help Attributes](Using-the-Help-Attributes)