Добавил:
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
strauss_d_getting_started_with_visual_studio_2022_learning_a.pdf
Скачиваний:
123
Добавлен:
26.06.2023
Размер:
17.04 Mб
Скачать

Chapter 2 Working with Visual Studio 2022

This is the power that NuGet provides. You, as a developer, need to consider using it if you do not already do so.

Hosting Your Own NuGet Feeds

Sometimes, you might need to create and share packages only available to a limited audience. Think of the developers inside your organization. Perhaps the company you work with does not allow the sharing of code with a public audience. Perhaps the code you want to share is specific to your organization and unsuitable for a public audience. Whatever the situation, NuGet supports private feeds in the following ways:

•\

Local feed – On a network file share.

•\

NuGet.Server – On a local HTTP server.

•\

NuGet gallery – Hosted on an Internet server using the NuGet Gallery

 

project, you can manage users and features to allow searching and

 

exploring available packages similar to nuget.org.

Other NuGet hosting solutions support the creation of remote private feeds. Some of these are

•\

Azure Artifacts

•\

MyGet – https://myget.org/

•\

ProGet – https://inedo.com/proget

•\

TeamCity – www.jetbrains.com/teamcity/

For a complete list of NuGet hosting products and for more information on creating your NuGet feeds, have a look at the following link on Microsoft Docs: https://docs. microsoft.com/en-us/nuget/hosting-packages/overview.

Managing nmp Packages

In a similar vein to NuGet, nmp allows you to install and manage packages that can be used in Node.js as well as ASP.NET Core apps. If you are unfamiliar with nmp, you can read more about it by looking at the nmp documentation at https://docs.npmjs.com/.

118

Chapter 2 Working with Visual Studio 2022

With Visual Studio 2022, the nmp package manager is available for CLI-based projects. This allows you to download nmp modules similar to the way you would download NuGet packages in an ASP.NET Core project.

The package manager can be opened by right-clicking the nmp node in the Solution Explorer as seen in Figure 2-40.

Figure 2-40.  Installing new nmp packages

You can now search for nmp packages and then select one to install as seen in Figure 2-41. Clicking the Install Package button installs the package.

119

Chapter 2 Working with Visual Studio 2022

Figure 2-41.  Searching for nmp packages

Creating Project Templates

Sometimes, developers create class libraries and code that they need to use repeatedly across various new projects. What developers end up doing is copying and pasting code into new class libraries. However, there is an easier way to create projects that reuse code you have previously written.

Enter Visual Studio project templates. These templates allow developers to speed up their development by including previously written code in new projects. Let’s assume we have created a project called ProjectUtilities (as seen in Figure 2-42) that contains various helper methods.

120

Chapter 2 Working with Visual Studio 2022

Figure 2-42.  ProjectUtilities project

We will need to use this Class Library over and over in various projects. So I have decided to create a project template from it.

From the Project menu, click Export Template, as seen in Figure 2-43.

121

Chapter 2 Working with Visual Studio 2022

Figure 2-43.  Export template

The Export Template Wizard is displayed as seen in Figure 2-44. This allows you to specify which template you need to create. The options are creating a Project template or an Item template. A Project template is what we are after in this example, but you can also create an Item template. This allows you to add the code via the Add New Item dialog box in Visual Studio.

122

Chapter 2 Working with Visual Studio 2022

Figure 2-44.  Export Template Wizard

For this example, however, we keep the Project template option selected and select the project to export from the drop-down list. This drop-down lists all the projects in my Visual Studio solution. Select the ProjectUtilities project, and click the Next button.

The following window is where one can enter various template options (Figure 2-45). Here, I can give the template a proper name and description, specify the icon and preview images, and select to import the template into Visual Studio automatically. Click Finish to create the new project template.

123

Chapter 2 Working with Visual Studio 2022

Figure 2-45.  Add template options

The next time I create a new project in Visual Studio, I can search for my Custom project template (Figure 2-46) and have it available for me to select.

124