craft_parts.plugins.dotnet_v2_plugin module

The new .NET plugin.

class craft_parts.plugins.dotnet_v2_plugin.DotnetConfiguration(value, names=<not given>, *values, module=None, qualname=None, type=None, start=1, boundary=None)

Bases: str, Enum

The .NET build configuration.

DEBUG = 'Debug'

Build with debug symbols and no optimizations.

RELEASE = 'Release'

Build with optimizations and no debug symbols. This is the default configuration.

class craft_parts.plugins.dotnet_v2_plugin.DotnetV2Plugin(*, properties, part_info)

Bases: Plugin

A plugin for .NET projects.

The .NET plugin uses the common plugin keys as well as those for “sources”. Additionally, the following plugin-specific keys can be used:

Global Flags:

  • dotnet-configuration (string) The .NET build configuration to use. (Default: “Release”).

  • dotnet-project (string) The .NET proj or solution file to build. (Default: omitted).

  • dotnet-properties (dictionary of strings to strings) The list of MSBuild properties to be used by the restore, build, and publish commands. (Default: empty).

  • dotnet-self-contained (bool) Build and publish the project as a self-contained application. (Default: False).

  • dotnet-verbosity (string) The verbosity level of the build output. Possible values are q[uiet], m[inimal], n[ormal], d[etailed], and diag[nostic]. (Default: “normal”).

  • dotnet-version (string) The version of the .NET SDK to download and use. This parameter is optional, so if no value is specified, the plugin will assume a .NET SDK is being provided and will not attempt to download one.

Restore-specific Flags:

  • dotnet-restore-sources (string) The URI of the NuGet package sources to use during the restore operation. Multiple values can be specified. This setting overrides all of the sources specified in the nuget.config files. (Default: omitted).

  • dotnet-restore-properties (dictionary of strings to strings) The list of MSBuild properties to be used by the restore command. (Default: empty).

  • dotnet-restore-configfile (string) The NuGet configuration file (nuget.config) to use. (Default: omitted).

Build-specific Flags:

  • dotnet-build-framework (string) The target framework to build for. (Default: omitted).

  • dotnet-build-properties (dictionary of strings to strings) The list of MSBuild properties to be used by the build command. (Default: empty).

Publish-specific Flags:

  • dotnet-publish-properties (dictionary of strings to strings) The list of MSBuild properties to be used by the publish command. (Default: empty).

Parameters:
get_build_commands()

Return a list of commands to run during the build step.

Return type:

list[str]

get_build_environment()

Return a dictionary with the environment to use in the build step.

Return type:

dict[str, str]

get_build_packages()

Return a set of required packages to install in the build environment.

Return type:

set[str]

get_build_snaps()

Return a set of required snaps to install in the build environment.

Return type:

set[str]

properties_class

alias of DotnetV2PluginProperties

validator_class

alias of DotnetV2PluginEnvironmentValidator

class craft_parts.plugins.dotnet_v2_plugin.DotnetV2PluginEnvironmentValidator(*, part_name, env, properties)

Bases: PluginEnvironmentValidator

Check the execution environment for the .NET plugin.

Parameters:
  • part_name (str) – The part whose build environment is being validated.

  • env (str) – A string containing the build step environment setup.

  • properties (PluginProperties)

validate_environment(*, part_dependencies=None)

Ensure the environment contains dependencies needed by the plugin.

Parameters:

part_dependencies (list[str] | None) – A list of the parts this part depends on.

Return type:

None

class craft_parts.plugins.dotnet_v2_plugin.DotnetV2PluginProperties(**data)

Bases: PluginProperties

The part properties used by the .NET plugin.

Parameters:

data (Any)

dotnet_build_framework: str | None

The specific .NET framework to compile for.

The framework must be defined in the .NET project file.

dotnet_build_properties: dict[str, str]

The MSBuild properties to append to the build command, in the format -p:<Key>=<Value>.

dotnet_configuration: DotnetConfiguration

The .NET build configuration to use.

dotnet_project: str | None

The path to the solution or project file to build, relative to the root of the snap source.

If a path isn’t specified, MSBuild will search the root of the source for a file with the .*proj or .sln extension.

dotnet_properties: dict[str, str]

The MSBuild properties to append to the restore, build, and publish commands.

dotnet_publish_properties: dict[str, str]

The MSBuild properties to append to the publish command, in the format -p:<Key>=<Value>.

dotnet_restore_configfile: str | None

The path to the part’s NuGet configuration file.

If set, only the settings from this file will be used.

If unset, the hierarchy of configuration files from the current directory will be used. For more information, see Common NuGet Configurations.

dotnet_restore_properties: dict[str, str]

The MSBuild properties to append to the restore command.

dotnet_restore_sources: list[str]

The URIs of the NuGet package sources for use during a restore.

If set, the URIs override all of the sources declared in the nuget.config files.

dotnet_self_contained: bool

Whether to create a self-contained .NET part.

The Runtime Identifier will be automatically set based on the value of the $CRAFT_BUILD_FOR environment variable:

$CRAFT_BUILD_FOR value

Runtime Identifier

amd64

linux-x64

arm64

linux-arm64

dotnet_verbosity: DotnetVerbosity

The verbosity of the MSBuild log.

dotnet_version: str | None

The .NET version to build the part with.

If set, the plugin will download the necessary .NET SDK content snap and use it to build the app.

See Dependencies for a more detailed explanation of this key.

model_config: ClassVar[ConfigDict] = {'alias_generator': <function PluginProperties.<lambda>>, 'extra': 'forbid', 'frozen': True, 'validate_assignment': True}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

plugin: Literal['dotnet']
source: str
classmethod validate_dotnet_version(value)

Validate the dotnet-version property.

Parameters:

value (str | None) – The value to validate.

Return type:

str | None

Returns:

The validated value.

class craft_parts.plugins.dotnet_v2_plugin.DotnetVerbosity(value, names=<not given>, *values, module=None, qualname=None, type=None, start=1, boundary=None)

Bases: str, Enum

The .NET build verbosity level.

DETAILED = 'detailed'

Show detailed build output.

DETAILED_SHORT = 'd'

Alias for detailed.

DIAGNOSTIC = 'diagnostic'

Show diagnostic build output, the most verbose level.

DIAGNOSTIC_SHORT = 'diag'

Alias for diagnostic.

MINIMAL = 'minimal'

Show minimal build output.

MINIMAL_SHORT = 'm'

Alias for minimal.

NORMAL = 'normal'

Show normal build output. This is the default level.

NORMAL_SHORT = 'n'

Alias for normal.

QUIET = 'quiet'

Show only errors.

QUIET_SHORT = 'q'

Alias for quiet.