Table of Contents

Interface INugetHelper

Namespace
Invex.Atom.Module.Dotnet.Helpers
Assembly
Invex.Atom.Module.Dotnet.dll

Provides helper methods for interacting with NuGet, such as pushing packages and managing NuGet configuration.

public interface INugetHelper : IBuildInfo, IBuildAccessor
Inherited Members

Remarks

This interface extends IBuildInfo to leverage build version information and provides functionality for common NuGet operations within a Invex.Atom build.

Properties

NugetConfigPath

Gets the path to the default NuGet configuration file (NuGet.Config) for the current operating system.

RootedPath NugetConfigPath { get; }

Property Value

RootedPath

Remarks

This property determines the standard location where NuGet configuration files are expected. On Windows, it's typically %APPDATA%\NuGet\NuGet.Config. On Linux/macOS, it's typically $HOME/.nuget/NuGet.Config.

NugetDryRun

Gets a value indicating whether NuGet write operations (like pushing packages) should be performed as a dry run.

[ParamDefinition("nuget-dry-run", "Whether to perform a dry run of nuget write operations.", ParamSource.All, null)]
bool NugetDryRun { get; }

Property Value

bool

Remarks

When true, NuGet operations that modify remote feeds will be simulated and logged, but no actual changes will be made. This is useful for testing build configurations.

Methods

CreateNugetConfigOverwriteScope(NugetFeed[], bool, CancellationToken)

Creates a Invex.FileSystem.TransformFileScope that temporarily overwrites the default NuGet.Config file with a configuration that includes the specified NuGet feeds and their credentials.

Task<TransformFileScope?> CreateNugetConfigOverwriteScope(NugetFeed[] feeds, bool skipIfExists = false, CancellationToken cancellationToken = default)

Parameters

feeds NugetFeed[]

An array of NugetFeed objects to include in the configuration.

skipIfExists bool

If true, and all specified feeds are already present in the existing NuGet.Config, no overwrite will occur, and null will be returned.

cancellationToken CancellationToken

A cancellation token to observe while waiting for the task to complete.

Returns

Task<TransformFileScope>

A System.Threading.Tasks.Task<TResult> that returns a Invex.FileSystem.TransformFileScope instance, or null if the overwrite was skipped. Disposing the scope restores the original NuGet.Config file.

Remarks

This method generates a NuGet.Config XML structure including <packageSources> and < packageSourceCredentials> based on the provided feed information. Passwords are included as clear text if specified via PlainTextPassword.

CreateNugetConfigOverwriteScope(string, CancellationToken)

Creates a Invex.FileSystem.TransformFileScope that temporarily overwrites the default NuGet.Config file with the provided content.

Task<TransformFileScope> CreateNugetConfigOverwriteScope(string contents, CancellationToken cancellationToken = default)

Parameters

contents string

The new content for the NuGet.Config file.

cancellationToken CancellationToken

A cancellation token to observe while waiting for the task to complete.

Returns

Task<TransformFileScope>

A System.Threading.Tasks.Task<TResult> that returns a Invex.FileSystem.TransformFileScope instance. Disposing this scope will restore the original NuGet.Config file.

IsNugetPackageVersionPublished(string, string, string, string?, CancellationToken)

Checks if a specific version of a NuGet package is already published to a given feed.

Task<bool> IsNugetPackageVersionPublished(string projectName, string version, string feedUrl, string? feedKey = null, CancellationToken cancellationToken = default)

Parameters

projectName string

The name of the NuGet package (e.g., "MyProject.Core").

version string

The semantic version of the package (e.g., "1.0.0").

feedUrl string

The URL of the NuGet feed (e.g., "https://api.nuget.org/v3/index.json").

feedKey string

Optional API key for authenticated feeds.

cancellationToken CancellationToken

A cancellation token to observe while waiting for the task to complete.

Returns

Task<bool>

A System.Threading.Tasks.Task<TResult> that returns true if the package version is published, otherwise false .

Exceptions

InvalidOperationException

Thrown if the NuGet feed's registration base URL cannot be found or if the status check fails unexpectedly.

PushPackageToNuget(RootedPath, string, string, RootedPath?, CancellationToken)

Pushes a specific NuGet package file to a NuGet feed.

Task PushPackageToNuget(RootedPath packagePath, string feed, string apiKey, RootedPath? configFile = null, CancellationToken cancellationToken = default)

Parameters

packagePath RootedPath

The full path to the .nupkg file to push.

feed string

The NuGet feed URL to push the package to.

apiKey string

The API key for authenticating with the NuGet feed.

configFile RootedPath

Optional path to a NuGet configuration file to use instead of the default one.

cancellationToken CancellationToken

A cancellation token to observe while waiting for the task to complete.

Returns

Task

A System.Threading.Tasks.Task representing the asynchronous operation.

Remarks

If NugetDryRun is true, the push operation will be simulated. The API key is never written to the log. If dotnet nuget push exits with a non-zero exit code, the process runner throws and the target fails.

PushProject(string, string, string, RootedPath?, CancellationToken)

Pushes a NuGet package for a specific project to a NuGet feed.

Task PushProject(string projectName, string feed, string apiKey, RootedPath? configFile = null, CancellationToken cancellationToken = default)

Parameters

projectName string

The name of the project whose package is to be pushed.

feed string

The NuGet feed URL to push the package to.

apiKey string

The API key for authenticating with the NuGet feed.

configFile RootedPath

Optional path to a NuGet configuration file to use instead of the default one.

cancellationToken CancellationToken

A cancellation token to observe while waiting for the task to complete.

Returns

Task

A System.Threading.Tasks.Task representing the asynchronous operation.

Remarks

This method expects the project to have been built and its NuGet package (`.nupkg`) to be available in the Atom artifacts directory, named according to the project name and the BuildVersion.

It requires the `dotnet` CLI to be installed and available in the system's PATH.

If NugetDryRun is true, the push operation will be simulated.