问题
In my project, I want to add several folders containing different files to Project-Properties-Resources
, but I found that I could't add folders to resources, which is the way I really need.
So, is there any possible way that I can add folders to Project-Properties-Resources
? In visual studio, I only found Add Existing File, Add New String and so on.
Thanks in advance to anyone who read my question.
回答1:
You compress the folders into ZIP files, add the file, then decompress at runtime. using System.IO.Compression....
string startPath = @"c:\example\start";//folder to add
string zipPath = @"c:\example\result.zip";
ZipFile.CreateFromDirectory(startPath, zipPath, CompressionLevel.Fastest, true);
//add the ZIP file you just created to your resources
//Then, on startup, extract the zip to a folder you control
string extractPath = @"c:\example\extract";
ZipFile.ExtractToDirectory(zipPath, extractPath);
To do this once per update, do something like create a setting for delete, set it to true on distribution, then:
private void shouldExtract()
{
if (MyProject.Properties.Settings.Default.DeleteExtractionFolder == true)
{
if (Directory.Exists(myExtractionDirectory))
{
Directory.Delete(myExtractionDirectory);
//unzip
MyProject.Properties.Settings.Default.DeleteExtractionFolder = false;
}
}
}
Adding a whole folder (with subfolders) as embedded resource?
来源:https://stackoverflow.com/questions/39732390/c-sharp-add-folders-to-resources