Skip to content

Commit da1517b

Browse files
committed
Try to fix ci
1 parent 6b34bc6 commit da1517b

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

src/hostfxr/library.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,16 @@ impl Hostfxr {
6262
pub fn load_with_nethost() -> Result<Self, LoadHostfxrError> {
6363
crate::nethost::load_hostfxr()
6464
}
65+
66+
/// Returns the path to the dotnet root.
67+
pub fn get_dotnet_root(&self) -> PathBuf {
68+
self.get_dotnet_exe().parent().unwrap().to_owned()
69+
}
70+
71+
/// Returns the path to the dotnet executable of the same installation as hostfxr.
72+
pub fn get_dotnet_exe(&self) -> PathBuf {
73+
self.dotnet_exe.to_os_string().into()
74+
}
6575
}
6676

6777
/// Either the exit code of the app if it ran successful, otherwise the error from the hosting components.

src/hostfxr/library6_0.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use hostfxr_sys::hostfxr_dotnet_environment_info;
33
use crate::{
44
error::{HostingError, HostingResult},
55
hostfxr::Hostfxr,
6-
pdcstring::PdCStr,
6+
pdcstring::{PdCStr, PdCString},
77
};
88
use std::{ffi::c_void, mem::MaybeUninit, path::PathBuf, ptr, slice};
99

@@ -104,10 +104,12 @@ impl Hostfxr {
104104
/// then it will also enumerate SDKs and frameworks from the global install location.
105105
#[cfg_attr(feature = "doc-cfg", doc(cfg(feature = "net6_0")))]
106106
pub fn get_dotnet_environment_info(&self) -> Result<EnvironmentInfo, HostingError> {
107+
let dotnet_root = PdCString::from_os_str(self.get_dotnet_root()).ok();
108+
let dotnet_root_ptr = dotnet_root.as_ref().map_or_else(ptr::null, |p| p.as_ptr());
107109
let mut info = MaybeUninit::<EnvironmentInfo>::uninit();
108110
let result = unsafe {
109111
self.lib.hostfxr_get_dotnet_environment_info(
110-
ptr::null(),
112+
dotnet_root_ptr,
111113
ptr::null_mut(),
112114
get_dotnet_environment_info_callback,
113115
info.as_mut_ptr().cast(),

0 commit comments

Comments
 (0)