WiX 제거시 파일 제거
내 애플리케이션을 제거 할 때 원래 설치 후 추가 된 모든 파일을 제거 하도록 Wix 설정을 구성하고 싶습니다 . 제거 프로그램은 MSI 파일에서 원래 설치된 디렉토리와 파일 만 제거하고 나중에 추가 된 모든 파일은 응용 프로그램 폴더에 남겨 둡니다. 즉, 제거 할 때 디렉토리를 제거하고 싶습니다. 어떻게하나요?
On = " uninstall " 과 함께 RemoveFile 요소 를 사용하십시오 . 예를 들면 다음과 같습니다.
<Directory Id="CommonAppDataFolder" Name="CommonAppDataFolder">
<Directory Id="MyAppFolder" Name="My">
<Component Id="MyAppFolder" Guid="*">
<CreateFolder />
<RemoveFile Id="PurgeAppFolder" Name="*.*" On="uninstall" />
</Component>
</Directory>
</Directory>
최신 정보
100 % 작동하지 않았습니다. 파일을 제거했지만 추가 디렉토리 (설치 후 생성 된 디렉토리)는 제거되지 않았습니다. 그것에 대한 생각은? – 프리 베이로
불행히도 Windows Installer는 하위 디렉터리가있는 디렉터리 삭제를 지원하지 않습니다. 이 경우 사용자 지정 작업에 의존해야합니다. 또는 하위 폴더가 무엇인지 알고있는 경우 RemoveFolder 및 RemoveFile 요소를 만듭니다.
RemoveFolderEx
WiX에서 Util 확장의 요소를 사용합니다 .
이 접근 방식을 사용하면 모든 하위 디렉터리도 제거됩니다 ( element를 직접 사용RemoveFile
하는 것과 반대 ). 이 요소는 MSI 데이터베이스의 RemoveFile
및 RemoveFolder
테이블에 임시 행을 추가 합니다.
이를 위해 간단히 제거 할 때 호출 할 사용자 지정 작업을 만들었습니다.
WiX 코드는 다음과 같습니다.
<Binary Id="InstallUtil" src="InstallUtilLib.dll" />
<CustomAction Id="DIRCA_TARGETDIR" Return="check" Execute="firstSequence" Property="TARGETDIR" Value="[ProgramFilesFolder][Manufacturer]\[ProductName]" />
<CustomAction Id="Uninstall" BinaryKey="InstallUtil" DllEntry="ManagedInstall" Execute="deferred" />
<CustomAction Id="UninstallSetProp" Property="Uninstall" Value="/installtype=notransaction /action=uninstall /LogFile= /targetDir="[TARGETDIR]\Bin" "[#InstallerCustomActionsDLL]" "[#InstallerCustomActionsDLLCONFIG]"" />
<Directory Id="BinFolder" Name="Bin" >
<Component Id="InstallerCustomActions" Guid="*">
<File Id="InstallerCustomActionsDLL" Name="SetupCA.dll" LongName="InstallerCustomActions.dll" src="InstallerCustomActions.dll" Vital="yes" KeyPath="yes" DiskId="1" Compressed="no" />
<File Id="InstallerCustomActionsDLLCONFIG" Name="SetupCA.con" LongName="InstallerCustomActions.dll.Config" src="InstallerCustomActions.dll.Config" Vital="yes" DiskId="1" />
</Component>
</Directory>
<Feature Id="Complete" Level="1" ConfigurableDirectory="TARGETDIR">
<ComponentRef Id="InstallerCustomActions" />
</Feature>
<InstallExecuteSequence>
<Custom Action="UninstallSetProp" After="MsiUnpublishAssemblies">$InstallerCustomActions=2</Custom>
<Custom Action="Uninstall" After="UninstallSetProp">$InstallerCustomActions=2</Custom>
</InstallExecuteSequence>
InstallerCustomActions.DLL의 OnBeforeUninstall 메서드에 대한 코드는 다음과 같습니다 (VB).
Protected Overrides Sub OnBeforeUninstall(ByVal savedState As System.Collections.IDictionary)
MyBase.OnBeforeUninstall(savedState)
Try
Dim CommonAppData As String = Me.Context.Parameters("CommonAppData")
If CommonAppData.StartsWith("\") And Not CommonAppData.StartsWith("\\") Then
CommonAppData = "\" + CommonAppData
End If
Dim targetDir As String = Me.Context.Parameters("targetDir")
If targetDir.StartsWith("\") And Not targetDir.StartsWith("\\") Then
targetDir = "\" + targetDir
End If
DeleteFile("<filename.extension>", targetDir) 'delete from bin directory
DeleteDirectory("*.*", "<DirectoryName>") 'delete any extra directories created by program
Catch
End Try
End Sub
Private Sub DeleteFile(ByVal searchPattern As String, ByVal deleteDir As String)
Try
For Each fileName As String In Directory.GetFiles(deleteDir, searchPattern)
File.Delete(fileName)
Next
Catch
End Try
End Sub
Private Sub DeleteDirectory(ByVal searchPattern As String, ByVal deleteDir As String)
Try
For Each dirName As String In Directory.GetDirectories(deleteDir, searchPattern)
Directory.Delete(dirName)
Next
Catch
End Try
End Sub
Here's a variation on @tronda's suggestion. I'm deleting a file "install.log" that gets created by another Custom Action, during Uninstall:
<Product>
<CustomAction Id="Cleanup_logfile" Directory="INSTALLFOLDER"
ExeCommand="cmd /C "del install.log""
Execute="deferred" Return="ignore" HideTarget="no" Impersonate="no" />
<InstallExecuteSequence>
<Custom Action="Cleanup_logfile" Before="RemoveFiles" >
REMOVE="ALL"
</Custom>
</InstallExecuteSequence>
</Product>
As far as I understand, I can't use "RemoveFile" because this file is created after the installation, and is not part of a Component Group.
Not an WIX expert, but could a possible (simpler?) solution to this be to run the Quiet Execution Custom Action which is part of the built in extensions of WIX?
Could run the rmdir MS DOS command with the /S and /Q options.
<Binary Id="CommandPrompt" SourceFile="C:\Windows\System32\cmd.exe" />
And the custom action doing the job is simple:
<CustomAction Id="DeleteFolder" BinaryKey="CommandPrompt"
ExeCommand='/c rmdir /S /Q "[CommonAppDataFolder]MyAppFolder\PurgeAppFolder"'
Execute="immediate" Return="check" />
Then you'll have to modify the InstallExecuteSequence as documented many places.
Update: Had issues with this approach. Ended up making a custom task instead, but still considers this a viable solution, but without getting the details to work.
This would be a more complete answer for @Pavel suggestion, for me it's working 100%:
<Fragment Id="FolderUninstall">
<?define RegDir="SYSTEM\ControlSet001\services\[Manufacturer]:[ProductName]"?>
<?define RegValueName="InstallDir"?>
<Property Id="INSTALLFOLDER">
<RegistrySearch Root="HKLM" Key="$(var.RegDir)" Type="raw"
Id="APPLICATIONFOLDER_REGSEARCH" Name="$(var.RegValueName)" />
</Property>
<DirectoryRef Id='INSTALLFOLDER'>
<Component Id="UninstallFolder" Guid="*">
<CreateFolder Directory="INSTALLFOLDER"/>
<util:RemoveFolderEx Property="INSTALLFOLDER" On="uninstall"/>
<RemoveFolder Id="INSTALLFOLDER" On="uninstall"/>
<RegistryValue Root="HKLM" Key="$(var.RegDir)" Name="$(var.RegValueName)"
Type="string" Value="[INSTALLFOLDER]" KeyPath="yes"/>
</Component>
</DirectoryRef>
</Fragment>
And, under Product element:
<Feature Id="Uninstall">
<ComponentRef Id="UninstallFolder" Primary="yes"/>
</Feature>
This approach set a registry value with the desired path of the folder to be deleted on uninstall. At the end, both INSTALLFOLDER and registry folder are removed from the system. Note that the path to the registry can be at other hive and other locations.
참고URL : https://stackoverflow.com/questions/195919/removing-files-when-uninstalling-wix
'Nice programing' 카테고리의 다른 글
vdso와 vsyscall은 무엇입니까? (0) | 2020.10.16 |
---|---|
테스트가 없습니다. (0) | 2020.10.16 |
LINQ to SQL의 TransactionScope와 Transaction (0) | 2020.10.16 |
[L 배열 표기법-어디에서 왔습니까? (0) | 2020.10.16 |
Django에서 manage.py를 사용하여 CLI에서 데이터베이스를 지우는 가장 쉬운 방법은 무엇입니까? (0) | 2020.10.16 |