
上QQ阅读APP看书,第一时间看更新
How to do it...
- Open Visual Studio 2017.
- Click File | New | Project and, in the New Project template dialog box, select Visual Studio Solutions under the Other Project Types node in the left-hand pane, and select Blank Solution in the right-hand pane:

- In the Name: textbox, type a name for your application. In this case, type Chapter1.Library. Select a preferred location under the Location: drop-down list or click the Browse... button and select a location. Leave the defaults as they are:

- Now you have a blank solution. Let's add a C# class library project to the solution. Click Project | Add New Item... or you can right-click on the Chapter1.Library solution label in the Solution Explorer, and select Add | New Project....
- In the Add New Project template dialog box, select Visual C# in the left side, pane and select Class Library (.NET Framework) in the right-hand pane:

- In the Name: textbox, type a name for your class library. In this case, type Chapter1.Library.HelloLib as the name of the project. Leave the current location under the Location: drop-down list and click OK to create the project:

- Now we have a brand new .NET Framework-based class library. In the Solution Explorer (press Ctrl + Alt + L if you don't see the Solution Explorer), the default structure should look like this:

- Now we have a default template for a class library project. Let's rename Class1.cs to something more meaningful. Rename it HelloWorld.cs. You can simply soft click on the label of the file in the Solution Explorer and type the new name (or click on the filename label and press F2). Click Yes in the confirmation box to confirm the renaming.
- Type the following code snippet in the HelloWorld class body:
public string SayHello(string name)
{
return $"Hello {name}, congratulations !!!,
this message is from the class library you created.";
}
- Let's build our code to check that everything is fine. Click Build | Build Solution, or press Ctrl + Shift + B, and the solution should build successfully. Let's test our class library in the next recipe.
- Click File | Save All, or press Ctrl + Shift + S, to save the solution and the class library project.