Просмотр исходного кода

Looking for WinSCP.exe also in entry .NET assembly folder

To support running in .NET Core applications from Visual Studio that use NuGet packages installed in user profile folder

Source commit: 9a28e66ce1b771a3b18d0a08b7efd039193ba6b2
Martin Prikryl 6 лет назад
Родитель
Сommit
30a29416ac
2 измененных файлов с 25 добавлено и 3 удалено
  1. 13 3
      dotnet/internal/ExeSessionProcess.cs
  2. 12 0
      dotnet/internal/Logger.cs

+ 13 - 3
dotnet/internal/ExeSessionProcess.cs

@@ -842,6 +842,7 @@ namespace WinSCP
                 else
                 else
                 {
                 {
                     if (!TryFindExecutableInPath(GetAssemblyPath(), out executablePath) &&
                     if (!TryFindExecutableInPath(GetAssemblyPath(), out executablePath) &&
+                        !TryFindExecutableInPath(GetEntryAssemblyPath(), out executablePath) &&
 #if !NETSTANDARD
 #if !NETSTANDARD
                         !TryFindExecutableInPath(GetInstallationPath(RegistryHive.CurrentUser), out executablePath) &&
                         !TryFindExecutableInPath(GetInstallationPath(RegistryHive.CurrentUser), out executablePath) &&
                         !TryFindExecutableInPath(GetInstallationPath(RegistryHive.LocalMachine), out executablePath) &&
                         !TryFindExecutableInPath(GetInstallationPath(RegistryHive.LocalMachine), out executablePath) &&
@@ -851,8 +852,8 @@ namespace WinSCP
                         throw _logger.WriteException(
                         throw _logger.WriteException(
                             new SessionLocalException(_session,
                             new SessionLocalException(_session,
                                 string.Format(CultureInfo.CurrentCulture,
                                 string.Format(CultureInfo.CurrentCulture,
-                                    "The {0} executable was not found at location of the assembly ({1}), nor in an installation path. You may use Session.ExecutablePath property to explicitly set path to {0}.",
-                                    ExeExecutableFileName, GetAssemblyPath())));
+                                    "The {0} executable was not found at location of the assembly {1} ({2}), nor the executing assembly {3} ({4}), nor in an installation path. You may use Session.ExecutablePath property to explicitly set path to {0}.",
+                                    ExeExecutableFileName, Assembly.GetExecutingAssembly(), GetAssemblyPath(), Assembly.GetEntryAssembly(), GetEntryAssemblyPath())));
                     }
                     }
                 }
                 }
                 return executablePath;
                 return executablePath;
@@ -908,7 +909,16 @@ namespace WinSCP
 
 
         private string GetAssemblyPath()
         private string GetAssemblyPath()
         {
         {
-            string codeBasePath = _logger.GetAssemblyFilePath();
+            return DoGetAssemblyPath(_logger.GetAssemblyFilePath());
+        }
+
+        private string GetEntryAssemblyPath()
+        {
+            return DoGetAssemblyPath(_logger.GetEntryAssemblyFilePath());
+        }
+
+        private static string DoGetAssemblyPath(string codeBasePath)
+        {
             string path = null;
             string path = null;
             if (!string.IsNullOrEmpty(codeBasePath))
             if (!string.IsNullOrEmpty(codeBasePath))
             {
             {

+ 12 - 0
dotnet/internal/Logger.cs

@@ -19,6 +19,17 @@ namespace WinSCP
         public string GetAssemblyFilePath()
         public string GetAssemblyFilePath()
         {
         {
             Assembly assembly = Assembly.GetExecutingAssembly();
             Assembly assembly = Assembly.GetExecutingAssembly();
+            return DoGetAssemblyFilePath(assembly);
+        }
+
+        public string GetEntryAssemblyFilePath()
+        {
+            Assembly assembly = Assembly.GetEntryAssembly();
+            return DoGetAssemblyFilePath(assembly);
+        }
+
+        private string DoGetAssemblyFilePath(Assembly assembly)
+        {
             string path = null;
             string path = null;
 
 
             // https://blogs.msdn.microsoft.com/suzcook/2003/06/26/assembly-codebase-vs-assembly-location/
             // https://blogs.msdn.microsoft.com/suzcook/2003/06/26/assembly-codebase-vs-assembly-location/
@@ -369,6 +380,7 @@ namespace WinSCP
             FileVersionInfo version = string.IsNullOrEmpty(path) ? null : FileVersionInfo.GetVersionInfo(path);
             FileVersionInfo version = string.IsNullOrEmpty(path) ? null : FileVersionInfo.GetVersionInfo(path);
             WriteLine("Assembly path: {0}", path);
             WriteLine("Assembly path: {0}", path);
             WriteLine("Assembly product version: {0}", ((version != null) ? version.ProductVersion : "unknown"));
             WriteLine("Assembly product version: {0}", ((version != null) ? version.ProductVersion : "unknown"));
+            WriteLine("Entry assembly path: {0}", GetEntryAssemblyFilePath());
         }
         }
 
 
         public static string LastWin32ErrorMessage()
         public static string LastWin32ErrorMessage()