我在一些ClickOnce的文章中读到,ClickOnce不允许为应用程序创建桌面图标。是否有任何解决方法?
我在一些ClickOnce的文章中读到,ClickOnce不允许为应用程序创建桌面图标。是否有任何解决方法?
似乎有一种方法可以在ClickOnce中将图标放置在桌面上。
private void CreateDesktopIcon()
{
ApplicationDeployment ad = ApplicationDeployment.CurrentDeployment;
if (ad.IsFirstRun)
{
Assembly assembly = Assembly.GetEntryAssembly();
string company = string.Empty;
string description = string.Empty;
if (Attribute.IsDefined(assembly, typeof(AssemblyCompanyAttribute)))
{
AssemblyCompanyAttribute ascompany =
(AssemblyCompanyAttribute)Attribute.GetCustomAttribute(
assembly, typeof(AssemblyCompanyAttribute));
company = ascompany.Company;
}
if (Attribute.IsDefined(assembly, typeof(AssemblyDescriptionAttribute)))
{
AssemblyDescriptionAttribute asdescription =
(AssemblyDescriptionAttribute)Attribute.GetCustomAttribute(
assembly, typeof(AssemblyDescriptionAttribute));
description = asdescription.Description;
}
if (!string.IsNullOrEmpty(company))
{
string desktopPath = string.Empty;
desktopPath = string.Concat(
Environment.GetFolderPath(Environment.SpecialFolder.Desktop),
"\\",
description,
".appref-ms");
string shortcutName = string.Empty;
shortcutName = string.Concat(
Environment.GetFolderPath(Environment.SpecialFolder.Programs),
"\\",
company,
"\\",
description,
".appref-ms");
System.IO.File.Copy(shortcutName, desktopPath, true);
}
}
}
}
如果您想使用PowerShell,可以创建到.bat文件的快捷方式:
@ECHO OFF
PowerShell -ExecutionPolicy Unrestricted .\script.ps1 >> "%TEMP%\StartupLog.txt" 2>&1
EXIT /B %errorlevel%
静默运行 script.ps1 的代码:
$app = "http://your.site/YourApp/YourApp.application";
[Diagnostics.Process]::Start("rundll32.exe", "dfshim.dll,ShOpenVerbApplication " + $app);
打开你的 ClickOnce 应用程序。
如果有人想使用Visual Studio 2022进行设置选项,
在选择“Clickonce”后,在发布窗口上选择“下一步”。
一直选择“下一步”,直到到达“设置”。
现在选择“选项”链接,打开“发布选项”窗口。
在“发布选项”窗口上选择“清单”。
然后您会看到一个复选框,上面写着“创建桌面快捷方式”。
选择它。