pub struct Hostfxr {
    pub lib: Arc<Container<Hostfxr>>,
    /* private fields */
}
Expand description

A struct representing a loaded hostfxr library.

Fields§

§lib: Arc<Container<Hostfxr>>

The underlying hostfxr library.

Implementations§

source§

impl Hostfxr

source

pub fn load_from_path(path: impl AsRef<Path>) -> Result<Self, Error>

Loads the hostfxr library from the given path.

source

pub fn load_with_nethost() -> Result<Self, LoadHostfxrError>

Locates the hostfxr library using nethost and loads it.

source

pub fn get_dotnet_root(&self) -> PathBuf

Returns the path to the dotnet root.

source

pub fn get_dotnet_exe(&self) -> PathBuf

Returns the path to the dotnet executable of the same installation as hostfxr.

source§

impl Hostfxr

source

pub fn run_app(&self, app_path: &PdCStr) -> AppOrHostingResult

👎Deprecated: Use HostfxrContext::run_app instead
Available on crate feature netcore1_0 only.

Run an application.

§Note

This function does not return until the application completes execution. It will shutdown CoreCLR after the application executes. If the application is successfully executed, this value will return the exit code of the application. Otherwise, it will return an error code indicating the failure.

source

pub fn run_app_with_args<A: AsRef<PdCStr>>( &self, app_path: &PdCStr, args: &[A] ) -> AppOrHostingResult

👎Deprecated: Use HostfxrContext::run_app instead
Available on crate feature netcore1_0 only.

Run an application with the specified arguments.

§Note

This function does not return until the application completes execution. It will shutdown CoreCLR after the application executes. If the application is successfully executed, this value will return the exit code of the application. Otherwise, it will return an error code indicating the failure.

source§

impl Hostfxr

source

pub fn run_app_with_args_and_startup_info<'a, A: AsRef<PdCStr>>( &'a self, app_path: &'a PdCStr, args: impl IntoIterator<Item = &'a PdCStr>, host_path: &PdCStr, dotnet_root: &PdCStr ) -> Result<AppOrHostingResult>

👎Deprecated: Use HostfxrContext::run_app instead
Available on crate feature netcore2_1 only.

Run an application.

§Arguments
  • app_path path to the application to run
  • args command-line arguments
  • host_path path to the host application
  • dotnet_root path to the .NET Core installation root

This function does not return until the application completes execution. It will shutdown CoreCLR after the application executes. If the application is successfully executed, this value will return the exit code of the application. Otherwise, it will return an error code indicating the failure.

source

pub fn resolve_sdk( &self, sdk_dir: &PdCStr, working_dir: &PdCStr, allow_prerelease: bool ) -> Result<ResolveSdkResult, HostingError>

Available on crate feature netcore2_1 only.

Determine the directory location of the SDK, accounting for global.json and multi-level lookup policy.

§Arguments
  • sdk_dir - main directory where SDKs are located in sdk\[version] sub-folders.
  • working_dir - directory where the search for global.json will start and proceed upwards
  • allow_prerelease - allow resolution to return a pre-release SDK version
source

pub fn get_available_sdks(&self) -> Vec<PathBuf>

Available on crate feature netcore2_1 only.

Get the list of all available SDKs ordered by ascending version.

source

pub fn get_available_sdks_with_dotnet_path( &self, dotnet_path: &PdCStr ) -> Vec<PathBuf>

Available on crate feature netcore2_1 only.

Get the list of all available SDKs ordered by ascending version, based on the provided dotnet executable.

source

pub fn get_native_search_directories( &self, app_path: &PdCStr ) -> Result<Vec<PathBuf>, HostingError>

Available on crate feature netcore2_1 only.

Get the native search directories of the runtime based upon the specified app.

§Arguments
  • app_path - path to application
source§

impl Hostfxr

source

pub fn initialize_for_dotnet_command_line( &self, app_path: impl AsRef<PdCStr> ) -> Result<HostfxrContext<InitializedForCommandLine>, HostingError>

Available on crate feature netcore3_0 only.

Initializes the hosting components for a dotnet command line running an application

Like all the other initialize functions, this function will

  • Process the .runtimeconfig.json
  • Resolve framework references and find actual frameworks
  • Find the root framework (Microsoft.NETCore.App) and load the hostpolicy from it
  • The hostpolicy will then process all relevant .deps.json files and produce the list of assemblies, native search paths and other artifacts needed to initialize the runtime.

The functions will NOT load the CoreCLR runtime. They just prepare everything to the point where it can be loaded.

§Arguments
  • app_path: The path to the target application.
§Remarks

This function parses the specified command-line arguments to determine the application to run. It will then find the corresponding .runtimeconfig.json and .deps.json with which to resolve frameworks and dependencies and prepare everything needed to load the runtime.

source

pub fn initialize_for_dotnet_command_line_with_host_path( &self, app_path: impl AsRef<PdCStr>, host_path: impl AsRef<PdCStr> ) -> Result<HostfxrContext<InitializedForCommandLine>, HostingError>

Available on crate feature netcore3_0 only.

Initializes the hosting components for a dotnet command line running an application

Like all the other initialize functions, this function will

  • Process the .runtimeconfig.json
  • Resolve framework references and find actual frameworks
  • Find the root framework (Microsoft.NETCore.App) and load the hostpolicy from it
  • The hostpolicy will then process all relevant .deps.json files and produce the list of assemblies, native search paths and other artifacts needed to initialize the runtime.

The functions will NOT load the CoreCLR runtime. They just prepare everything to the point where it can be loaded.

§Arguments
  • app_path: The path to the target application.
  • host_path: Path to the native host (typically the .exe). This value is not used for anything by the hosting components. It’s just passed to the CoreCLR as the path to the executable. It can point to a file which is not executable itself, if such file doesn’t exist (for example in COM activation scenarios this points to the comhost.dll). This is used by PAL to initialize internal command line structures, process name and so on.
§Remarks

This function parses the specified command-line arguments to determine the application to run. It will then find the corresponding .runtimeconfig.json and .deps.json with which to resolve frameworks and dependencies and prepare everything needed to load the runtime.

source

pub fn initialize_for_dotnet_command_line_with_dotnet_root( &self, app_path: impl AsRef<PdCStr>, dotnet_root: impl AsRef<PdCStr> ) -> Result<HostfxrContext<InitializedForCommandLine>, HostingError>

Available on crate feature netcore3_0 only.

Initializes the hosting components for a dotnet command line running an application

Like all the other initialize functions, this function will

  • Process the .runtimeconfig.json
  • Resolve framework references and find actual frameworks
  • Find the root framework (Microsoft.NETCore.App) and load the hostpolicy from it
  • The hostpolicy will then process all relevant .deps.json files and produce the list of assemblies, native search paths and other artifacts needed to initialize the runtime.

The functions will NOT load the CoreCLR runtime. They just prepare everything to the point where it can be loaded.

§Arguments
  • app_path: The path to the target application.
  • dotnet_root: Path to the root of the .NET Core installation in use. This typically points to the install location from which the hostfxr has been loaded. For example on Windows this would typically point to C:\Program Files\dotnet. The path is used to search for shared frameworks and potentially SDKs.
§Remarks

This function parses the specified command-line arguments to determine the application to run. It will then find the corresponding .runtimeconfig.json and .deps.json with which to resolve frameworks and dependencies and prepare everything needed to load the runtime.

source

pub fn initialize_for_dotnet_command_line_with_args( &self, app_path: impl AsRef<PdCStr>, args: impl Iterator<Item = impl AsRef<PdCStr>> ) -> Result<HostfxrContext<InitializedForCommandLine>, HostingError>

Available on crate feature netcore3_0 only.

Initializes the hosting components for a dotnet command line running an application

Like all the other initialize functions, this function will

  • Process the .runtimeconfig.json
  • Resolve framework references and find actual frameworks
  • Find the root framework (Microsoft.NETCore.App) and load the hostpolicy from it
  • The hostpolicy will then process all relevant .deps.json files and produce the list of assemblies, native search paths and other artifacts needed to initialize the runtime.

The functions will NOT load the CoreCLR runtime. They just prepare everything to the point where it can be loaded.

§Arguments
  • app_path: The path to the target application.
  • args: The command line arguments for the managed application.
§Remarks

This function parses the specified command-line arguments to determine the application to run. It will then find the corresponding .runtimeconfig.json and .deps.json with which to resolve frameworks and dependencies and prepare everything needed to load the runtime.

source

pub fn initialize_for_dotnet_command_line_with_args_and_host_path( &self, app_path: impl AsRef<PdCStr>, args: impl Iterator<Item = impl AsRef<PdCStr>>, host_path: impl AsRef<PdCStr> ) -> Result<HostfxrContext<InitializedForCommandLine>, HostingError>

Available on crate feature netcore3_0 only.

Initializes the hosting components for a dotnet command line running an application

Like all the other initialize functions, this function will

  • Process the .runtimeconfig.json
  • Resolve framework references and find actual frameworks
  • Find the root framework (Microsoft.NETCore.App) and load the hostpolicy from it
  • The hostpolicy will then process all relevant .deps.json files and produce the list of assemblies, native search paths and other artifacts needed to initialize the runtime.

The functions will NOT load the CoreCLR runtime. They just prepare everything to the point where it can be loaded.

§Arguments
  • app_path: The path to the target application.
  • args: The command line arguments for the managed application.
  • host_path: Path to the native host (typically the .exe). This value is not used for anything by the hosting components. It’s just passed to the CoreCLR as the path to the executable. It can point to a file which is not executable itself, if such file doesn’t exist (for example in COM activation scenarios this points to the comhost.dll). This is used by PAL to initialize internal command line structures, process name and so on.
§Remarks

This function parses the specified command-line arguments to determine the application to run. It will then find the corresponding .runtimeconfig.json and .deps.json with which to resolve frameworks and dependencies and prepare everything needed to load the runtime.

source

pub fn initialize_for_dotnet_command_line_with_args_and_dotnet_root( &self, app_path: impl AsRef<PdCStr>, args: impl Iterator<Item = impl AsRef<PdCStr>>, dotnet_root: impl AsRef<PdCStr> ) -> Result<HostfxrContext<InitializedForCommandLine>, HostingError>

Available on crate feature netcore3_0 only.

Initializes the hosting components for a dotnet command line running an application

Like all the other initialize functions, this function will

  • Process the .runtimeconfig.json
  • Resolve framework references and find actual frameworks
  • Find the root framework (Microsoft.NETCore.App) and load the hostpolicy from it
  • The hostpolicy will then process all relevant .deps.json files and produce the list of assemblies, native search paths and other artifacts needed to initialize the runtime.

The functions will NOT load the CoreCLR runtime. They just prepare everything to the point where it can be loaded.

§Arguments
  • app_path: The path to the target application.
  • args: The command line arguments for the managed application.
  • dotnet_root: Path to the root of the .NET Core installation in use. This typically points to the install location from which the hostfxr has been loaded. For example on Windows this would typically point to C:\Program Files\dotnet. The path is used to search for shared frameworks and potentially SDKs.
§Remarks

This function parses the specified command-line arguments to determine the application to run. It will then find the corresponding .runtimeconfig.json and .deps.json with which to resolve frameworks and dependencies and prepare everything needed to load the runtime.

source

pub fn initialize_for_runtime_config( &self, runtime_config_path: impl AsRef<PdCStr> ) -> Result<HostfxrContext<InitializedForRuntimeConfig>, HostingError>

Available on crate feature netcore3_0 only.

This function loads the specified .runtimeconfig.json, resolve all frameworks, resolve all the assets from those frameworks and then prepare runtime initialization where the TPA contains only frameworks. Note that this case does NOT consume any .deps.json from the app/component (only processes the framework’s .deps.json).

Like all the other initialize functions, this function will

  • Process the .runtimeconfig.json
  • Resolve framework references and find actual frameworks
  • Find the root framework (Microsoft.NETCore.App) and load the hostpolicy from it
  • The hostpolicy will then process all relevant .deps.json files and produce the list of assemblies, native search paths and other artifacts needed to initialize the runtime.

The functions will NOT load the CoreCLR runtime. They just prepare everything to the point where it can be loaded.

§Arguments
  • runtime_config_path: Path to the .runtimeconfig.json file to process. Unlike with initialize_for_dotnet_command_line, any .deps.json from the app/component will not be processed by the hosting layers.
source

pub fn initialize_for_runtime_config_with_host_path( &self, runtime_config_path: impl AsRef<PdCStr>, host_path: impl AsRef<PdCStr> ) -> Result<HostfxrContext<InitializedForRuntimeConfig>, HostingError>

Available on crate feature netcore3_0 only.

This function loads the specified .runtimeconfig.json, resolve all frameworks, resolve all the assets from those frameworks and then prepare runtime initialization where the TPA contains only frameworks. Note that this case does NOT consume any .deps.json from the app/component (only processes the framework’s .deps.json).

Like all the other initialize functions, this function will

  • Process the .runtimeconfig.json
  • Resolve framework references and find actual frameworks
  • Find the root framework (Microsoft.NETCore.App) and load the hostpolicy from it
  • The hostpolicy will then process all relevant .deps.json files and produce the list of assemblies, native search paths and other artifacts needed to initialize the runtime.

The functions will NOT load the CoreCLR runtime. They just prepare everything to the point where it can be loaded.

§Arguments
  • runtime_config_path: Path to the .runtimeconfig.json file to process. Unlike with initialize_for_dotnet_command_line, any .deps.json from the app/component will not be processed by the hosting layers.
  • host_path: Path to the native host (typically the .exe). This value is not used for anything by the hosting components. It’s just passed to the CoreCLR as the path to the executable. It can point to a file which is not executable itself, if such file doesn’t exist (for example in COM activation scenarios this points to the comhost.dll). This is used by PAL to initialize internal command line structures, process name and so on.
source

pub fn initialize_for_runtime_config_with_dotnet_root( &self, runtime_config_path: impl AsRef<PdCStr>, dotnet_root: impl AsRef<PdCStr> ) -> Result<HostfxrContext<InitializedForRuntimeConfig>, HostingError>

Available on crate feature netcore3_0 only.

This function loads the specified .runtimeconfig.json, resolve all frameworks, resolve all the assets from those frameworks and then prepare runtime initialization where the TPA contains only frameworks. Note that this case does NOT consume any .deps.json from the app/component (only processes the framework’s .deps.json).

Like all the other initialize functions, this function will

  • Process the .runtimeconfig.json
  • Resolve framework references and find actual frameworks
  • Find the root framework (Microsoft.NETCore.App) and load the hostpolicy from it
  • The hostpolicy will then process all relevant .deps.json files and produce the list of assemblies, native search paths and other artifacts needed to initialize the runtime.

The functions will NOT load the CoreCLR runtime. They just prepare everything to the point where it can be loaded.

§Arguments
  • runtime_config_path: Path to the .runtimeconfig.json file to process. Unlike with initialize_for_dotnet_command_line, any .deps.json from the app/component will not be processed by the hosting layers.
  • dotnet_root: Path to the root of the .NET Core installation in use. This typically points to the install location from which the hostfxr has been loaded. For example on Windows this would typically point to C:\Program Files\dotnet. The path is used to search for shared frameworks and potentially SDKs.
source§

impl Hostfxr

source

pub fn get_dotnet_environment_info( &self ) -> Result<EnvironmentInfo, HostingError>

Available on crate feature net6_0 only.

Loads info about the dotnet environemnt, including the version of hostfxr and installed sdks and frameworks.

§Ordering

SDks are ordered by version ascending and multi-level lookup locations are put before private locations - items later in the list have priority over items earlier in the list. Frameworks are ordered by name ascending followed by version ascending. Multi-level lookup locations are put before private locations.

§Note

This is equivalent to the info retrieved using dotnet --info. Which means it enumerates SDKs and frameworks from the dotnet root directory (either explicitly specified or using global install location per design). If DOTNET_MULTILEVEL_LOOKUP is enabled (Windows-only), and the dotnet root is specified and it’s not the global install location, then it will also enumerate SDKs and frameworks from the global install location.

Trait Implementations§

source§

impl Clone for Hostfxr

source§

fn clone(&self) -> Hostfxr

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl From<(Arc<Container<Hostfxr>>, PdCString)> for Hostfxr

source§

fn from(original: (Arc<Container<Hostfxr>>, PdCString)) -> Hostfxr

Converts to this type from the input type.

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.