How can I create a shortcut programmatically for my WinUI 3 app written in C#? I've tried some code that I've found on this website(https://stackoverflow.com/a/14632782/10228444)
private static void CreateLink()
{
IShellLink link = (IShellLink)new ShellLink();
// setup shortcut information
link.SetDescription("My Description");
string installedPath = System.Reflection.Assembly.GetExecutingAssembly().Location;
link.SetPath(installedPath);
// save it
IPersistFile file = (IPersistFile)link;
string desktopPath = Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory);
file.Save(Path.Combine(desktopPath, "MyLink.lnk"), false);
}
installedPath references C:Users\Program Files\WindowsApps\GUID_1.0.0_x64_hash\MyApp.dll. I've also tried with ...\MyApp.exe but to no avail.
I've created manualy a shortcut for the app and it's properties are different from other shortcuts. TargetType would be GUID__hash(instead of GUID was the value that I've obtained for GUID in installedPath variable, same for hash), TargetType Applications and Target GUID__hash!App. An excel shortcut would contain as TargetType Application, TargetLocation Office 16, Target "C:\Program Files (x86)\Microsoft Office\root\Office16\EXCEL.EXE".
If your project is a unpackage project, you could double click the exe. You could try to create a desktop shortcut with the Windows Script Host
If your project is a package project, you need to use the Windows Application Packaging Project to generate an MSIX for your application. And you couldn't create a desktop shortcut from code for the project