Setup App.Config As Custom Action in Setup Project

守給你的承諾、 提交于 2020-01-10 17:45:09

问题


I have a custom application with a simple app.config specifying SQL Server name and Database, I want to prompt the user on application install for application configuration items and then update the app.config file.

I admit I'm totally new to setup projects and am looking for some guidance. Thank You Mark Koops


回答1:


I had problems with the code Gulzar linked to on a 64 bit machine. I found the link below to be a simple solution to getting values from the config ui into the app.config.

http://raquila.com/software/configure-app-config-application-settings-during-msi-install/




回答2:


check this out - Installer with a custom action for changing settings




回答3:


App.Config CAN be changed...however it exists in a location akin to HKEY___LOCAL_MACHINE i.e. the average user has read-only access.

So you will need to change it as an administrator - best time would be during installation, where you're (supposed to be) installing with enhanced permissions.

So create an Installer class, use a Custom Action in the setup project to pass in the user's choices (e.g. "/svr=[SERVER] /db=[DB] /uilevel=[UILEVEL]") and, in the AfterInstall event, change the App.Config file using something like:

Public Shared Property AppConfigSetting(ByVal SettingName As String) As Object
    Get
        Return My.Settings.PropertyValues(SettingName)
    End Get
    Set(ByVal value As Object)
        Dim AppConfigFilename As String = String.Concat(System.Reflection.Assembly.GetExecutingAssembly.Location, ".config")

        If (My.Computer.FileSystem.FileExists(AppConfigFilename)) Then
            Dim AppSettingXPath As String = String.Concat("/configuration/applicationSettings/", My.Application.Info.AssemblyName, ".My.MySettings/setting[@name='", SettingName, "']/value")

            Dim AppConfigXML As New System.Xml.XmlDataDocument
            With AppConfigXML
                .Load(AppConfigFilename)

                Dim DataNode As System.Xml.XmlNode = .SelectSingleNode(AppSettingXPath)

                If (DataNode Is Nothing) Then
                    Throw New Xml.XmlException(String.Format("Application setting not found ({0})!", AppSettingXPath))

                Else
                    DataNode.InnerText = value.ToString
                End If

                .Save(AppConfigFilename)
            End With

        Else
            Throw New IO.FileNotFoundException("App.Config file not found!", AppConfigFilename)
        End If

    End Set
End Property



回答4:


Create custom dialogs for use in your Visual Studio Setup projects: http://www.codeproject.com/Articles/18834/Create-custom-dialogs-for-use-in-your-Visual-Studi



来源:https://stackoverflow.com/questions/249159/setup-app-config-as-custom-action-in-setup-project

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!