Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 24 additions & 27 deletions docs/core/tutorials/library-with-visual-studio-code.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
---
title: Create a .NET class library using Visual Studio Code
description: Learn how to create a .NET class library using Visual Studio Code.
ms.date: 09/12/2024
ms.date: 01/29/2026
---
# Tutorial: Create a .NET class library using Visual Studio Code

In this tutorial, you create a simple utility library that contains a single string-handling method.

A *class library* defines types and methods that are called by an application. If the library targets .NET Standard 2.0, it can be called by any .NET implementation (including .NET Framework) that supports .NET Standard 2.0. If the library targets .NET 9, it can be called by any application that targets .NET 9. This tutorial shows how to target .NET 9.
A *class library* defines types and methods that are called by an application. If the library targets .NET Standard 2.0, it can be called by any .NET implementation (including .NET Framework) that supports .NET Standard 2.0. If the library targets .NET 10, it can be called by any application that targets .NET 10. This tutorial shows how to target .NET 10.

When you create a class library, you can distribute it as a third-party component or as a bundled component with one or more applications.

Expand All @@ -23,33 +23,23 @@ Start by creating a .NET class library project named "StringLibrary" and an asso

1. Go to the Explorer view and select **Create .NET Project**. Alternatively, you can bring up the Command Palette using Ctrl+Shift+P (Command+Shift+P on MacOS) and then type ".NET" and find and select the .NET: New Project command.

1. After selecting the command, you'll need to choose the project template. Choose Class Library.

1. Then select the location where you would like the new project to be created.
1. Choose the project template **Class Library**.

1. Then select the location where you would like the new project to be created: Create a folder named `ClassLibraryProjects` and select it.

1. Name the project **StringLibrary**, select **Show all template options**, select **.NET 9** and select **Create Project**.

1. Name the project **StringLibrary** and select **Create Project**.
1. Name the project **StringLibrary**.

1. Press <kbd>Enter</kbd> at the prompt **Project will be created in \<path>**.
1. Select **.sln** as the solution file format.

1. Check to make sure that the library targets .NET 9. In **Explorer**, open *StringLibrary/StringLibrary.csproj*.
1. Select **Show all template options**.

The `TargetFramework` element shows that the project targets .NET 9.0.
1. Next select **.NET 10**. Then select **Create Project**.

```xml
<Project Sdk="Microsoft.NET.Sdk">
1. In the **Do you trust the authors of the files in this folder?** dialog, select **Yes, I trust the authors**. You can trust the authors because this folder only has files generated by .NET and added or modified by you.

<PropertyGroup>
<TargetFramework>net9.0</TargetFramework>
</PropertyGroup>
1. The project is created and *Class1.cs* opens.

</Project>
```

1. Open *Class1.cs* and replace the code with the following code.
1. Replace the contents of *Class1.cs* with the following code:

:::code language="csharp" source="./snippets/library-with-visual-studio/csharp/StringLibrary/Class1.cs":::

Expand All @@ -66,11 +56,9 @@ Start by creating a .NET class library project named "StringLibrary" and an asso
The terminal output looks like the following example:

```output
Microsoft (R) Build Engine version 17.8.0+b89cb5fde for .NET
Copyright (C) Microsoft Corporation. All rights reserved.
Determining projects to restore...
All projects are up-to-date for restore.
StringLibrary -> C:\Projects\ClassLibraryProjects\StringLibrary\bin\Debug\net9.0\StringLibrary.dll
StringLibrary -> C:\Projects\ClassLibraryProjects\StringLibrary\bin\Debug\net10.0\StringLibrary.dll
Build succeeded.
0 Warning(s)
0 Error(s)
Expand All @@ -83,9 +71,9 @@ Add a console application that uses the class library. The app will prompt the u

1. Right-click the solution in **Solution Explorer** and select **New Project**, or in the Command Palette select **.NET: New Project**.

1. Select Console app.
1. Select **Console App**.

1. Give it the name **ShowCase**, select the default location and select **Create Project**.
1. Give it the name **ShowCase**, select the default directory and select **Create Project**.

1. Open *ShowCase/Program.cs* and replace all of the code with the following code.

Expand All @@ -105,13 +93,22 @@ Initially, the new console app project doesn't have access to the class library.

1. Select StringLibrary.

> [!TIP]
> Alternatively, add the following to *ShowCase.csproj*:
>
> ```xml
> <ItemGroup>
> <ProjectReference Include="..\StringLibrary\StringLibrary.csproj" />
> </ItemGroup>
> ```

## Run the app

1. Select **Run** > **Run without debugging**.
1. Use the top menu bar to select **Run** > **Run without debugging**.

1. Select **C#**.

1. Select **ShowCase**.
1. Select **C#: ShowCase**.

If you get an error that says no C# program is loaded, close the folder that you have open, and open the `ShowCase` folder. Then try running the app again.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<RootNamespace></RootNamespace>
<TargetFramework>netstandard2.0</TargetFramework>
<TargetFramework>net10.0</TargetFramework>
</PropertyGroup>

</Project>