Help us shape the future of Go! Take the 2026 Go Developer Survey

dotnet

package
v1.37.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 20, 2026 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// SingleFileAspireHostName is the required filename for single-file Aspire AppHosts
	SingleFileAspireHostName = "apphost.cs"
	// AspireSdkDirective is the SDK directive that must be present in single-file Aspire AppHosts
	AspireSdkDirective = "#:sdk Aspire.AppHost.Sdk"
)

Constants for Aspire AppHost detection

Variables

View Source
var DotNetProjectExtensions = []string{".csproj", ".fsproj", ".vbproj"}

DotNetProjectExtensions lists all valid .NET project file extensions

Functions

func ArtifactsPathFromContext added in v1.25.1

func ArtifactsPathFromContext(ctx context.Context) string

ArtifactsPathFromContext retrieves the per-service artifacts path from the context, or "" if none was set.

func ContextWithArtifactsPath added in v1.25.1

func ContextWithArtifactsPath(ctx context.Context, path string) context.Context

ContextWithArtifactsPath returns a new context carrying a per-service artifacts path. When set, dotnet publish commands append `--artifacts-path <path>` to redirect all intermediate build outputs (obj/, bin/) to a service-specific directory, preventing file races when multiple services sharing <ProjectReference> dependencies are published in parallel.

Types

type Cli

type Cli struct {
	// contains filtered or unexported fields
}

func NewCli

func NewCli(commandRunner exec.CommandRunner) *Cli

func (*Cli) Build

func (cli *Cli) Build(ctx context.Context, project string, configuration string, output string, env []string) error

func (*Cli) BuildContainerLocal

func (cli *Cli) BuildContainerLocal(
	ctx context.Context, project, configuration, imageName string, containerEngine tools.ContainerEngine,
) (int, string, error)

BuildContainerLocal runs `dotnet publish` with `/t:PublishContainer` to build a container image locally without pushing to a registry. Returns the port number and image name. A zero-value containerEngine uses the .NET SDK's default runtime.

func (*Cli) CheckInstalled

func (cli *Cli) CheckInstalled(ctx context.Context) error

func (*Cli) GetMsBuildProperty

func (cli *Cli) GetMsBuildProperty(ctx context.Context, project string, propertyName string) (string, error)

GetMsBuildProperty uses -getProperty to fetch a property after evaluation, without executing the build.

This only works for versions dotnet >= 8, MSBuild >= 17.8. On older tool versions, this will return an error.

func (*Cli) GitIgnore

func (cli *Cli) GitIgnore(ctx context.Context, projectPath string, options *GitIgnoreOptions) error

func (*Cli) InitializeSecret

func (cli *Cli) InitializeSecret(ctx context.Context, project string) error

func (*Cli) InstallUrl

func (cli *Cli) InstallUrl() string

func (*Cli) IsAspireHostProject

func (cli *Cli) IsAspireHostProject(ctx context.Context, projectPath string) (bool, error)

IsAspireHostProject returns true if the project at the given path has an MS Build Property named "IsAspireHost" which is set to true or has a ProjectCapability named "Aspire". For single-file apphost (apphost.cs), it validates them without running msbuild.

func (*Cli) IsSingleFileAspireHost

func (cli *Cli) IsSingleFileAspireHost(filePath string) (bool, error)

IsSingleFileAspireHost checks if the given file is a single-file Aspire AppHost. The caller should verify the filename matches SingleFileAspireHostName before calling this function. A file-based Aspire AppHost must meet all of these conditions: 1. File name: Must be named apphost.cs (case-insensitive) - verified by caller 2. No sibling .NET project files: The directory must NOT contain .csproj, .fsproj, or .vbproj files 3. SDK Directive: Must contain the AspireSdkDirective in the file content

func (*Cli) Name

func (cli *Cli) Name() string

func (*Cli) Publish

func (cli *Cli) Publish(ctx context.Context, project string, configuration string, output string, env []string) error

func (*Cli) PublishAppHostManifest

func (cli *Cli) PublishAppHostManifest(
	ctx context.Context, hostProject string, manifestPath string, dotnetEnv string,
) error

func (*Cli) PublishContainer

func (cli *Cli) PublishContainer(
	ctx context.Context, project, configuration, imageName, server, username, password string,
	containerEngine tools.ContainerEngine,
) (int, error)

PublishContainer runs `dotnet publish` with `/t:PublishContainer` to build and publish a container image. It returns the port number from `--getProperty:GeneratedContainerConfiguration`. For single-file apps (.cs files), it runs from the file's directory to resolve relative references. A zero-value containerEngine uses the .NET SDK's default runtime.

func (*Cli) Restore

func (cli *Cli) Restore(ctx context.Context, project string, env []string) error

func (*Cli) SdkVersion added in v1.24.0

func (cli *Cli) SdkVersion(ctx context.Context) (semver.Version, error)

SdkVersion returns the installed .NET SDK version by running `dotnet --version` and parsing the output as semver. Successful probes are cached, while failed probes may be retried.

func (*Cli) SetSecrets

func (cli *Cli) SetSecrets(ctx context.Context, secrets map[string]string, project string) error

func (*Cli) SupportsArtifactsPath added in v1.33.0

func (cli *Cli) SupportsArtifactsPath(ctx context.Context) (bool, error)

SupportsArtifactsPath reports whether the installed .NET SDK supports `dotnet publish --artifacts-path`.

type GitIgnoreIfExistsStrategy

type GitIgnoreIfExistsStrategy string
const (
	// GitIgnoreIfExistsStrategySkip skips creating the .gitignore file if it already exists. This is the default behavior.
	GitIgnoreIfExistsStrategySkip GitIgnoreIfExistsStrategy = "skip"
	// GitIgnoreIfExistsStrategyOverwrite overwrites the existing .gitignore file.
	GitIgnoreIfExistsStrategyOverwrite GitIgnoreIfExistsStrategy = "overwrite"
)

type GitIgnoreOptions

type GitIgnoreOptions struct {
	// IfExistsStrategy determines what to do if the .gitignore file already exists. Default is Skip.
	IfExistsStrategy GitIgnoreIfExistsStrategy
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL