在c#中使用.nsi安装脚本保存和编辑文件的正确方法是什么?
本文关键字:编辑文件 方法 是什么 保存 nsi 脚本 安装 | 更新日期: 2023-09-27 18:07:04
在我的项目中,我有一个xml文件,该文件存储了程序读取和显示的一堆字符串。我想要发生的是用文件构建程序,使用安装脚本创建安装程序(我已经通过后构建事件将所有.dll和.exe文件移动到脚本的bin文件夹),然后让最终用户能够访问此文件,并让程序每次运行时自动加载文件。
这是我当前打开文件的方式。这看起来在调试文件夹,但我希望它住在一个持久的位置。
XmlDocument doc = new XmlDocument();
doc.Load("PowerManagers.xml");
我的。nsi文件:
!define FullName "Power Manager Safety Testing"
!define ProductName "Power Manager Safety Testing"
!define ProductExe "PowerManagerSafetyTesting.exe"
;--------------------------------
;Include Modern UI
!include "MUI.nsh"
!include "Framework .Net Install.nsh"
!include "Common Functions.nsh"
!include "Common Drivers.nsh"
ShowInstDetails show
!insertmacro Insert_System_Configuration
;--------------------------------
; The stuff to install
Section "${ProductName}" Sec_Id_Main
SectionIn RO
Call MainSectionInstall
; The files to use in this installer
File "..'..'bin'PowerManagerSafetyTesting'*.exe"
File "..'..'bin'PowerManagerSafetyTesting'*.dll"
File "..'..'bin'PowerManagerSafetyTesting'PowerManagers.xml"
SectionEnd
;---------
;---------
; Optional section (can be disabled by the user)
Section "Start Menu Shortcuts" Sec_Id_Start
Call StartMenuSection
SectionEnd
;---------
; Optional section (can be disabled by the user)
Section "Desktop Shortcuts" Sec_Id_Desktop
Call DesktopShortcutsSection
SectionEnd
;--------------------------------
; Uninstaller
Section "Uninstall"
Call un.UninstallerSection
SectionEnd
;--------------------------------
; Page descriptions
!insertmacro MUI_FUNCTION_DESCRIPTION_BEGIN
!insertmacro MUI_DESCRIPTION_TEXT ${SECDOTNET_ID} $(DESC_LONGDOTNET)
!insertmacro MUI_DESCRIPTION_TEXT ${Sec_Id_Main} "Installs the core files required to run the ${ProductName}"
!insertmacro MUI_DESCRIPTION_TEXT ${Sec_Id_Start} "Installs short cuts to the start menu"
!insertmacro MUI_DESCRIPTION_TEXT ${Sec_Id_Desktop} "Installs short cuts to the desktop"
!insertmacro MUI_FUNCTION_DESCRIPTION_END
你需要把你的XML文件放在Windows数据目录下,即C:'ProgramData'Your_App
,从你的c#应用程序中读取,并从你的安装程序中写入该路径下的文件。
String strPath = Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData);
strPath += "''Your_App''PowerManagers.xml";
XmlDocument doc = new XmlDocument();
doc.Load(strPath);
<<p> NSIS脚本/strong> ReadRegStr $0 HKLM "Software'Microsoft'Windows'CurrentVersion'Explorer'ShellFolders" "Common AppData"
CreateDirectory "$0'Your_App"
SetOutPath "$0'Your_App"
File "..'..'bin'PowerManagerSafetyTesting'PowerManagers.xml"