diff --git a/src/corehost/common/pal.unix.cpp b/src/corehost/common/pal.unix.cpp index ead8034d8..b060afcc0 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 #if defined(__APPLE__) #include @@ -83,12 +86,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 d70bd60e9..8a7a9a960 100644 --- a/src/corehost/common/pal.windows.cpp +++ b/src/corehost/common/pal.windows.cpp @@ -14,7 +14,6 @@ static std::wstring_convert, wchar_t> g_converter; 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)) { @@ -27,7 +26,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; }