# .NET

---

## Overview

Your private NuGet packages and public dependencies from nuget.org, all managed through one registry.

---

## Supported Clients

JFrog Fly supports .NET packages with:

- **dotnet CLI** (`dotnet nuget push`, `dotnet restore`) - The modern .NET command-line interface

- **NuGet CLI** (`nuget push`, `nuget restore`) - The standalone NuGet command-line tool

---

## Upload / Push Package

### With Fly App

Activate .NET in your Fly App to configure .NET globally with Fly. The Fly App sets the Fly registry as the default push source, so you can push without specifying `--source`:

**Using dotnet CLI:**
```bash
dotnet nuget push <package>.nupkg
```

**Using NuGet CLI:**
```bash
nuget push <package>.nupkg
```

### Manual Configuration

**1. Generate an access token** in Fly Token Management

**2. Configure .NET:**

**Using dotnet CLI:**
```bash
dotnet nuget add source https://<your-fly-subdomain>.jfrog.io/artifactory/api/nuget/nuget \
  --name Fly \
  --username <your-fly-username> \
  --password <your-fly-token> \
  --store-password-in-clear-text
```

**Using NuGet CLI:**
```bash
nuget sources add -Name Fly \
  -Source https://<your-fly-subdomain>.jfrog.io/artifactory/api/nuget/nuget \
  -Username <your-fly-username> \
  -Password <your-fly-token>
```

**3. Push package:**

**Using dotnet CLI:**
```bash
dotnet nuget push <package>.nupkg --source Fly
```

**Using NuGet CLI:**
```bash
nuget push <package>.nupkg -Source Fly
```

---

## Download / Restore Package

### With Fly App

Activate .NET in your Fly App to configure .NET globally with Fly, then restore as usual:

**Using dotnet CLI:**
```bash
dotnet restore
```

**Using NuGet CLI:**
```bash
nuget restore
```

### Manual Configuration

**1. Generate an access token** in Fly Token Management

**2. Configure .NET:**

**Using dotnet CLI:**
```bash
dotnet nuget add source https://<your-fly-subdomain>.jfrog.io/artifactory/api/nuget/nuget \
  --name Fly \
  --username <your-fly-username> \
  --password <your-fly-token> \
  --store-password-in-clear-text
```

**Using NuGet CLI:**
```bash
nuget sources add -Name Fly \
  -Source https://<your-fly-subdomain>.jfrog.io/artifactory/api/nuget/nuget \
  -Username <your-fly-username> \
  -Password <your-fly-token>
```

**3. Restore packages:**

**Using dotnet CLI:**
```bash
dotnet restore
```

**Using NuGet CLI:**
```bash
nuget restore
```

### From Public Registry

When you restore a package that isn't in your Fly Registry, JFrog Fly automatically fetches it from nuget.org and caches it for future use.

**Using dotnet CLI:**
```bash
dotnet restore
```

**Using NuGet CLI:**
```bash
nuget restore
```

---

## Upload/Download Packages with CI

To push and restore .NET packages with CI, update your GitHub Actions workflow to include the Fly action.

Simply ask your coding agent: **"Configure my workflows with Fly"** and Fly MCP will configure your GitHub Actions workflow yml file, as follows:

**1. Add permissions** (top level, after `on:`):
```yaml
permissions:
  contents: read
  id-token: write
```

**2. Add Fly Action** (after `actions/setup-dotnet`, before dotnet/nuget commands):
```yaml
- uses: jfrog/fly-action@v1              # Setup Fly package managers
```

### GitHub Action Example

```yaml
name: Build and Publish .NET Package

on:
  push:
    branches: [main]

permissions:
  contents: read
  id-token: write

jobs:
  build:
    runs-on: ubuntu-latest

    steps:
      - uses: actions/checkout@v4

      - uses: actions/setup-dotnet@v4
        with:
          dotnet-version: '8.0'

      - uses: jfrog/fly-action@v1              # Setup Fly package managers

      - run: dotnet restore                    # Dependencies from Fly registry

      - run: dotnet build --configuration Release

      - run: dotnet pack --configuration Release

      - run: dotnet nuget push ./bin/Release/*.nupkg
        # Push to Fly registry
```

---

*Back to [Package Managers →](../)*
