Home:ALL Converter>Delete Temp files generated by using CompileAssemblyFromSource in c# application

Delete Temp files generated by using CompileAssemblyFromSource in c# application

Ask Time:2015-06-11T14:56:29         Author:Anky

Json Formatter

I have a C# application which generates temp files at C:\Users\xxxx\AppData\Local\Temp. These temp files are being generated as a result of using Microsoft.CSharp.CSharpCodeProvider().CompileAssemblyFromSource. For each dynamic assembly following files (.tmp, .out, .err, .dll, .pdb, .cmdline, .cs) are generated. I tried to use

result.TempFiles.KeepFiles = false;

but this is not deleting these temp files automatically. How can I get rid of these temp files before the end of c# application execution ?

Author:Anky,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/30773707/delete-temp-files-generated-by-using-compileassemblyfromsource-in-c-sharp-applic
Yuval Itzchakov :

KeepFiles seems to only be a flag:\n\n\n Each temporary file\n in the collection has an associated keep file flag that determines, on\n a per-file basis, whether that file is to be kept or deleted. Files\n are automatically kept or deleted on completion of the compilation\n based on their associated keep files value. However, after compilation\n is complete, files that were kept can be released by setting KeepFiles\n false and calling the Delete method. This will result in all files\n being deleted.\n\n\nWill either need to call TempFileCollection.Delete or using TempFileCollection.Dispose():\n\nWhen you're done using the collection:\n\nresult.TempFiles.Delete();\n\n\nOr\n\nresult.TempFiles.Dispose();\n\n\nWhich are equivalent.",
2015-06-11T07:04:13
yy