【发布时间】:2015-08-18 14:29:32
【问题描述】:
我使用 Costura.Fody 将每个 dll 编译到我的 .exe 中
我有一个 .ico,我的项目使用它来为程序创建一个快捷方式,以便在启动时启动程序或删除它(用户可以通过复选框添加/删除它)
但是我希望能够将此 .ico 作为 .exe 的一部分包含在内,并且能够引用它而不是使用路径(当前在 .exe 的目录中使用 .ico。这可能吗?作为资源?
目前我在做:
public void CreateShortcut(string shortcutName, string shortcutPath, string targetFileLocation)
{
string shortcutLocation = System.IO.Path.Combine(shortcutPath, shortcutName + ".lnk");
WshShell shell = new WshShell();
IWshShortcut shortcut = (IWshShortcut)shell.CreateShortcut(shortcutLocation);
shortcut.Description = "Description"; // The description of the shortcut
shortcut.IconLocation = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "icon.ico");
shortcut.TargetPath = targetFileLocation; // The path of the file that will launch when the shortcut is run
shortcut.Save(); // Save the shortcut
}
public void DeleteShortcut()
{
// should find the file and delete it
string[] dirs = Directory.GetFiles(Environment.GetFolderPath(Environment.SpecialFolder.Startup), "StartupApp*");
foreach (string dir in dirs)
{
System.IO.File.Delete(dir);
}
}
【问题讨论】:
-
我可以这样做:shortcut.IconLocation = Icon.ExtractAssociatedIcon(Assembly.GetExecutingAssembly().Location);但是通过设置快捷方式图标而不是设置其图标路径?
标签: c# exe embedded-resource