WPF 打包

打包为单个exe文件直接运行

- - - 版本
.NET 8
  • 新建WPF项目

  • 右键 - 发布

  • 选择发布文件夹

  • 选择发布文件夹

  • 选择发布文件夹

  • 配置

  • 配置,保存

  • 发布

WPF 打包为exe安装程序

示例

  • 实现思路

    • 引导项目中嵌入其它项目可运行目录的zip
    • 引导项目中解压zip文件到指定文件夹
    • 是否创建快捷方式
  • 将 WPF 项目的 Debug 文件夹打包为zip

  • 按照上述 新建一个安装引导项目, 打包为单个exe文件直接运行

    • 引入 Debug.zip 文件
      • 右键该文件
    • 安装引导自定义 (例)
      • 用户是否同意
      • 安装目录
      • 是否创建快捷方式
  • 解压方法

csharp 复制代码
/// <summary>
/// 解压方法
/// </summary>
/// <param name="zipFilePath">zip文件目录  D:\\123.zip</param>
/// <param name="destinationFolder">解压目录  D:\\123</param>
public static void UnzipFile(string zipFilePath, string destinationFolder)
{
    Directory.CreateDirectory(destinationFolder);
    using (var zipToOpen = new FileStream(zipFilePath, FileMode.Open))
    {
        using (var archive = new ZipArchive(zipToOpen, ZipArchiveMode.Read))
        {
            foreach (var entry in archive.Entries)
            {
                if (entry.Length == 0) continue;
                var destFileName = Path.Combine(destinationFolder, entry.FullName);
                var destinationDirectory = Path.GetDirectoryName(destFileName);
                Directory.CreateDirectory(destinationDirectory);
                using (var entryStream = entry.Open())
                using (var fileStream = new FileStream(destFileName, FileMode.Create))
                {
                    entryStream.CopyTo(fileStream);
                }
            }
        }
    }
} 
  • 创建快捷方式

csharp 复制代码
string exePath = @"C:\路径\xxxx.exe";
string desktopPath = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
string shortcutPath = Path.Combine(desktopPath, "xxxx.lnk");
WshShell shell = new WshShell();
IWshShortcut shortcut = (IWshShortcut)shell.CreateShortcut(shortcutPath);
shortcut.Description = "描述";
shortcut.TargetPath = exePath; 
shortcut.WorkingDirectory = Path.GetDirectoryName(exePath);
shortcut.Save();
相关推荐
ALex_zry11 小时前
构建高可靠C++服务框架:从日志系统到任务调度器的完整实现
开发语言·c++·wpf
Bruce_Cheung1 天前
WPF旋转板栈设计一例
wpf·rack·tube·料盒·料管
leslie_xin1 天前
(原创)[开源][.Net Framework 4.5] SimpleMVVM(极简MVVM框架)更新 v1.1,增加NuGet包
c#·wpf
不知名君2 天前
WPF轮播图动画交互 动画缩放展示图片
wpf
Sitarrrr3 天前
【WPF】IOC控制反转的应用:弹窗但不互相调用ViewModel
设计模式·c#·wpf
"孙小浩6 天前
HarmonyOS应用开发者高级-编程题-001
华为·wpf·harmonyos
yngsqq6 天前
003集——《利用 C# 与 AutoCAD API 开发 WPF 随机圆生成插件》(侧栏菜单+WPF窗体和控件+MVVM)
wpf
baivfhpwxf20236 天前
WPF 免费UI 控件HandyControl
ui·wpf
qq_196055876 天前
WPF插入背景图
wpf
baivfhpwxf20236 天前
prism WPF 对话框
c#·wpf