Struct netcorehost::hostfxr::Hostfxr
source · 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
impl Hostfxr
sourcepub fn load_from_path(path: impl AsRef<Path>) -> Result<Self, Error>
pub fn load_from_path(path: impl AsRef<Path>) -> Result<Self, Error>
Loads the hostfxr library from the given path.
sourcepub fn load_with_nethost() -> Result<Self, LoadHostfxrError>
pub fn load_with_nethost() -> Result<Self, LoadHostfxrError>
Locates the hostfxr library using nethost
and loads it.
sourcepub fn get_dotnet_root(&self) -> PathBuf
pub fn get_dotnet_root(&self) -> PathBuf
Returns the path to the dotnet root.
sourcepub fn get_dotnet_exe(&self) -> PathBuf
pub fn get_dotnet_exe(&self) -> PathBuf
Returns the path to the dotnet executable of the same installation as hostfxr.
source§impl Hostfxr
impl Hostfxr
sourcepub fn run_app(&self, app_path: &PdCStr) -> AppOrHostingResult
👎Deprecated: Use HostfxrContext::run_app
insteadAvailable on crate feature netcore1_0
only.
pub fn run_app(&self, app_path: &PdCStr) -> AppOrHostingResult
HostfxrContext::run_app
insteadnetcore1_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.
sourcepub fn run_app_with_args<A: AsRef<PdCStr>>(
&self,
app_path: &PdCStr,
args: &[A]
) -> AppOrHostingResult
👎Deprecated: Use HostfxrContext::run_app
insteadAvailable on crate feature netcore1_0
only.
pub fn run_app_with_args<A: AsRef<PdCStr>>( &self, app_path: &PdCStr, args: &[A] ) -> AppOrHostingResult
HostfxrContext::run_app
insteadnetcore1_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
impl Hostfxr
sourcepub 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
insteadAvailable on crate feature netcore2_1
only.
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>
HostfxrContext::run_app
insteadnetcore2_1
only.Run an application.
§Arguments
app_path
path to the application to runargs
command-line argumentshost_path
path to the host applicationdotnet_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.
sourcepub fn resolve_sdk(
&self,
sdk_dir: &PdCStr,
working_dir: &PdCStr,
allow_prerelease: bool
) -> Result<ResolveSdkResult, HostingError>
Available on crate feature netcore2_1
only.
pub fn resolve_sdk( &self, sdk_dir: &PdCStr, working_dir: &PdCStr, allow_prerelease: bool ) -> Result<ResolveSdkResult, HostingError>
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 insdk\[version]
sub-folders.working_dir
- directory where the search forglobal.json
will start and proceed upwardsallow_prerelease
- allow resolution to return a pre-release SDK version
sourcepub fn get_available_sdks(&self) -> Vec<PathBuf>
Available on crate feature netcore2_1
only.
pub fn get_available_sdks(&self) -> Vec<PathBuf>
netcore2_1
only.Get the list of all available SDKs ordered by ascending version.
sourcepub fn get_available_sdks_with_dotnet_path(
&self,
dotnet_path: &PdCStr
) -> Vec<PathBuf>
Available on crate feature netcore2_1
only.
pub fn get_available_sdks_with_dotnet_path( &self, dotnet_path: &PdCStr ) -> Vec<PathBuf>
netcore2_1
only.Get the list of all available SDKs ordered by ascending version, based on the provided dotnet
executable.
sourcepub fn get_native_search_directories(
&self,
app_path: &PdCStr
) -> Result<Vec<PathBuf>, HostingError>
Available on crate feature netcore2_1
only.
pub fn get_native_search_directories( &self, app_path: &PdCStr ) -> Result<Vec<PathBuf>, HostingError>
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
impl Hostfxr
sourcepub fn initialize_for_dotnet_command_line(
&self,
app_path: impl AsRef<PdCStr>
) -> Result<HostfxrContext<InitializedForCommandLine>, HostingError>
Available on crate feature netcore3_0
only.
pub fn initialize_for_dotnet_command_line( &self, app_path: impl AsRef<PdCStr> ) -> Result<HostfxrContext<InitializedForCommandLine>, HostingError>
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.
sourcepub 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.
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>
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 theCoreCLR
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 thecomhost.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.
sourcepub 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.
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>
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 toC:\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.
sourcepub 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.
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>
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.
sourcepub 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.
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>
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 theCoreCLR
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 thecomhost.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.
sourcepub 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.
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>
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 toC:\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.
sourcepub fn initialize_for_runtime_config(
&self,
runtime_config_path: impl AsRef<PdCStr>
) -> Result<HostfxrContext<InitializedForRuntimeConfig>, HostingError>
Available on crate feature netcore3_0
only.
pub fn initialize_for_runtime_config( &self, runtime_config_path: impl AsRef<PdCStr> ) -> Result<HostfxrContext<InitializedForRuntimeConfig>, HostingError>
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 withinitialize_for_dotnet_command_line
, any.deps.json
from the app/component will not be processed by the hosting layers.
sourcepub 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.
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>
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 withinitialize_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 theCoreCLR
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 thecomhost.dll
). This is used by PAL to initialize internal command line structures, process name and so on.
sourcepub 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.
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>
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 withinitialize_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 toC:\Program Files\dotnet
. The path is used to search for shared frameworks and potentially SDKs.
source§impl Hostfxr
impl Hostfxr
sourcepub fn get_dotnet_environment_info(
&self
) -> Result<EnvironmentInfo, HostingError>
Available on crate feature net6_0
only.
pub fn get_dotnet_environment_info( &self ) -> Result<EnvironmentInfo, HostingError>
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.