• NeonSDK
  • NeonKUBE
Search Results for

    Show / Hide Table of Contents
    • Neon
      • Build
    • Neon.Blazor
      • BlazorHelper
      • BodyOutlet
      • ClientRenderContext
      • DOMRectReadOnly
      • EventHandlers
      • FileDownloader
      • HtmlElement
      • IRenderContext
      • IntersectionChangedEventArgs
      • IntersectionObserver
      • IntersectionObserverContext
      • MobileDetector
      • NeonBlazorExtensions
      • ServerRenderContext
      • SwipeDirection
      • SwipeHandler
    • Neon.Blazor.Analyzers
      • SvgGenerator
      • SvgGenerator.Svg
    • Neon.BuildInfo
      • ThisAssembly
      • ThisAssembly.Git
      • ThisAssembly.Git.BaseVersion
      • ThisAssembly.Git.SemVer
    • Neon.CSharp
      • CSharpHelper
      • CompilerErrorException
      • MetadataReferences
    • Neon.Cassandra
      • KeyspaceStatus
      • RowSetExtensions
      • SchemaManager
      • SchemaManagerException
      • SchemaStatus
      • SessionExtensions
    • Neon.Collections
      • ArgDictionary
      • Bits
      • IObjectDictionary
      • NiceDictionary<TKey, TValue>
      • ObjectDictionary
    • Neon.Common
      • AppDomainExtensions
      • Block
      • BlockArray
      • ByteEncoding
      • ByteUnits
      • CommandLine
      • CommandLine.OptionDefinition
      • CommandLine.Redactor
      • CpuArchitecture
      • Credentials
      • DateTimeExtensions
      • EnumExtensions
      • EnvironmentParser
      • EnvironmentParser.Parser<T>
      • EnvironmentParser.Validator<T>
      • EnvironmentParser.VariableSource
      • ExceptionExtensions
      • ExecuteException
      • ExecuteResponse
      • GlobPattern
      • HexDumpOption
      • HttpClientExtensions
      • HttpResponseMessageExtensions
      • IEnumerableExtensions
      • ILabeled
      • IOExtensions
      • IServiceContainer
      • IStaticDirectoryExtensions
      • LabelSelector
      • LabelSelectorOptions
      • LabelSelector<TItem>
      • NeonAssemblyExtensions
      • NeonExtendedHelper
      • NeonHelper
      • NetFramework
      • NewtonsoftExtensions
      • NotReadyException
      • ProcessExtensions
      • ProgramEntrypoint
      • ProgramEntrypointAsync
      • ProgramExitException
      • ProgramRunner
      • RandomExtensions
      • ReflectionExtensions
      • SemanticVersion
      • ServiceContainer
      • StaticZipOptions
      • StringBuilderExtensions
      • StringExtensions
      • Stub
      • Stub.Value
      • TaskExtensions
      • TimeSpanExtensions
      • ToolException
      • TriState
      • WeakEventController
      • WindowsEdition
      • WindowsFeatureStatus
      • YamlDotNetExtensions
    • Neon.Cryptography
      • AesCipher
      • CryptoExtensions
      • CryptoHelper
      • NeonVault
      • Wildcard
    • Neon.Csv
      • CsvReader
      • CsvTableReader
      • CsvTableWriter
      • CsvWriter
    • Neon.Data
      • DateTimeJsonConverter
      • DateTimeOffsetJsonConverter
      • IEnhancedJsonConverter
      • IGeneratedServiceClient
      • IPersistableType
      • IPersistableType<T>
      • IRoundtripData
      • IntegerEnumConverter<TEnum>
      • NotifyPropertyChanged
      • RoundtripDataFactory
      • RoundtripDataHelper
      • TimeSpanJsonConverter
      • VersionJsonConverter
    • Neon.Deployment
      • AwsCli
      • DeploymentException
      • DeploymentHelper
      • DownloadManifest
      • DownloadPart
      • DownloadProgressDelegate
      • DownloadProgressType
      • GitHub
      • GitHubActionsApi
      • GitHubPackage
      • GitHubPackageApi
      • GitHubPackageType
      • GitHubPackageVersion
      • GitHubPackageVisibility
      • GitHubReleaseApi
      • GitHubRepoPath
      • GitHubTagApi
      • IProfileClient
      • IProfileRequest
      • IProfileResponse
      • MaintainerProfile
      • NotifyClient
      • OnePassword
      • OnePasswordException
      • ProfileException
      • ProfileHandlerResult
      • ProfileRequest
      • ProfileResponse
      • ProfileServer
      • ProfileStatus
      • XenServer
    • Neon.Deployment.CodeSigning
      • AzureProfile
      • CodeSigner
      • UsbTokenProfile
    • Neon.Diagnostics
      • AssertException
      • ConfigExtensions
      • ConsoleJsonLogExporter
      • ConsoleJsonLogExporterOptions
      • ConsoleTextLogExporter
      • ConsoleTextLogExporterOptions
      • ExceptionInfo
      • FileLogExporter
      • FileLogExporterFormat
      • FileLogExporterOptions
      • LogAsTraceProcessor
      • LogAsTraceProcessorOptions
      • LogAttributeNames
      • LogAttributes
      • LogEvent
      • LogEventInterceptor
      • LoggerExtensions
      • NullLogger
      • TelemetryHub
      • TelemetrySpanEventNames
      • TelemetrySpanExtensions
    • Neon.Docker
      • DockerClient
      • DockerNetwork
      • DockerNetworkContainer
      • DockerNetworkIpam
      • DockerNode
      • DockerNodeManagerStatus
      • DockerResponse
      • DockerSettings
      • DockerVolume
      • NetworkCreateResponse
      • ServiceBindOptions
      • ServiceConfig
      • ServiceContainerSpec
      • ServiceCredentialSpec
      • ServiceDetails
      • ServiceDiscreteResourceSpec
      • ServiceDnsConfig
      • ServiceEndpoint
      • ServiceEndpointMode
      • ServiceEndpointPortConfig
      • ServiceEndpointSpec
      • ServiceFile
      • ServiceGenericResources
      • ServiceGlobalSchedulingMode
      • ServiceHealthCheck
      • ServiceIsolationMode
      • ServiceListResponse
      • ServiceLogDriver
      • ServiceMode
      • ServiceMount
      • ServiceMountBindPropagation
      • ServiceMountConsistency
      • ServiceMountType
      • ServiceNamedResourceSpec
      • ServiceNetwork
      • ServicePlacement
      • ServicePlacementPreferences
      • ServicePlacementSpreadSettings
      • ServicePlatform
      • ServicePortMode
      • ServicePortProtocol
      • ServicePrivileges
      • ServiceReplicatedSchedulingMode
      • ServiceResourceSettings
      • ServiceResources
      • ServiceRestartCondition
      • ServiceRestartPolicy
      • ServiceRollbackConfig
      • ServiceRollbackFailureAction
      • ServiceRollbackOrder
      • ServiceSELinuxContext
      • ServiceSchedulingMode
      • ServiceSecret
      • ServiceSpec
      • ServiceTaskTemplate
      • ServiceTmpfsOptions
      • ServiceUpdateConfig
      • ServiceUpdateFailureAction
      • ServiceUpdateOrder
      • ServiceUpdateState
      • ServiceUpdateStatus
      • ServiceVersion
      • ServiceVirtualIP
      • ServiceVolumeDriverConfig
      • ServiceVolumeOptions
      • VolumeListResponse
    • Neon.GitHub
      • GitExtensions
      • GitHubCredentials
      • GitHubRepo
      • LocalRepoApi
      • NoLocalRepositoryException
      • RemoteRepoApi
      • RemoteRepoBranchApi
      • RemoteRepoIssueApi
      • RemoteRepoIssueCommentApi
      • RemoteRepoPath
      • RemoteRepoReleaseApi
      • RemoteRepoTagApi
    • Neon.HyperV
      • HyperVClient
      • HyperVDriverType
      • HyperVException
      • NetAdapter
      • VirtualDrive
      • VirtualIPAddress
      • VirtualMachine
      • VirtualMachineNetworkAdapter
      • VirtualMachineState
      • VirtualNat
      • VirtualSwitch
      • VirtualSwitchType
    • Neon.IO
      • BlockStream
      • FixedLengthStream
      • IStaticDirectory
      • IStaticFile
      • LineEnding
      • LinuxPath
      • LinuxPermissions
      • PreprocessReader
      • RelayStream
      • StaticDirectoryBase
      • StaticFileBase
      • SubStream
      • TempFile
      • TempFolder
    • Neon.JsonConverters
      • JsonDateTimeConverter
      • JsonGenericConverter<T>
      • JsonNullableDateTimeConverter
    • Neon.ModelGen
      • ActionResult<T>
      • ApiVersion
      • ApiVersionAttribute
      • BodyStreamAttribute
      • ControllerValidationAttribute
      • DataModelAttribute
      • EnumMember
      • FromBodyAttribute
      • FromHeaderAttribute
      • FromQueryAttribute
      • FromRouteAttribute
      • GeneratedClientAttribute
      • GeneratedMethodAttribute
      • GeneratedParamAttribute
      • HashSourceAttribute
      • HttpAttribute
      • HttpDeleteAttribute
      • HttpGetAttribute
      • HttpHeadAttribute
      • HttpOptionsAttribute
      • HttpPatchAttribute
      • HttpPostAttribute
      • HttpPutAttribute
      • IActionResult
      • ModelGenerator
      • ModelGeneratorOutput
      • ModelGeneratorSettings
      • NoCodeGenAttribute
      • NoControllerValidationAttribute
      • PassAs
      • PersistableAttribute
      • PersistableKeyAttribute
      • RouteAttribute
      • ServiceModelAttribute
      • TargetAttribute
      • UxFrameworks
    • Neon.Net
      • HttpApiException
      • HttpException
      • JsonClient
      • JsonClientPayload
      • JsonResponse
      • Jwt
      • LocalHostSection
      • NetConst
      • NetHelper
      • NetworkCidr
      • NetworkConfiguration
      • NetworkException
      • NetworkPorts
      • Pinger
      • ReachableHost
      • ReachableHostMode
      • StreamDocument
    • Neon.Postgres
      • ConnectionExtensions
      • DatabaseStatus
      • PreparedCommand
      • ReaderAsyncEnumerator
      • ReaderEnumerator
      • ReaderExtensions
      • SchemaManager
      • SchemaManagerException
      • SchemaStatus
    • Neon.Retry
      • ExponentialRetryPolicy
      • IRetryPolicy
      • LinearRetryPolicy
      • NoRetryPolicy
      • RetryPolicy
      • RetryPolicyBase
      • RetryTransientArgs
      • TransientDetector
      • TransientException
    • Neon.Roslyn
      • DisplayFormat
      • DocumentationComment
      • DocumentationItem
      • MetadataLoadContext
      • RoslynAssembly
      • RoslynConstructorInfo
      • RoslynCustomAttributeData
      • RoslynExtensions
      • RoslynFieldInfo
      • RoslynMethodInfo
      • RoslynParameterInfo
      • RoslynPropertyInfo
      • RoslynType
      • SharedUtilities
    • Neon.Roslyn.Xunit
      • AdditionalSourceText
      • CompilationOptions
      • CompilationOptionsProvider
      • TestCompilation
      • TestCompilationAssertions
      • TestCompilationBuilder
      • TestCompilationBuilderExtensions
      • TestCompilationExtensions
    • Neon.SSH
      • CommandBundle
      • CommandFile
      • CommandResponse
      • HostFolders
      • IBashCommandFormatter
      • ILinuxSshProxy
      • LinuxDiskInfo
      • LinuxDiskPartition
      • LinuxSshProxy
      • LinuxSshProxy<TMetadata>
      • NamespaceDoc
      • RemoteCommandException
      • RunOptions
      • SshCredentials
      • SshExtensions
      • SshProxyException
    • Neon.Service
      • LogMetricsProcessor
      • MetricsMode
      • MetricsOptions
      • NeonService
      • NeonServiceOptions
      • NeonServiceStatus
      • OtelConfigExtensions
      • OtlpCollectorChecker
      • ProcessTerminator
      • ServiceApiContact
      • ServiceApiInfo
      • ServiceApiLicense
      • ServiceDependencies
      • ServiceDescription
      • ServiceEndpoint
      • ServiceEndpointProtocol
      • ServiceEndpoints
      • ServiceMap
    • Neon.SignalR
      • DependencyInjectionExtensions
      • DnsCache
      • GroupAction
      • GroupCommand
      • IDnsCache
      • Invocation
      • NatsHubLifetimeManager<THub>
      • ProxyConfig
      • ServiceCollectionExtensions
      • ServiceDiscovey
      • SignalrProxyMiddleware
      • SignalrProxyMiddlewareExtensions
      • TracerProviderBuilderExtensions
    • Neon.Tailwind
      • ClickOffEventHandler
      • ComponentEventArgs<TSender>
      • ComponentEventArgs<TSender, TEventArgs>
      • DisclosureState
      • EventHandlerComponentBase<TComponent>
      • HeadlessButton
      • HeadlessDialog
      • HeadlessDialogPanel
      • HeadlessDisclosure
      • HeadlessDisclosureButton
      • HeadlessDisclosurePanel
      • HeadlessListboxButton<TValue>
      • HeadlessListboxLabel<TValue>
      • HeadlessListboxOption<TValue>
      • HeadlessListboxOptions<TValue>
      • HeadlessListbox<TValue>
      • HeadlessMenu
      • HeadlessMenuButton
      • HeadlessMenuItem
      • HeadlessMenuItems
      • HeadlessSwitch
      • HeadlessSwitchGroup
      • HeadlessSwitchLabel
      • IPortalBinder
      • KeyDownEventHandler
      • KeyboardKey
      • ListboxFocus
      • ListboxState
      • MenuFocus
      • MenuState
      • Portal
      • PortalBinder
      • PortalContent
      • SearchAssistant
      • TailwindExtensions
      • Transition
      • TransitionGroup
      • TransitionState
    • Neon.Tasks
      • Async
      • AsyncAutoResetEvent
      • AsyncManualResetEvent
      • AsyncMutex
      • AsyncPeriodicTask
      • AsyncReaderWriterLock
      • AsyncReentrantMutex
      • AsyncTimer
      • IAsyncFuture
      • IAsyncFuture<T>
      • NonDisposableTask
      • NonDisposableTask<T>
      • SyncContext
      • SyncContextMode
    • Neon.Temporal
      • ActivityHelper
      • ActivityLogEnricher
      • TemporalEnricherTagNames
      • WorkflowLogEnricher
    • Neon.Time
      • GatedTimer
      • GoDuration
      • PolledTimer
      • RecurringTimer
      • RecurringTimerType
      • SysTime
      • TimeOfDay
    • Neon.WSL
      • Wsl2Proxy
    • Neon.Web
      • AesProtector
      • DataProtectionExtensions
      • NeonController
      • NeonControllerBase
      • RoundTripJsonInputFormatter
      • RoundTripJsonOutputFormatter
      • TracerProviderBuilderExtensions
      • WebHelper
    • Neon.WinTTY
      • ConsoleTTY
    • Neon.Windows
      • MEMORYSTATUSEX
      • PowerShellException
      • Win32
    • Neon.XenServer
      • IXenClient
      • XenClient
      • XenClient.MachineOperations
      • XenClient.StorageOperations
      • XenClient.TemplateOperations
      • XenException
      • XenHostInfo
      • XenObject
      • XenResponse
      • XenStorageRepository
      • XenTempIso
      • XenTemplate
      • XenVirtualDisk
      • XenVirtualMachine
      • XenVmPowerState
    • Neon.Xunit
      • AnsiblePlayResults
      • AnsiblePlayer
      • AnsibleTaskResult
      • AspNetFixture
      • BasicFixture
      • CodeFixture
      • CollectionComparer<T>
      • ComposedFixture
      • ContainerFixture
      • ContainerLimits
      • DockerComposeFixture
      • DockerFixture
      • DockerFixture.ConfigInfo
      • DockerFixture.ContainerInfo
      • DockerFixture.NetworkInfo
      • DockerFixture.SecretInfo
      • DockerFixture.ServiceInfo
      • DockerFixture.StackDefinition
      • DockerFixture.StackInfo
      • DockerFixture.StackService
      • EnvironmentFixture
      • HostsFixture
      • ITestFixture
      • IncompatibleServiceException
      • MaintainerFactAttribute
      • MaintainerTheoryAttribute
      • MockHttpServer
      • MockHttpServerExtensions
      • NatsFixture
      • NatsStreamingFixture
      • NeonServiceFixture<TService>
      • PlatformFactAttribute
      • RepeatAttribute
      • TargetPlatforms
      • TestArea
      • TestCollection
      • TestContext
      • TestFixture
      • TestFixtureStatus
      • TestHelper
      • TestHttpClient
      • TestOutputWriter
      • TestTrait
      • XunitExtensions
    • Neon.Xunit.YugaByte
      • YugaByteFixture
    • Neon.YugaByte
      • YugaByteHelper

    Class Wsl2Proxy

    INTERNAL USE ONLY: Used internally for building Linux components.

    Inheritance
    object
    Wsl2Proxy
    Namespace: Neon.WSL
    Assembly: Neon.WSL.dll
    Syntax
    public sealed class Wsl2Proxy
    Remarks

    WSL2 distibutions are managed by the Microsoft wsl.exe command line tool. This includes commands to import/export, register, and terminate WSL2 Linux distributions as well as the ability to login and/or execute commands,

    wsl.exe seems to be primarily intended to be used by users performing interactive commands from within some sort of command shell like cmd.exe, Powershell, cmdr.exe, ms-terminal, etc.

    The Wsl2Proxy class wraps the wsl.exe tool such that Linux commands can be be invoked via code running on Windows. We currently use this for managing WSL2 for a local NEONDESKTOP cluster.

    Managing WSL2 Distros

    This class provides these static methods for managing distros:

    Import(string, string, string) Imports a WSL2 distro from a TAR file.
    Export(string, string) Exports a WSL2 distro to a TAR file.
    Terminate(string) Terminates the named WSL2 disto.
    Unregister(string) Unregisters the named WSL2 distribution. Note that you must Terminate(string) it first when the distro is running.
    List(bool, bool) Lists registered distributions, optionally returning only the running distros.

    Executing Commands

    To start a WSL distro, you'll need to instantiate an instance via new Wsl2Proxy(string, string), passing the registered name of the distribution and optionally the Linux user name (defaults to root). By default, the constructor logs into the distro using specified user name.

    This class provides several methods for executing commands within the distro:

    Execute(string, params object[]) Executes a command as the current user.
    ExecuteAs(string, string, params object[]) Executes a command as a specific user.
    ExecuteScript(string) Executes a script as the current user.
    ExecuteScriptAs(string, string) Executes a script as a specific user.
    SudoExecute(string, params object[]) sudo executes a command as the current user.
    SudoExecuteAs(string, string, params object[]) sudo executes a command as a specific user.
    SudoExecuteScript(string) sudo executes a script as the current user.
    SudoExecuteScriptAs(string, string) sudo executes a script as the current user.
    note

    IMPORTANT: Do not depend on the executed commands sharing the same environment variables. Also, don't depend on the Linux login having been started.

    Managing Files

    WSL2 distro file management is pretty easy because Windows mounts its file system at /mnt/DRIVE-LETTER/... within the distro so Linux code can access them and the distro files are mounted on Windows at //wsl$/DISTRO-NAME/....

    ToLinuxPath(string) Maps a host Windows file system path to the equivalent path within the Linux distro.
    ToWindowsPath(string) Maps a Linux distro file system path to the equivalent path on the Windows host.
    UploadFile(string, string, string, string, bool) Uploads a file from the Windows host to the distro, optionally setting the owner and permissions as well as optionally converting Windows style line endings (\r\n) to Linux (\n);
    note

    These file methods work when Wsl2Proxy instance regardless of whether the instance is logged into the distro or not.

    Constructors

    Wsl2Proxy(string, string)

    Constructs a proxy connected to a specific WSL2 distribution, starting the distribution by default of it's not already running.

    Declaration
    public Wsl2Proxy(string name, string user = "root")
    Parameters
    Type Name Description
    string name

    Identifies the target WSL2 distribution.

    string user

    Optionally connect as a non-root user.

    Remarks

    The user passed will become the default user for subsequent proxy operations. This may be overridden by for specific operations by specifying a different user in the call.

    Fields

    RootUser

    The name of the root Linux user.

    Declaration
    public const string RootUser = "root"
    Field Value
    Type Description
    string

    Properties

    IsDebian

    Returns true for Debian/Ubuntu based distributions.

    Declaration
    public bool IsDebian { get; }
    Property Value
    Type Description
    bool

    IsRunning

    Determines whether the distribution is running.

    Declaration
    public bool IsRunning { get; }
    Property Value
    Type Description
    bool

    IsWsl2Enabled

    Returns true if WSL2 is enabled on the local Windows workstation.

    Declaration
    public static bool IsWsl2Enabled { get; }
    Property Value
    Type Description
    bool

    Name

    Returns the distribution's name.

    Declaration
    public string Name { get; }
    Property Value
    Type Description
    string

    OSRelease

    Returns a dictionary with the properties loaded from the /etc/os-release file on the distribution.

    Declaration
    public IDictionary<string, string> OSRelease { get; }
    Property Value
    Type Description
    IDictionary<string, string>
    Remarks

    The contents will look something like:

    NAME=Ubuntu
    VERSION=20.04.1 LTS (Focal Fossa)
    ID=ubuntu
    ID_LIKE=debian
    PRETTY_NAME=Ubuntu 20.04.1 LTS
    VERSION_ID=20.04
    HOME_URL=https://www.ubuntu.com/
    SUPPORT_URL=https://help.ubuntu.com/
    BUG_REPORT_URL=https://bugs.launchpad.net/ubuntu/
    PRIVACY_POLICY_URL=https://www.ubuntu.com/legal/terms-and-policies/privacy-policy
    VERSION_CODENAME=focal
    UBUNTU_CODENAME=focal

    User

    Sppecifies the distribution user account to use for operations. This will be initialized to the user passed to the constructor but may be changed afterwards to perform operations under other accounts.

    Declaration
    public string User { get; set; }
    Property Value
    Type Description
    string

    Methods

    Dispose()

    Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.

    Declaration
    public void Dispose()

    Execute(string, params object[])

    Executes a program within the distribution as the current user.

    note

    The program will be executed within the current login session if there is one.

    Declaration
    public ExecuteResponse Execute(string path, params object[] args)
    Parameters
    Type Name Description
    string path

    The program path.

    object[] args

    Optional program arguments.

    Returns
    Type Description
    ExecuteResponse

    An ExecuteResponse with the command results.

    ExecuteAs(string, string, params object[])

    Executes a program within the distribution as a specific user.

    Declaration
    public ExecuteResponse ExecuteAs(string user, string path, params object[] args)
    Parameters
    Type Name Description
    string user

    The user.

    string path

    The program path.

    object[] args

    Optional program arguments.

    Returns
    Type Description
    ExecuteResponse

    An ExecuteResponse with the command results.

    ExecuteScript(string)

    Executes a bash script on the distribution as the current user.

    note

    The script will be executed within the current login session if there is one.

    Declaration
    public ExecuteResponse ExecuteScript(string script)
    Parameters
    Type Name Description
    string script

    The script text.

    Returns
    Type Description
    ExecuteResponse

    An ExecuteResponse with the command results.

    ExecuteScriptAs(string, string)

    Executes a bash script on the distribution as a specific user.

    Declaration
    public ExecuteResponse ExecuteScriptAs(string user, string script)
    Parameters
    Type Name Description
    string user

    The user.

    string script

    The script text.

    Returns
    Type Description
    ExecuteResponse

    An ExecuteResponse with the command results.

    Exists(string)

    Checks to see if a named distribution exists.

    Declaration
    public static bool Exists(string name)
    Parameters
    Type Name Description
    string name

    The distribution name.

    Returns
    Type Description
    bool

    true if the distribution exists.

    Export(string, string)

    Exports a named distribution to a TAR file.

    Declaration
    public static void Export(string name, string tarPath)
    Parameters
    Type Name Description
    string name

    The new distribution's name.

    string tarPath

    Path to the distribution output TAR file.

    GetDefault()

    Returns the name of the default WSL2 distribution, if any.

    Declaration
    public static string GetDefault()
    Returns
    Type Description
    string

    The name of the default distribution or null.

    Import(string, string, string)

    Imports a distribution from a TAR file.

    Declaration
    public static void Import(string name, string tarPath, string targetFolder)
    Parameters
    Type Name Description
    string name

    The new distribution's name.

    string tarPath

    Path to the distribution input TAR file.

    string targetFolder

    Path to the folder where the distribution image will be created.

    IsPortListening(int)

    Determines whether a WSL2 IPv4 port is currently listening for connections.

    Declaration
    public bool IsPortListening(int port)
    Parameters
    Type Name Description
    int port

    The port number.

    Returns
    Type Description
    bool

    true if the port is available.

    Remarks

    This is useful for ensuring that another distro hasn't started listening on a port that's going to conflict with this distro. This can happen because all WSL2 distros share the same network namespace. This can also happen when a Windows process is listening on the port.

    List(bool, bool)

    Lists the names of the installed WSL2 distributions, optionally limiting this to the running distributions.

    Declaration
    public static IEnumerable<string> List(bool runningOnly = false, bool keepDefault = false)
    Parameters
    Type Name Description
    bool runningOnly

    Optionally return just the running distribitions.

    bool keepDefault

    Optionally retain the " (Default)" substring identifying the default repo.

    Returns
    Type Description
    IEnumerable<string>

    The list of WSL2 distributions.

    SudoExecute(string, params object[])

    Executes a program within the distribution as the current user under SUDO.

    note

    The program will be executed within the current login session if there is one.

    Declaration
    public ExecuteResponse SudoExecute(string path, params object[] args)
    Parameters
    Type Name Description
    string path

    The program path.

    object[] args

    Optional program arguments.

    Returns
    Type Description
    ExecuteResponse

    An ExecuteResponse with the command results.

    SudoExecuteAs(string, string, params object[])

    Executes a program within the distribution as a specifc user under SUDO.

    Declaration
    public ExecuteResponse SudoExecuteAs(string user, string path, params object[] args)
    Parameters
    Type Name Description
    string user

    The user.

    string path

    The program path.

    object[] args

    Optional pprogram arguments.

    Returns
    Type Description
    ExecuteResponse

    An ExecuteResponse with the command results.

    SudoExecuteScript(string)

    Executes a bash script as SUDO on the distribution as the current user.

    note

    The script will be executed within the current login session if there is one.

    Declaration
    public ExecuteResponse SudoExecuteScript(string script)
    Parameters
    Type Name Description
    string script

    The script text.

    Returns
    Type Description
    ExecuteResponse

    An ExecuteResponse with the command results.

    SudoExecuteScriptAs(string, string)

    Executes a bash script as SUDO on the distribution as a specific user.

    Declaration
    public ExecuteResponse SudoExecuteScriptAs(string user, string script)
    Parameters
    Type Name Description
    string user

    The user.

    string script

    The script text.

    Returns
    Type Description
    ExecuteResponse

    An ExecuteResponse with the command results.

    Terminate()

    Terminates the distribution if it's running.

    Declaration
    public void Terminate()

    Terminate(string)

    Terminates the named distribution if it exists and is running.

    Declaration
    public static void Terminate(string name)
    Parameters
    Type Name Description
    string name

    Identifies the target WSL2 distribution.

    ToLinuxPath(string)

    Maps a fully qualified Windows host filesystem path to the corresponding path within the Linux distribution.

    Declaration
    public string ToLinuxPath(string windowsPath)
    Parameters
    Type Name Description
    string windowsPath

    The fully qualified host Windows path.

    Returns
    Type Description
    string

    The corresponding Windows host path.

    ToWindowsPath(string)

    Maps a fully qualified filesystem path within the Linux distribution to the corresponding Windows filesystem path on the host machine.

    Declaration
    public string ToWindowsPath(string linuxPath)
    Parameters
    Type Name Description
    string linuxPath

    The fully qualified internal Linux path.

    Returns
    Type Description
    string

    The corresponding Linux path.

    Remarks
    note

    This assumes that the internal Linux path includes only characters supported by Windows.

    Unregister(string)

    Terminates the named distribution (if it exists ans is running) and then unregisters it with WSL2 effectively removing it.

    Declaration
    public static void Unregister(string name)
    Parameters
    Type Name Description
    string name

    Identifies the target WSL2 distribution.

    UploadFile(string, string, string, string, bool)

    Creates a text file at the specifid path within the distribution. The file will be created with the current User as the owner by default by this can be overridden.

    Declaration
    public void UploadFile(string path, string text, string owner = null, string permissions = null, bool toLinuxText = false)
    Parameters
    Type Name Description
    string path

    The target path.

    string text

    The text to be written.

    string owner

    Optionally overrides the current user when setting the file owner.

    string permissions

    Optionally specifies the linux file permissions.

    bool toLinuxText

    Optionally convertes conversion of Windows (CRLF) line endings to the Linux standard (LF).

    In this article
    Back to top © Copyright 2005-2023 by NEONFORGE LLC