Uwp 将文件部署到安装文件夹
为了部署一个文件名为test.txt的文件,我将其放在Visual Studio 2015的资产下,并将其设置为内容。我可以通过以下方式访问它:Uwp 将文件部署到安装文件夹,uwp,Uwp,为了部署一个文件名为test.txt的文件,我将其放在Visual Studio 2015的资产下,并将其设置为内容。我可以通过以下方式访问它: Platform::String^ appInstallFolder = Windows::ApplicationModel::Package::Current->InstalledLocation->Path; std::wstring folderNameW(appInstallFolder->Begin()); std::st
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我无法在我身边再现你的问题。我假设Visual Studio在另一台计算机中的路径与您当前的计算机不同。从
Assets
文件夹获取文件的最佳实践是使用Windows.Storage
Api
var file = await Windows.ApplicationModel.Package.Current.InstalledLocation.GetFileAsync(@"Assets\Test.txt");
使用上面的方法,在
InstalledLocation
文件夹中获取文件可以避免路径错误。谢谢Nico。我使用默认设置安装了VS,我认为它们具有相同的路径。我无法理解为什么txt文件被部署到不同的路径。重新安装VS后路径是否相同?