diff --git a/src/corehost/common/pal.unix.cpp b/src/corehost/common/pal.unix.cpp index 171820e36..b7cf9caf0 100644 --- a/src/corehost/common/pal.unix.cpp +++ b/src/corehost/common/pal.unix.cpp @@ -9,6 +9,9 @@ #include #include #include +#include +#include +#include #include @@ -112,12 +115,22 @@ bool pal::is_path_rooted(const pal::string_t& path) bool pal::get_default_packages_directory(pal::string_t* recv) { recv->clear(); - if (!pal::getenv("HOME", recv)) + pal::string_t dir; + if (!pal::getenv("HOME", &dir)) + { + struct passwd* pw = getpwuid(getuid()); + if (pw && pw->pw_dir) + { + dir.assign(pw->pw_dir); + } + } + if (dir.empty()) { return false; } - append_path(&*recv, _X(".nuget")); - append_path(&*recv, _X("packages")); + append_path(&dir, _X(".nuget")); + append_path(&dir, _X("packages")); + recv->assign(dir); return true; } diff --git a/src/corehost/common/pal.windows.cpp b/src/corehost/common/pal.windows.cpp index a5ce39c7f..fc03c40ed 100644 --- a/src/corehost/common/pal.windows.cpp +++ b/src/corehost/common/pal.windows.cpp @@ -26,7 +26,6 @@ pal::string_t pal::to_string(int value) bool pal::find_coreclr(pal::string_t* recv) { pal::string_t candidate; - pal::string_t test; // Try %LocalAppData%\dotnet if (pal::getenv(_X("LocalAppData"), &candidate)) { @@ -39,7 +38,19 @@ bool pal::find_coreclr(pal::string_t* recv) } } - // TODO: Try somewhere in Program Files, see https://github.com/dotnet/cli/issues/249 + + // Try %ProgramFiles%. Note this works for both x86 and x64/wow64 as per: + // https://msdn.microsoft.com/en-us/library/windows/desktop/aa384274(v=vs.85).aspx + + // candidate.clear(); getenv clears it. + if (pal::getenv(_X("ProgramFiles"), &candidate)) { + append_path(&candidate, _X("dotnet")); + append_path(&candidate, _X("bin")); + if (coreclr_exists_in_dir(candidate)) { + recv->assign(candidate); + return true; + } + } return false; }