UWP app:如何部署可更新的Json文件?

时间:2017-05-02 14:04:14

标签: uwp windows-store-apps

如何使用我的Win10应用程序打包json文件,使其在LocalState(或sub)文件夹中显示为独立文件?我需要让我的应用偶尔更新此文件。

如果这是不可能的,应用程序可以在安装过程中将文件放在某个应用程序数据文件夹中吗?

2 个答案:

答案 0 :(得分:2)

首次运行时,只需将其从应用包复制到应用本地存储。

答案 1 :(得分:1)

您可以将该文件标记为“内容”和“始终复制”,在应用启动时,您可以通过编程方式将其复制到LocalFolder,然后随时更新。

例如:假设您在根项目下有一个“Config”文件夹,test.json是您要替换的文件,然后

string testPath = Path.Combine(ApplicationData.Current.LocalFolder.Path, "test.json");

if (!File.Exists(testPath))
    {
            string tempPath = "ms-appx:///Config/test.json";
            Uri location = new Uri(tempPath, UriKind.Absolute);
            StorageFile file = await StorageFile.GetFileFromApplicationUriAsync(location);
            await file.CopyAsync(ApplicationData.Current.LocalFolder);
    }