项目场景:
wpf core 怎么打包安装包
问题描述:
这个问题困扰了我很久 用过微软自带的

失败
用过wix toolset 失败
error CNDL0044 : The Class element’s ForeignServer or Server attribute was not found; one of these is required.
C:\Program Files (x86)\WiX Toolset v3.11\bin>light.exe -ext WixUIExtension Pack2MSI.wixobj
light.exe : error LGHT0103 : The system cannot find the file ‘Pack2MSI.wixobj’ with type ‘Source’.
国外论坛
DevExpress.更新问题
说是 少添加了 -sreg -scom
当时在家 远程弄 还是失败 懒得整了
heat.exe : error HEAT0001 : 对路径“C:\Program Files (x86)\WiX Toolset v3.11\bin\myAppad.wxs”的访问被拒绝。
Exception Type: System.UnauthorizedAccessException
Stack Trace:
在 System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
在 System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, Int32 rights, Boolean useRights, FileShare share, Int32 bufferSize, FileOptions options, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy, Boolean useLongPath, Boolean checkHost)
在 System.IO.FileStream…ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, FileOptions options, String msgPath, Boolean bFromProxy, Boolean useLongPath, Boolean checkHost)
在 System.IO.StreamWriter.CreateFile(String path, Boolean append, Boolean checkHost)
在 System.IO.StreamWriter…ctor(String path, Boolean append, Encoding encoding, Int32 bufferSize, Boolean checkHost)
在 System.IO.StreamWriter…ctor(String path, Boolean append, Encoding encoding)
在 Microsoft.Tools.WindowsInstallerXml.Tools.Heat.Run(String[] args)
很多微软推荐的都用了 生成uwp等
后来问群友 推荐 单一文件 但是调用不了资源文件 图片或者文件的
但是算是给我打开大门,我既然能发布 发布的文件夹也能运行 打包和微软有啥关系。。没关系啊 跟文件夹有关系啊
原因分析:
所以抛开所有 打包文件夹才对
解决方案:
首先是发布
选择独立
把这些资源文件 放在发个发布的文件夹里 这些资源访问 代码
```csharp
string ptp = Directory.GetCurrentDirectory();
ptp =ptp+"/TXT/模板.xlsx";
这块就是访问 bin\Debug\netcoreapp3.1 资源代码
打开发布后文件夹中的 exe 能完美运行 下一步打包
这里用到了
NSIS和 HM NIS Edit
和
打开HM NIS Edit
打开文件
新建脚本向导
下一步
设置好这些名称东西
选择简体中文 当然你有别的语言需求再说
选择授权文件 自己新建txt 加点文字就行
删除掉这个exe
点击树状图 然后 添加你发布的那个文件夹
下一步
继续下一步
点击完成 保存好文件
如果这里报错 没关系 删除掉就行
运行完
到这里找到安装包就行
完美
其实还有很多 打包软件 而且有些很傻瓜 很方便。比wix 强多了