Skip to content

Latest commit

 

History

History
209 lines (127 loc) · 8.9 KB

get-started-artifacts-ai.md

File metadata and controls

209 lines (127 loc) · 8.9 KB
title description ms.service ms.topic ms.author author ms.date ms.collection monikerRange
Publish a package to an Azure Artifacts feed - Copilot
Learn how to publish your first package to an Azure Artifacts feed.
azure-devops-artifacts
quickstart
rabououn
ramiMSFT
06/21/2024
ce-skilling-ai-copilot
>= azure-devops-2020

Publish a package to an Azure Artifacts feed

Azure Artifacts enables developers to efficiently manage all their dependencies from a single feed. Feeds in Azure Artifacts serve as organizational repositories for storing, managing, and sharing your packages within your team, across organizations, or publicly on the internet. Azure Artifacts feeds support a wide range of package types, including NuGet, npm, Python, Maven, Cargo, and Universal Packages.

This article walks you through the process of publishing your first package to an Azure Artifacts feed. You also have the option to use GitHub Copilot to streamline this process and explore the capabilities of the GitHub Copilot Chat in Visual Studio Code.

Prerequisites

Create a feed

::: moniker range="azure-devops"

  1. Sign in to your Azure DevOps organization, and then navigate to your project.

  2. Select Artifacts, and then select Create Feed.

  3. Provide a descriptive Name for your feed and set its Visibility (who can view packages in your feed). Define the Scope of your feed, and if you want to include packages from public sources, check the Upstream sources checkbox.

  4. Select Create when you're done.

    :::image type="content" source="media/create-new-feed-azure-devops.png" alt-text="Screenshot that shows how to create a new feed in Azure DevOps Services.":::

::: moniker-end

::: moniker range="azure-devops-2022 || azure-devops-2020"

  1. Sign in to your Azure DevOps server, and then navigate to your project.

  2. Select Artifacts, and then select Create Feed.

  3. Provide a descriptive Name for your feed and set its Visibility (who can view packages in your feed). Define the Scope of your feed, and if you want to include packages from public sources, check the Upstream sources checkbox.

::: moniker-end

::: moniker range="azure-devops-2022"

  1. Select Create when you're done.

    :::image type="content" source="media/create-new-feed-server-2022.png" alt-text="Screenshot that shows how to create a new feed in Azure DevOps Server 2022.":::

::: moniker-end

::: moniker range="azure-devops-2020"

  1. Select Create when you're done.

    :::image type="content" source="media/create-new-feed-server-2020.png" alt-text="Screenshot that shows how to create a new feed in Azure DevOps Server 2020.":::

::: moniker-end

Prepare the code

Follow these steps to create a basic Class Library project from the command line, set up your package's metadata, and generate a NuGet package:

  1. On your local machine, create a new folder and give it a name.

  2. Open a command prompt window and navigate to the folder you created.

  3. Run the following command to create a new Class Library project:

    dotnet new classlib
    
  4. Open your csproj file and add your package metadata within the <PropertyGroup> tag. Your file structure should resemble the following:

    <Project Sdk="Microsoft.NET.Sdk">
    
      <PropertyGroup>
        <TargetFramework>net8.0</TargetFramework>
        <RootNamespace>demo_class_library</RootNamespace>
        <ImplicitUsings>enable</ImplicitUsings>
        <Nullable>enable</Nullable>
    
        <PackageId>YOUR_PACKAGE_NAME</PackageId>
        <Version>YOUR_PACKAGE_VERSION</Version>
        <Authors>YOUR_NAME</Authors>
        <Company>YOUR_COMPANY</Company>
    
      </PropertyGroup>
    
    </Project>
  5. Run the following command to package your project and generate a .nupkg artifact. your NuGet package is generated in the bin\release directory.

    dotnet pack
    

Before publishing a package to the feed you created earlier, you must first pack your project and prepare it for publishing.

The following example walks you through using GitHub Copilot to create a sample .NET Core class library and generate a NuGet package from the command line. You can also use GitHub Copilot to generate other types of projects, such as npm or Python projects.

  1. Open Visual Studio Code and select the chat icon from the left navigation panel to open the GitHub Copilot Chat.

  2. In the prompt box. ask GitHub copilot: "How do I create a .NET Core project and package it as a NuGet package?". GitHub Copilot's response might be something similar to the following:

    :::image type="content" source="media/create-project-github-copilot-response.png" alt-text="A screenshot that shows a response from GitHub Copilot Chat.":::

  3. Follow the provided steps to generate your project, define your package ID and version, and pack your project.

You can also ask GitHub Copilot to explain your project structure using the @workspace command, which lets you interact with the files and folders in your current workspace.

@workspace explain my app structure

:::image type="content" source="media/github-copilot-app-structure.png" alt-text="A screenshot that shows GitHub Copilot explaining workspace app structure.":::

Another useful method to understand new source code is to ask GitHub Copilot how specific files are related within the project. For example, you can ask how the csproj file is related to the Class1.cs file:

#file:artifacts-github-copilot.csproj #file:Class1.cs how are these files related

:::image type="content" source="media/github-copilot-csproj-class-relation.png" alt-text="A screenshot that shows GitHub Copilot response in Visual Studio Code.":::


Connect to a feed

::: moniker range="azure-devops"

  1. Select Artifacts and then select your feed from the dropdown menu.

  2. Select Connect to feed, and then select dotnet from the NuGet section.

  3. Follow the instructions in the Project setup to set up your nuget.config file. The structure of your file should look similar to this:

    • Project-scoped feed:

      <?xml version="1.0" encoding="utf-8"?>
      <configuration>
        <packageSources>
          <clear />
          <add key="<FEED_NAME>" value="https://pkgs.dev.azure.com/<ORGANIZATION_NAME>/<PROJECT_NAME>/_packaging/<FEED_NAME>/nuget/v3/index.json" />
        </packageSources>
      </configuration>
    • Organization-scoped feed:

      <?xml version="1.0" encoding="utf-8"?>
      <configuration>
        <packageSources>
          <clear />
          <add key="<FEED_NAME>" value="https://pkgs.dev.azure.com/<ORGANIZATION_NAME>/_packaging/<FEED_NAME>/nuget/v3/index.json" />
        </packageSources>
      </configuration>

::: moniker-end

::: moniker range="azure-devops-2020 || azure-devops-2022"

  1. Sign in to your Azure DevOps collection, and then navigate to your project.

  2. Select Artifacts, and then select your feed from the dropdown menu.

  3. Select Connect to Feed, and then select dotnet from the left navigation pane.

  4. Follow the instructions in the Project setup section to configure your nuget.config file and connect to your feed.

    :::image type="content" source="media/connect-to-feed-dotnet-server-2020-and-2022.png" alt-text="A screenshot that shows how to connect to a feed with dotnet in Azure DevOps Server 2020 and 2022.":::

::: moniker-end

Tip

You can ask GitHub Copilot, "how to add a new package source to an existing nuget.config file". Copilot will guide you through using the nuget sources Add command to add your new feed source URL to your nuget.config file.

Publish packages

Run the following command from your project directory to publish your package. The ApiKey is required, but you can use any string value when publishing to an Azure Artifacts feed.

dotnet nuget push --source <FEED_NAME> --api-key az <PACKAGE_PATH>

Next steps

[!div class="nextstepaction"] Monitor Artifacts storage Share packages publicly Manage permissions