UWP 应用程序:如何部署可更新的 Json 文件?
UWP app: How can I deploy updatable Json file?
如何将 json 文件与我的 Win10 应用程序打包,使其在 LocalState(或子)文件夹中显示为独立文件?我需要我的应用程序能够偶尔更新此文件。
如果这不可能,应用程序可以在安装过程中将文件放在某个应用程序数据文件夹中吗?
先从应用包中拷贝到应用本地存储即可运行。
您可以将该文件标记为 "Content" 和 "Copy Always",并且在应用程序启动时,您可以通过编程将其复制到 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);
}
如何将 json 文件与我的 Win10 应用程序打包,使其在 LocalState(或子)文件夹中显示为独立文件?我需要我的应用程序能够偶尔更新此文件。
如果这不可能,应用程序可以在安装过程中将文件放在某个应用程序数据文件夹中吗?
先从应用包中拷贝到应用本地存储即可运行。
您可以将该文件标记为 "Content" 和 "Copy Always",并且在应用程序启动时,您可以通过编程将其复制到 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);
}