NSIS Changing config file present in XAP file i.e. silverlight component build

早过忘川 提交于 2020-01-16 09:05:30

问题


I am creating one installer which needs to change config file of my one silverlight component. This component's config file is inside XAP file. Is there any way to change that config file?


回答1:


Host your configuration file side-by-side with your XAP file.

  • ../YourProject.XAP
  • ../YourProjectSettings.XML

The following code will download a file called "Settings.xml" which sits in the same directory as your XAP, and place it in Isolated Storage. You can then open/close/parse it as needed later.

    private void DownloadFile()
    {
        Uri downloadPath = new Uri(Application.Current.Host.Source, "Settings.xml");
        WebClient webClient = new WebClient();
        webClient.OpenReadCompleted += OnDownloadComplete;
        webClient.OpenReadAsync(downloadPath);
    }

    private void OnDownloadComplete(object sender, OpenReadCompletedEventArgs e)
    {
        if (e.Error != null) throw e.Error;

        using (var isoStorage = IsolatedStorageFile.GetUserStoreForApplication())
        {
            IsolatedStorageFileStream isoStream = isoStorage.CreateFile("CachedSettings.xml");

            const int size = 4096;
            byte[] bytes = new byte[4096];
            int numBytes;

            while ((numBytes = e.Result.Read(bytes, 0, size)) > 0)
                isoStream.Write(bytes, 0, numBytes);

            isoStream.Flush();
            isoStream.Close();
        }
    }

In this way, your installer can add the necessary settings file side-by-side with your XAP via conditional file copy. Cracking open the XAP is a hack; it will complicate your installer code and will invalidate a signed XAP.




回答2:


I have written console application in C# that is doing these changes in XAP build. I am simply calling that application from my installer as I could not find any way of doing this in NSIS.



来源:https://stackoverflow.com/questions/14961017/nsis-changing-config-file-present-in-xap-file-i-e-silverlight-component-build

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