在我的项目中,我有一个xml文件,它存储程序读取和显示的一串字符串。我想要发生的是使用该文件构建程序,使用安装脚本来创建安装程序(我已经通过构建后事件将所有.dll和.exe文件移动到脚本文件夹中)然后具有最终用户可以访问此文件,并让程序在每次运行时自动加载文件。
这是我当前打开文件的方式。这看起来在调试文件夹中,但我希望它生活在一个持久的位置。
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
答案 0 :(得分:0)
您需要将XML文件放在Windows数据目录中,即String strPath = Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData);
strPath += "\\Your_App\\PowerManagers.xml";
XmlDocument doc = new XmlDocument();
doc.Load(strPath);
,然后从C#应用程序中读取,并从安装程序中写入该路径中的文件。
C#计划
ReadRegStr $0 HKLM "Software\Microsoft\Windows\CurrentVersion\Explorer\ShellFolders" "Common AppData"
CreateDirectory "$0\Your_App"
SetOutPath "$0\Your_App"
File "..\..\bin\PowerManagerSafetyTesting\PowerManagers.xml"
NSIS脚本
return false;