Skip to content

Commit 427223b

Browse files
author
Ron Petrusha
authored
Revised class library getting started topics for .NET Core 2.0 (dotnet#2837)
* Some changes for library getting started topics * Revised testing libraries topic * Revised consuming library topic * Changed source code filename * Fixed build break * Incorporated review comments, fixed formatting * fixed broken link * Fixed additional broken links.
1 parent 50557d3 commit 427223b

File tree

47 files changed

+300
-45
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+300
-45
lines changed

docs/csharp/getting-started/consuming-library-with-visual-studio.md renamed to docs/core/tutorials/consuming-library-with-visual-studio.md

Lines changed: 38 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ description: Learn how to call the members in a class library with Visual Studio
44
keywords: .NET Core, .NET Core class library, .NET Standard, .NET Standard class library distribution
55
author: BillWagner
66
ms.author: wiwang
7-
ms.date: 04/17/2017
7+
ms.date: 08/07/2017
88
ms.topic: article
99
ms.prod: .net
1010
ms.technology: devlang-csharp
@@ -14,7 +14,7 @@ ms.assetid: d7b94076-1108-4174-94e7-a18f00072bb7
1414

1515
# Consuming a class library with .NET Core in Visual Studio 2017
1616

17-
Once you've followed the steps in [Building a C# class library with .NET Core in Visual Studio 2017](./library-with-visual-studio.md) and [Testing a class library with .NET Core in Visual Studio 2017](testing-library-with-visual-studio.md) to build and test your class library and you've built a Release version of the library, the next step is to make it available to callers. You can do this in two ways:
17+
Once you've created a class library by following the steps in [Building a C# class library with .NET Core in Visual Studio 2017](./library-with-visual-studio.md) or [Building a Visual Basic class library with .NET Core in Visual Studio 2017](vb-library-with-visual-studio.md), tested it in [Testing a class library with .NET Core in Visual Studio 2017](testing-library-with-visual-studio.md), and built a Release version of the library, the next step is to make it available to callers. You can do this in two ways:
1818

1919
* If the library will be used by a single solution (for example, if it's a component in a single large application), you can include it as a project in your solution.
2020

@@ -24,13 +24,14 @@ Once you've followed the steps in [Building a C# class library with .NET Core in
2424

2525
Just as you included unit tests in the same solution as your class library, you can include your application as part of that solution. For example, you can use your class library in a console application that prompts the user to enter a string and reports whether its first character is uppercase:
2626

27+
# [C#](#tab/csharp)
2728
1. Open the `ClassLibraryProjects` solution you created in the [Building a C# Class Library with .NET Core in Visual Studio 2017](./library-with-visual-studio.md) topic. In **Solution Explorer**, right-click the **ClassLibraryProjects** solution and select **Add** > **New Project** from the context menu.
2829

29-
1. In the **Add New Project** dialog, select the **.NET Core** node followed by the **Console App (.NET Core)** project template. In the **Name** text box, type "ShowCase", and select the **OK** button.
30+
1. In the **Add New Project** dialog, expand the **Visual C#** node and select the **.NET Core** node followed by the **Console App (.NET Core)** project template. In the **Name** text box, type "ShowCase", and select the **OK** button.
3031

3132
![Add New Project dialog](./media/consuming-library-with-visual-studio/addnewproject.png)
3233

33-
1. In **Solution Explorer**, right-click the **ShowCase** project and select **Set as StartUp Project** in the context menu.
34+
1. In **Solution Explorer**, right-click the **ShowCase** project and select **Set as StartUp Project** in the context menu.
3435

3536
![ShowCase context menu](./media/consuming-library-with-visual-studio/setstartupproject.png)
3637

@@ -44,7 +45,7 @@ Just as you included unit tests in the same solution as your class library, you
4445

4546
1. In the code window for the *Program.cs* file, replace all of the code with the following code:
4647

47-
[!CODE-csharp[UsingClassLib#1](../../../samples/snippets/csharp/getting_started/with_visual_studio_2017/showcase.cs#1)]
48+
[!CODE-csharp[UsingClassLib#1](../../../samples/snippets/csharp/getting_started/with_visual_studio_2017/showcase.cs)]
4849

4950
The code uses the [Console.WindowHeight](xref:System.Console.WindowHeight) property to determine the number of rows in the console window. Whenever the [Console.CursorTop](xref:System.Console.CursorTop) property is greater than or equal to the number of rows in the console window, the code clears the console window and displays a message to the user.
5051

@@ -53,8 +54,39 @@ Just as you included unit tests in the same solution as your class library, you
5354
1. If necessary, change the toolbar to compile the **Debug** release of the `ShowCase` project. Compile and run the program by selecting the green arrow on the **ShowCase** button.
5455

5556
![Image](./media/consuming-library-with-visual-studio/toolbar.png)
57+
# [Visual Basic](#tab/visual-basic)
58+
1. Open the `ClassLibraryProjects` solution you created in the [Building a class Library with Visual Basic and .NET Core in Visual Studio 2017](vb-library-with-visual-studio.md) topic. In **Solution Explorer**, right-click the **ClassLibraryProjects** solution and select **Add** > **New Project** from the context menu.
5659

57-
You can debug and publish the application that uses this library by following the steps in [Debugging your C# Hello World application with Visual Studio 2017](debugging-with-visual-studio.md) and [Publishing your Hello World Application with Visual Studio 2017](publishing-with-visual-studio.md).
60+
1. In the **Add New Project** dialog, expand the **Visual Basic** node and select the **.NET Core** node followed by the **Console App (.NET Core)** project template. In the **Name** text box, type "ShowCase", and select the **OK** button.
61+
62+
![Add New Project dialog](./media/consuming-library-with-visual-studio/vb-addnewproject.png)
63+
64+
1. In **Solution Explorer**, right-click the **ShowCase** project and select **Set as StartUp Project** in the context menu.
65+
66+
![ShowCase context menu](./media/consuming-library-with-visual-studio/setstartupproject.png)
67+
68+
1. Initially, your project doesn't have access to your class library. To allow it to call methods in your class library, you create a reference to the class library. In **Solution Explorer**, right-click the `ShowCase` project's **Dependencies** node and select **Add Reference**.
69+
70+
![ShowCase Dependencies context menu](./media/consuming-library-with-visual-studio/addreference.png)
71+
72+
1. In the **Reference Manager** dialog, select **StringLibrary**, your class library project, and select the **OK** button.
73+
74+
![Reference manager](./media/consuming-library-with-visual-studio/referencemanager.png)
75+
76+
1. In the code window for the *Program.vb* file, replace all of the code with the following code:
77+
78+
[!CODE-vb[UsingClassLib#1](../../../samples/snippets/core/tutorials/vb-library-with-visual-studio/showcase.vb)]
79+
80+
The code uses the [Console.WindowHeight](xref:System.Console.WindowHeight) property to determine the number of rows in the console window. Whenever the [Console.CursorTop](xref:System.Console.CursorTop) property is greater than or equal to the number of rows in the console window, the code clears the console window and displays a message to the user.
81+
82+
The program prompts the user to enter a string. It indicates whether the string starts with an uppercase character. If the user presses the Enter key without entering a string, the application terminates, and the console window closes.
83+
84+
1. If necessary, change the toolbar to compile the **Debug** release of the `ShowCase` project. Compile and run the program by selecting the green arrow on the **ShowCase** button.
85+
86+
![Image](./media/consuming-library-with-visual-studio/toolbar.png)
87+
---
88+
89+
You can debug and publish the application that uses this library by following the steps in [Debugging your Hello World application with Visual Studio 2017](debugging-with-visual-studio.md) and [Publishing your Hello World Application with Visual Studio 2017](publishing-with-visual-studio.md).
5890

5991
## Distributing the library in a NuGet package
6092

docs/core/tutorials/index.md

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,10 @@ The following tutorials are available for learning about .NET Core.
2020
- [Building a C# Hello World application](../../csharp/getting-started/with-visual-studio.md)
2121
- [Debugging your C# Hello World application](../../csharp/getting-started/debugging-with-visual-studio.md)
2222
- [Publishing your C# Hello World application](../../csharp/getting-started/publishing-with-visual-studio.md)
23-
- [Building a C# class library](../../csharp/getting-started/library-with-visual-studio.md)
24-
- [Testing a C# class library](../../csharp/getting-started/testing-library-with-visual-studio.md)
25-
- [Consuming a C# class library with .NET Core](../../csharp/getting-started/consuming-library-with-visual-studio.md)
23+
- [Building a C# class library](../../core/tutorials/library-with-visual-studio.md)
24+
- [Building a class library with Visual Basic](../../core/tutorials/vb-library-with-visual-studio.md)
25+
- [Testing a class library](../../core/tutorials/testing-library-with-visual-studio.md)
26+
- [Consuming a class library](../../core/tutorials/consuming-library-with-visual-studio.md)
2627
- [Building a complete C# .NET Core solution on Windows](using-on-windows-full-solution.md)
2728
- [NoSQL tutorial: Build a DocumentDB C# console application on .NET Core](/azure/documentdb/documentdb-dotnetcore-get-started)
2829

@@ -40,7 +41,7 @@ The following tutorials are available for learning about .NET Core.
4041

4142
- [Getting started with .NET Core on Windows/Linux/macOS using the .NET Core CLI tools](using-with-xplat-cli.md)
4243
- [Organizing and testing projects with the .NET Core CLI tools](testing-with-cli.md)
43-
- [Getting started with F#](../../fsharp/tutorials/getting-started/getting-started-command-line.md)
44+
- [Get started with F#](../../fsharp/get-started/get-started-command-line.md)
4445

4546
## Other
4647
- [Unit Testing in .NET Core using dotnet test](../testing/unit-testing-with-dotnet-test.md)
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,24 @@
11
---
2-
title: Building a class library with C# and .NET Core in Visual Studio 2017
3-
description: Learn how to build a class library written in C# using Visual Studio 2017
2+
title: Building a .NET Standard class library with C# and .NET Core in Visual Studio 2017
3+
description: Learn how to create a .NET Standard class library written in C# using Visual Studio 2017.
44
keywords: .NET Core, .NET Standard class library, Visual Studio 2017
55
author: BillWagner
66
ms.author: wiwagn
7-
ms.date: 04/17/2017
7+
ms.date: 08/07/2017
88
ms.topic: article
99
ms.prod: .net-core
1010
ms.technology: devlang-csharp
1111
ms.devlang: csharp
1212
ms.assetid: c849ca26-6a25-4d35-9544-f343af88e0e7
1313
---
14-
1514
# Building a class library with C# and .NET Core in Visual Studio 2017
1615

17-
A *class library* defines types and methods that are called by an application. A class library developed using .NET Core supports the .NET Standard, which allows your library to be called by any .NET implementation that supports that version of the .NET Standard. When you finish your class library, you can decide whether you want to distribute it as a third-party component or whether you want to include it as a bundled component with one or more applications.
16+
A *class library* defines types and methods that are called by an application. A class library that targets the .NET Standard 2.0 allows your library to be called by any .NET implementation that supports that version of the .NET Standard. When you finish your class library, you can decide whether you want to distribute it as a third-party component or whether you want to include it as a bundled component with one or more applications.
1817

1918
> [!NOTE]
2019
> For a list of the .NET Standard versions and the platforms they support, see [.NET Standard](../../standard/net-standard.md).
2120
22-
In this topic, you'll create a simple utility library that contains a single string-handling method. You'll implement it as an [extension method](../../csharp/programming-guide/classes-and-structs/extension-methods.md) so that you can call it as if it were a member of the @System.String class.
21+
In this topic, you'll create a simple utility library that contains a single string-handling method. You'll implement it as an [extension method](../../csharp/programming-guide/classes-and-structs/extension-methods.md) so that you can call it as if it were a member of the <xref:System.String> class.
2322

2423
## Creating a class library solution
2524

@@ -37,22 +36,28 @@ Create your class library project:
3736

3837
1. In **Solution Explorer**, right-click on the **ClassLibraryProjects** solution file and from the context menu, select **Add** > **New Project**.
3938

40-
1. In the **Add New Project** dialog, select the **.NET Core** node followed by the **Class Library (.NET Core)** project template. In the **Name** text box, enter "StringLibrary" as the name of the project. Select **OK** to create the class library project.
39+
1. In the **Add New Project** dialog, expand the **Visual C#** node, then select the **.NET Standard** node followed by the **Class Library (.NET Standard)** project template. In the **Name** text box, enter "StringLibrary" as the name of the project. Select **OK** to create the class library project.
4140

4241
![Add New Project dialog](./media/library-with-visual-studio/libproject.png)
4342

43+
The code window then opens in the Visual Studio development environment.
44+
4445
![Visual Studio application window showing the default class library template code](./media/library-with-visual-studio/stringlibrary.png)
4546

47+
1. Check to make sure that our library targets the correct version of the .NET Standard. Right-click on the library project in the **Solution Explorer** windows, then select **Properties**. The **Target Framework** text box shows that we're targeting .NET Standard 2.0.
48+
49+
![Project properties for the class library](./media/library-with-visual-studio/properties.png)
50+
4651
1. Replace the code in the code window with the following code and save the file:
4752

48-
[!CODE-csharp[ClassLib#1](../../../samples/snippets/csharp/getting_started/with_visual_studio_2017/classlib.cs#1)]
53+
[!CODE-csharp[ClassLib#1](../../../samples/snippets/csharp/getting_started/with_visual_studio_2017/classlib.cs)]
4954

50-
The class library, `UtilityLibraries.StringLibrary`, contains a method named `StartsWithUpper`, which returns a @System.Boolean value that indicates whether the current string instance begins with an uppercase character. The Unicode standard distinguishes uppercase characters from lowercase characters. In .NET Core, the [`Char.IsUpper`](xref:System.Char.IsUpper(System.Char)) method returns `true` if a character is uppercase.
55+
The class library, `UtilityLibraries.StringLibrary`, contains a method named `StartsWithUpper`, which returns a <xref:System.Boolean> value that indicates whether the current string instance begins with an uppercase character. The Unicode standard distinguishes uppercase characters from lowercase characters. The <xref:System.Char.IsUpper(System.Char)?displayProperty=fullName> method returns `true` if a character is uppercase.
5156

5257
1. On the menu bar, select **Build** > **Build Solution**. The project should compile without error.
5358

5459
![Output pane showing that the build succeeded](./media/library-with-visual-studio/buildsucceeds.png)
5560

5661
## Next step
5762

58-
You've successfully built the library. Because you haven't called any of its methods, you don't know whether it works as expected. The next step in developing your library is to test it by using a [C# Unit Test Project](testing-library-with-visual-studio.md).
63+
You've successfully built the library. Because you haven't called any of its methods, you don't know whether it works as expected. The next step in developing your library is to test it by using a [Unit Test Project](testing-library-with-visual-studio.md).
Loading
Loading
Loading
Loading
Loading
Loading
Loading
Loading
Loading
Binary file not shown.
Loading
Loading

0 commit comments

Comments
 (0)