1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
use crate::{
hostfxr::{AppOrHostingResult, Hostfxr},
pdcstring::PdCStr,
};
use super::UNSUPPORTED_HOST_VERSION_ERROR_CODE;
impl Hostfxr {
/// 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.
#[cfg_attr(
feature = "netcore3_0",
deprecated(note = "Use `HostfxrContext::run_app` instead"),
allow(deprecated)
)]
#[cfg_attr(feature = "doc-cfg", doc(cfg(feature = "netcore1_0")))]
#[must_use]
pub fn run_app(&self, app_path: &PdCStr) -> AppOrHostingResult {
self.run_app_with_args::<&PdCStr>(app_path, &[])
}
/// 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.
#[cfg_attr(
feature = "netcore3_0",
deprecated(note = "Use `HostfxrContext::run_app` instead")
)]
#[cfg_attr(feature = "doc-cfg", doc(cfg(feature = "netcore1_0")))]
pub fn run_app_with_args<A: AsRef<PdCStr>>(
&self,
app_path: &PdCStr,
args: &[A],
) -> AppOrHostingResult {
let args = [&self.dotnet_exe, app_path]
.into_iter()
.chain(args.iter().map(|s| s.as_ref()))
.map(|s| s.as_ptr())
.collect::<Vec<_>>();
let result = unsafe {
self.lib
.hostfxr_main(args.len().try_into().unwrap(), args.as_ptr())
}
.unwrap_or(UNSUPPORTED_HOST_VERSION_ERROR_CODE);
AppOrHostingResult::from(result)
}
}