From 1c610dcb1abff994d4f15b1f4382810422099cb7 Mon Sep 17 00:00:00 2001 From: Andrew Arnott Date: Sun, 3 Oct 2021 20:40:56 -0600 Subject: [PATCH] Fix `CreateShortcutForThisExe` for .NET Core apps The entrypoint assembly is reported as being a .dll in the .NET Core case. A shortcut to the dll is *not* what the developer expects and it doesn't work for the user. Instead, look for a nearby .exe with the same file name and use that. --- src/Squirrel/IUpdateManager.cs | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/Squirrel/IUpdateManager.cs b/src/Squirrel/IUpdateManager.cs index 73375daf3..c1c554de7 100644 --- a/src/Squirrel/IUpdateManager.cs +++ b/src/Squirrel/IUpdateManager.cs @@ -183,8 +183,17 @@ await This.ErrorIfThrows(() => public static void CreateShortcutForThisExe(this IUpdateManager This) { - This.CreateShortcutsForExecutable(Path.GetFileName( - Assembly.GetEntryAssembly().Location), + string entrypoint = Assembly.GetEntryAssembly().Location; + if (String.Equals(Path.GetExtension(entrypoint), ".dll", StringComparison.OrdinalIgnoreCase)) { + // This happens in .NET Core apps. A shortcut to a .dll doesn't work, so replace with the .exe. + string candidateExe = Path.Combine(Path.GetDirectoryName(entrypoint), Path.GetFileNameWithoutExtension(entrypoint)) + ".exe"; + if (File.Exists(candidateExe)) { + entrypoint = candidateExe; + } + } + + This.CreateShortcutsForExecutable( + Path.GetFileName(entrypoint), ShortcutLocation.Desktop | ShortcutLocation.StartMenu, Environment.CommandLine.Contains("squirrel-install") == false, null, null);