将文件部署到安装文件夹

时间:2018-06-07 00:29:24

标签: uwp

要部署文件名为test.txt的文件,我将其放在Visual Studio 2015中的Assets下并将其设置为content。我可以使用以下方式访问它:

Platform::String^ appInstallFolder = Windows::ApplicationModel::Package::Current->InstalledLocation->Path;

std::wstring folderNameW(appInstallFolder->Begin());
std::string folderNameA(folderNameW.begin(), folderNameW.end());

std::string fileName = folderNameA + "\\test.txt";

但是,当我从另一台计算机部署时,要访问我必须使用的文件:

std::string fileName = folderNameA + "\\Assets\\test.txt";

我只是将项目从一个计算复制到另一个计算,并没有改变任何东西。我很困惑为什么路径不同。

非常感谢。

YL

1 个答案:

答案 0 :(得分:0)

我无法在我身边重现你的问题。我认为Visual Studio在另一个计算中的路径与您当前的计算不同。从fontselected文件夹获取文件的最佳做法是使用Assets Api。

Windows.Storage

使用上述方法获取var file = await Windows.ApplicationModel.Package.Current.InstalledLocation.GetFileAsync(@"Assets\Test.txt"); 文件夹中的文件可以避免路径错误。