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();
相关推荐
明耀41 分钟前
WPF DataGrid 默认显示行号
wpf
lph19725 小时前
wpf的converter
wpf
fyifei05585 小时前
WPF学习PropertyChanged
wpf
爱炸薯条的小朋友5 小时前
C#由于获取WPF窗口名称造成的异常报错问题
windows·c#·wpf
baivfhpwxf20236 小时前
wpf ListBox 去除item 单击样式
wpf
诗仙&李白6 小时前
lnnovationHubTool,用prism+WPF编写的MVVM模式的快速上位机软件开发框架平台
wpf·mvvm·prism·上位机软件开发框架平台
程序员小刘9 小时前
【HarmonyOS 5】教育开发实践详解以及详细代码案例
华为·wpf·harmonyos
Java Fans1 天前
在WPF项目中集成Python:Python.NET深度实战指南
python·.net·wpf
布伦鸽1 天前
C# WPF 左右布局实现学习笔记(1)
笔记·学习·c#·wpf
code bean2 天前
【WPF】WPF 项目实战:构建一个可增删、排序的光源类型管理界面(含源码)
wpf