Skip to content

Commit 2d5f27c

Browse files
committed
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.
1 parent d854131 commit 2d5f27c

1 file changed

Lines changed: 12 additions & 2 deletions

File tree

src/Squirrel/IUpdateManager.cs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -183,8 +183,18 @@ await This.ErrorIfThrows(() =>
183183

184184
public static void CreateShortcutForThisExe(this IUpdateManager This)
185185
{
186-
This.CreateShortcutsForExecutable(Path.GetFileName(
187-
Assembly.GetEntryAssembly().Location),
186+
string entrypoint = Assembly.GetEntryAssembly().Location;
187+
if (String.Equals(Path.GetExtension(entrypoint), ".dll", StringComparison.OrdinalIgnoreCase)) {
188+
// This happens in .NET Core apps. A shortcut to a .dll doesn't work, so replace with the .exe.
189+
string candidateExe = Path.Combine(Path.GetDirectoryName(entrypoint), Path.GetFileNameWithoutExtension(entrypoint)) + ".exe";
190+
if (File.Exists(candidateExe))
191+
{
192+
entrypoint = candidateExe;
193+
}
194+
}
195+
196+
This.CreateShortcutsForExecutable(
197+
Path.GetFileName(entrypoint),
188198
ShortcutLocation.Desktop | ShortcutLocation.StartMenu,
189199
Environment.CommandLine.Contains("squirrel-install") == false,
190200
null, null);

0 commit comments

Comments
 (0)