【发布时间】:2011-10-20 21:45:28
【问题描述】:
我有一个标准的 Visual Studio 设置项目,我正在将其转换为 InstallShield LE 项目。
我在 CustomActions-Install-PrimaryOutputFromMyProject(Active) - CustomActionData - /sectionName="userSettings/SSE.My.MySettings" /provName="DPAPIProtection"
下有以下自定义操作如何在 InstallShield 中重新创建此自定义操作?
这是我的安装程序类中的代码,它所做的只是保护 app.config 文件的某些部分:
Imports System.ComponentModel
Imports System.Configuration.Install
Imports System.Configuration
'// This file encrypts the app.config file
Public Class CustomInstaller
Inherits Installer
Public Sub New()
MyBase.New()
'This call is required by the Component Designer.
InitializeComponent()
'Add initialization code after the call to InitializeComponent
End Sub
Public Overrides Sub Install(ByVal stateSaver As System.Collections.IDictionary)
MyBase.Install(stateSaver)
'get Configuration section
'name from custom action parameter
Dim sectionName As String = Me.Context.Parameters("sectionName")
'get Protected Configuration Provider
'name from custom action parameter
Dim provName As String = Me.Context.Parameters("provName")
' get the exe path from the default context parameters
Dim exeFilePath As String = Me.Context.Parameters("assemblypath")
'encrypt the configuration section
ProtectSection(sectionName, provName, exeFilePath)
End Sub
Private Sub ProtectSection(ByVal sectionName As String, ByVal provName As String, ByVal exeFilePath As String)
Dim config As Configuration = ConfigurationManager.OpenExeConfiguration(exeFilePath)
Dim section As ConfigurationSection = config.GetSection(sectionName)
If Not section.SectionInformation.IsProtected Then
'Protecting the specified section with the specified provider
section.SectionInformation.ProtectSection(provName)
End If
section.SectionInformation.ForceSave = True
config.Save(ConfigurationSaveMode.Modified)
End Sub
End Class
【问题讨论】:
标签: visual-studio installshield