# jf nuget Run NuGet commands with Artifactory integration for dependency resolution and build information collection. This topic covers the following tasks: * [Configure NuGet for Artifactory (`jf nuget-config`)](#configuration-jf-nuget-config) * [Run NuGet commands (`jf nuget`)](#build-jf-nuget) ## When to Use Use `jf nuget` if your .NET project uses the NuGet CLI directly for package management. For projects using the .NET SDK CLI (`dotnet restore`, `dotnet build`), use [`jf dotnet`](jf-dotnet.md) instead. ## Prerequisites * Run `jf nuget-config` in the project directory before the first build. * Configure a server with `jf config add` or `jf c add`. * Authentication to Artifactory is required. *** ## Configuration: `jf nuget-config` Generate NuGet configuration for resolving packages through Artifactory. **Run this once per project before your first build.** **To configure NuGet for Artifactory:** ### Synopsis ``` jf nuget-config [options] ``` **Aliases:** `nugetc` ### Configuration Options | Flag | Default | Description | | --------------------- | ------- | ----------------------------------------------------- | | `--global` | `false` | Apply configuration globally for all projects | | `--server-id-resolve` | — | Artifactory server ID for dependency resolution | | `--repo-resolve` | — | Repository for resolving packages | | `--nuget-v2` | `false` | Use NuGet V2 protocol when restoring from Artifactory | ### Configuration Examples #### View Help ```bash jf nuget-config --help ``` #### Non-Interactive Configuration Configure NuGet with non-interactive flags: ```bash jf nuget-config --server-id-resolve= --repo-resolve= ``` Where: * \: The server ID configured using `jf config add` * \: The name of the NuGet repository in Artifactory For example: ```bash jf nuget-config --server-id-resolve=my-server --repo-resolve=nuget-virtual ``` ### Why Run Config First? You must run `jf nuget-config` **before** `jf nuget restore`. The config creates `.jfrog/projects/nuget.yaml` for NuGet package resolution through Artifactory. Without it, `jf nuget` does not know where to fetch packages. If you skip this step, you will see the error: `no config file was found! Before running the 'jf nuget' command on a project for the first time, the project should be configured with the 'jf nuget-config' command`. > **Shortcut**: In CI/CD, pass all flags non-interactively so the config step is fully automated and reproducible. ### Configuration Notes * **Run once per project**: Re-run when changing the resolution repository. * **NuGet V2**: Set `--nuget-v2=true` only if your Artifactory NuGet repository uses V2 protocol. * **Alternative**: For .NET SDK projects, use [`jf dotnet`](jf-dotnet.md) for broader .NET integration. ### Expected Output ``` $ jf nuget-config --server-id-resolve=my-server --repo-resolve=nuget-virtual NuGet build configuration saved successfully. ``` ### How to Verify After running, confirm the configuration exists: ```bash cat .jfrog/projects/nuget.yaml ``` *** ## Build: `jf nuget` Run NuGet commands with Artifactory integration for dependency resolution and build information collection. **To run NuGet with Artifactory integration:** ### Synopsis ``` jf nuget [options] ``` **Aliases:** none ### Arguments | Argument | Required | Description | | ----------------- | -------- | ------------------------------------------------------------ | | `nuget-arguments` | Yes | NuGet command and arguments (for example, `restore`, `push`) | ### Build Options | Flag | Default | Description | | ------------------------------ | ------- | ----------------------------------------------------------------- | | `--build-name` | — | Build name for build information (requires `--build-number`) | | `--build-number` | — | Build number for build information (requires `--build-name`) | | `--project` | — | JFrog Artifactory project key | | `--module` | — | Optional module name for build information | | `--allow-insecure-connections` | `false` | Configure NuGet sources with unsecured connections (testing only) | ### Build Examples #### Restore Packages ```bash jf nuget restore ``` #### Push with Build Information ```bash jf nuget push --build-name= --build-number= ``` Where: * `` is the path to the `.nupkg` file (e.g., `bin/Release/MyPackage.1.0.0.nupkg`) * `` is a name for the build (e.g., `my-dotnet-app`) * `` is a number or identifier for the build run (e.g., `1`) For example: ```bash jf nuget push bin/Release/MyPackage.1.0.0.nupkg --build-name=my-dotnet-app --build-number=1 ``` *** ## Important Notes * **NuGet v2 vs v3**: Use `--nuget-v2` in `jf nuget-config` if your Artifactory NuGet repository is configured for the V2 protocol. * **Insecure connections**: The `--allow-insecure-connections` flag is for **testing only**. Do not use in production. * **Build-info**: Use `--build-name` and `--build-number`, then publish with `jf rt build-publish`. * **Alternative**: For .NET projects, `jf dotnet` provides similar functionality using the .NET CLI instead of NuGet directly. ## Running Builds with MSBuild JFrog CLI includes integration with MSBuild and Artifactory, allowing you to resolve dependencies and deploy build artifacts while collecting build-info. This is done by having JFrog CLI in your search path and adding JFrog CLI commands to the MSBuild `.csproj` file. For detailed instructions, refer to the [MSBuild project example on GitHub](https://github.com/jfrog/project-examples). ## CI/CD Example (GitHub Actions) ```yaml # .github/workflows/build.yml steps: - uses: actions/checkout@v4 - name: Setup JFrog CLI uses: jfrog/setup-jfrog-cli@v4 env: JF_URL: ${{ vars.JF_URL }} JF_ACCESS_TOKEN: ${{ secrets.JF_ACCESS_TOKEN }} - name: Configure NuGet run: jf nuget-config --server-id-resolve=setup-jfrog-cli-server --repo-resolve=nuget-virtual - name: Restore packages run: jf nuget restore --build-name=my-dotnet-app --build-number=${{ github.run_number }} - name: Publish build info run: jf rt build-publish my-dotnet-app ${{ github.run_number }} ``` ## Troubleshooting | Symptom | Cause | Fix | | ---------------------------------------- | ----------------------------------------------------- | ----------------------------------------------------------------------------------- | | `no config file was found` | `jf nuget-config` was not run | Run `jf nuget-config` in the project directory | | 404 on `jf nuget restore` | Resolution repository does not exist or name is wrong | Verify `--repo-resolve` matches an existing NuGet virtual repository in Artifactory | | 401 / 403 errors | Invalid credentials or insufficient permissions | Re-run `jf config add` with a valid access token | | NuGet V2 protocol errors | Artifactory repo uses V2 but config defaults to V3 | Set `--nuget-v2=true` in `jf nuget-config` | | `jf nuget restore` fails with SSL errors | Corporate proxy or self-signed certificates | Use `--allow-insecure-connections` for testing (not recommended for production) | **Enable debug logging:** `export JFROG_CLI_LOG_LEVEL=DEBUG`
## Related Topics * [Build Tools Overview](/artifactory/docs/build-tool-commands) — Capabilities matrix and tool reference * [Native Mode](/artifactory/docs/native-mode) — Supported packages with Native Mode