我正在使用 WiX 将应用程序安装到 Program Files 文件夹。我正在使用 util:XmlFile 更新 connectionStrings 元素,但出现错误“无法打开 XML 文件 C:\Program Files (x86)\developMENTALmadness\MainApp.exe.config 系统错误 -2147024786”。我正在尝试提升权限并设置目标文件和父文件夹的权限,但没有设置权限。
产品.wxs:
<?xml version="1.0" encoding="UTF-8"?>
<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi"
xmlns:util="http://schemas.microsoft.com/wix/UtilExtension">
<Product Id="{7A04DDDD-F423-4E81-A42F-6831479ECF15}" Name="Installer"
Language="1033" Version="1.0.0.0"
Manufacturer="developMENTALmadness"
UpgradeCode="a65f51b5-8bf8-4490-8fab-899cc23a8e1b">
<Package InstallerVersion="200" Compressed="yes" InstallScope="perMachine"
InstallPrivileges="elevated" />
<MajorUpgrade DowngradeErrorMessage="A newer version is already installed." />
<MediaTemplate EmbedCab="yes" />
<Property Id="SQLSERVER" Value="(local)" />
<Property Id="SQLDATABASE" Value="OMDatabase" />
<Property Id="SQLINSTALLUSER" Value="sa" />
<Property Id="SQLINSTALLPWD" />
<Property Id="SQLUSER" />
<Property Id="SQLPWD" />
<Feature Id="ProductFeature" Title="Installer" Level="1">
<ComponentGroupRef Id="main_output"/>
</Feature>
<!--<UIRef Id="WixUI_Minimal"/>-->
<UIRef Id="CustomWizard"/>
<Binary Id="WixUI_Bmp_Banner"
SourceFile="$(var.MainApp.ProjectDir)info.png" />
<Binary Id="WixUI_Ico_Info"
SourceFile="$(var.MainApp.ProjectDir)favicon.ico"/>
</Product>
<Fragment>
<Directory Id="TARGETDIR" Name="SourceDir">
<Directory Id="ProgramFilesFolder">
<Directory Id="INSTALLFOLDER" Name="developMENTALmadness">
<Directory Id="target_root" Name="HelloWiX" >
</Directory>
</Directory>
</Directory>
</Directory>
</Fragment>
我使用 heat.exe 生成了组件列表并对其进行了修改(MainOutput.wxs):
<?xml version="1.0" encoding="utf-8"?>
<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi" xmlns:util="http://schemas.microsoft.com/wix/UtilExtension">
<Fragment>
<DirectoryRef Id="target_root">
<Component Id="root_permissions" Guid="{87E634CC-8F0E-4610-961A-9B6C1BBDAEFE}">
<CreateFolder Directory="target_root">
<util:PermissionEx User="Users" GenericAll="yes" ChangePermission="yes" />
</CreateFolder>
</Component>
</DirectoryRef>
</Fragment>
<Fragment>
<ComponentGroup Id="main_output">
<Component Id="cmp2D913B775A49E24FBD0E4DB1A96F05A7" Directory="target_root" Guid="{6284BD47-6181-4220-8DF8-D76F43A608F4}">
<File Id="fil115E0DBDE48A315B4A1DABD091FE0184" KeyPath="yes" Source="$(var.MainApp.TargetPath)" />
</Component>
<Component Id="cmp1A2EDC339002636FAD729B028E1D726A" Directory="target_root" Guid="{45D6B30C-4C74-4260-B53F-855E5F4681FA}">
<File Id="filB9D96E3BAC71662F051EA888708285DA" KeyPath="yes" Source="$(var.MainApp.TargetPath).config" Vital="yes">
<util:PermissionEx User="Users" GenericAll="yes" ChangePermission="yes" />
</File>
<util:XmlFile Id="SetSqlConnection" Action="setValue"
ElementPath="/configuration/connectionStrings/add[\[]@name='database'[\]]"
File="[INSTALLFOLDER]$(var.MainApp.TargetFileName).config"
Value="Server=[SQLSERVER];Database=[SQLDATABASE];uid=[SQLUSER];pwd=[SQLPWD];"
Sequence="1"
SelectionLanguage="XPath" Name="connectionString" />
</Component>
</ComponentGroup>
</Fragment>