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();
相关推荐
Scout-leaf5 天前
WPF新手村教程(三)—— 路由事件
c#·wpf
柒.梧.7 天前
基于SpringBoot+JWT 实现Token登录认证与登录人信息查询
wpf
十月南城10 天前
Flink实时计算心智模型——流、窗口、水位线、状态与Checkpoint的协作
大数据·flink·wpf
听麟13 天前
HarmonyOS 6.0+ 跨端会议助手APP开发实战:多设备接续与智能纪要全流程落地
分布式·深度学习·华为·区块链·wpf·harmonyos
@hdd13 天前
Kubernetes 可观测性:Prometheus 监控、日志采集与告警
云原生·kubernetes·wpf·prometheus
zls36536513 天前
C# WPF canvas中绘制缺陷分布map
开发语言·c#·wpf
专注VB编程开发20年13 天前
c#Redis扣款锁的设计,多用户,多台电脑操作
wpf
闲人编程14 天前
定时任务与周期性调度
分布式·python·wpf·调度·cron·定时人物·周期性
zls36536514 天前
C# WPF canvas中绘制缺陷分布map并实现缩放
开发语言·c#·wpf
数据知道15 天前
PostgreSQL:Citus 分布式拓展,水平分片,支持海量数据与高并发
分布式·postgresql·wpf