在Azure Artifacts中创建一个package feed

it2023-02-13  82

 

In this part, you'll set up Azure Artifacts and create a new feed. You'll use this feed later, to store your new Models package and to consume the package in your application pipeline.

Set up Azure Artifacts

From Azure DevOps, go to the Artifacts tab, and then select + Create feed.

Name the feed Tailspin.SpaceGame.Web.Models.

Under Visibility, select Members of (your organization).

Under Upstream sources, unselect Include packages from common public sources.

The other choice, to use public sources, is if you want to create an upstream from this feed. That is, you can access your packages and packages from public package managers like NuGet or npmjs from this feed.

Select Create.

Select Connect to feed.

This has a list of links, commands, and a credential provider you could use if you wanted to run this locally by using Visual Studio. For brevity, we'll skip this part.

Andy: I've got Azure Artifacts set up. Now we need to create a pipeline that creates the new package there.

Here you'll get the team's new code for the Tailspin.SpaceGame.Web.Models project that is now separate from the Tailspin.SpaceGame.Web project. You'll create a Microsoft Azure Pipelines project for the Models project, and see the artifact in Microsoft Azure Artifacts with a version number of 1.0.0 in your feed.

What changes were made to the project?

Recall that the Space Game website is an ASP.NET Core application. It uses the Model-View-Controller (MVC) pattern to separate data from how that data is displayed in the user interface. Andy and Mara want to move the model classes to a separate library so that multiple projects can use those classes.

To do that, they create a new C# project, called Tailspin.SpaceGame.Web.Models, that contains only the model classes. At the same time, they remove the model classes from their existing project, Tailspin.SpaceGame.Web. They replace the model classes in their existing project with a reference to the Tailspin.SpaceGame.Web.Models project.

To build these projects, Andy and Mara use two pipelines, one for each project. You already have the first project and its associated Azure Pipelines configuration. Here, you'll fork the second project on GitHub, and create an Azure Pipelines configuration to build it. You'll publish the resulting package to Azure Artifacts.

Prepare Visual Studio Code

Set up Visual Studio Code so you can work with source files.

From Visual Studio Code, open the integrated terminal.Go to a directory to work from, such as your home directory (~). We suggest using the parent directory from where your mslearn-tailspin-spacegame-web project is located.

Get the source code

Get the source code for the second project from GitHub, and set up Visual Studio Code so you can work with the files.

Create a fork

The first step is to fork the mslearn-tailspin-spacegame-web-models repository so you can work with and modify the source files. Recall that Mara put the Models directory in a new project, and removed it from the web project.

To fork the mslearn-tailspin-spacegame-web-models project into your GitHub account:

From a web browser, go to GitHub  and sign in.Go to the mslearn-tailspin-spacegame-web-models  project.Select Fork.Follow the instructions to fork the repository into your account.

Clone your fork locally

To clone the mslearn-tailspin-spacegame-web-models projects to your computer:

Go to your fork of the mslearn-tailspin-spacegame-web-models project on GitHub.

Select Clone or download. Then select the button next to the URL that's shown to copy the URL to your clipboard.

From Visual Studio Code, go to the terminal window and run this git clone command. Replace the URL that's shown with the contents of your clipboard.

git clone https://github.com/your-name/mslearn-tailspin-spacegame-web-models.git

Move to the mslearn-tailspin-spacegame-web-models directory. This is the root directory of your repository.

cd mslearn-tailspin-spacegame-web-models

Open the project and examine the configuration

In Visual Studio Code, your terminal window points to the root directory of the mslearn-tailspin-spacegame-web-models project. Open the project from the file explorer so that you can view its structure and work with files.

From the File menu, select Open.

Go to the root directory of the mslearn-tailspin-spacegame-web-models project.

You see the directory and file tree in the file explorer.

Open the azure-pipelines.yml file.

You see the steps where the package is built, the version is set, and the package is added to Azure Artifacts.

This DotNetCoreCLI@2 task builds the project:

- task: DotNetCoreCLI@2 displayName: 'Build the project - $(buildConfiguration)' inputs: command: 'build' arguments: '--no-restore --configuration $(buildConfiguration)' projects: '**/*.csproj'

This DotNetCoreCLI@2 task packages the project with a version of 1.0.0:

- task: DotNetCoreCLI@2 displayName: 'Pack the project - $(buildConfiguration)' inputs: command: 'pack' projects: '**/*.csproj' arguments: '--no-build --configuration $(buildConfiguration)' versioningScheme: byPrereleaseNumber majorVersion: '1' minorVersion: '0' patchVersion: '0'

When developing your package, it's common to use the byPrereleaseNumber versioning scheme. This appends a unique pre-release suffix, such as "-CI-20190621-042647" to the end of the version number. Following this example, the complete version number would be "1.0.0-CI-20190621-042647".

This NuGetCommand@2 task pushes the package to your Tailspin.SpaceGame.Web.Models Azure Artifacts feed:

- task: NuGetCommand@2 displayName: 'Publish NuGet package' inputs: command: push publishVstsFeed: 'Space Game - web - Dependencies/Tailspin.SpaceGame.Web.Models' allowPackageConflicts: true condition: succeeded()

 

原文:

Create a package feed in Azure Artifacts

https://docs.microsoft.com/zh-cn/learn/modules/manage-build-dependencies/4-create-feed

Create a pipeline for your package

https://docs.microsoft.com/zh-cn/learn/modules/manage-build-dependencies/5-create-package-pipeline

 

 

最新回复(0)