Maui打包文件

Maui打包文件

  1. 把需要打包的文件放到Resources\Raw\目录下。

  2. 设置文件的生成操作Build Action为MauiAsset

  3. 使用using (Stream instream = FileSystem.Current.OpenAppPackageFileAsync(fileName))读取文件。

  4. 将文件拷贝到其他目录

    1
    2
    3
    4
    5
    6
    7
    8
    9
    
    // Open the source file
        using Stream inputStream = await FileSystem.Current.OpenAppPackageFileAsync(filename);
    
        // Create an output filename
        string targetFile = Path.Combine(FileSystem.Current.AppDataDirectory, filename);
    
        // Copy the file to the AppDataDirectory
        using FileStream outputStream = File.Create(targetFile);
        await inputStream.CopyToAsync(outputStream);
    
Licensed under CC BY-NC-SA 4.0
Built with Hugo
Theme Stack designed by Jimmy