我正在创建一个安装程序,它需要更改我的一个 silverlight 组件的配置文件。该组件的配置文件位于 XAP 文件中。有什么办法可以更改该配置文件?
问问题
408 次
2 回答
1
将配置文件与 XAP 文件并排托管。
- ../YourProject.XAP
- ../YourProjectSettings.XML
以下代码将下载一个名为“Settings.xml”的文件,该文件与 XAP 位于同一目录中,并将其放置在独立存储中。然后,您可以稍后根据需要打开/关闭/解析它。
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();
}
}
这样,您的安装程序可以通过条件文件复制将必要的设置文件与您的 XAP 并排添加。破解 XAP 是一种 hack;它会使您的安装程序代码复杂化,并使已签名的 XAP 无效。
于 2013-02-19T20:40:39.510 回答
0
我用 C# 编写了控制台应用程序,它在 XAP 构建中进行了这些更改。我只是从我的安装程序中调用该应用程序,因为我在 NSIS 中找不到任何方法。
于 2013-03-01T08:19:17.053 回答