Skip to content

Commit 18aa015

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 18aa015

1 file changed

Lines changed: 13 additions & 2 deletions

File tree

src/Squirrel/IUpdateManager.cs

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -183,8 +183,19 @@ 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+
{
189+
// This happens in .NET Core apps. A shortcut to a .dll doesn't work, so replace with the .exe.
190+
string candidateExe = Path.Combine(Path.GetDirectoryName(entrypoint), Path.GetFileNameWithoutExtension(entrypoint)) + ".exe";
191+
if (File.Exists(candidateExe))
192+
{
193+
entrypoint = candidateExe;
194+
}
195+
}
196+
197+
This.CreateShortcutsForExecutable(
198+
Path.GetFileName(entrypoint),
188199
ShortcutLocation.Desktop | ShortcutLocation.StartMenu,
189200
Environment.CommandLine.Contains("squirrel-install") == false,
190201
null, null);

0 commit comments

Comments
 (0)