From 18aa015721f4a3d3b17cf958d535b71c76552fe5 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 | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/src/Squirrel/IUpdateManager.cs b/src/Squirrel/IUpdateManager.cs index 73375daf3..15da68ae8 100644 --- a/src/Squirrel/IUpdateManager.cs +++ b/src/Squirrel/IUpdateManager.cs @@ -183,8 +183,19 @@ 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);