gpt4 book ai didi

c# - 删除在 C# 应用程序中使用 CompileAssemblyFromSource 生成的临时文件

转载 作者:太空宇宙 更新时间:2023-11-03 13:06:01 29 4
gpt4 key购买 nike

我有一个 C# 应用程序,它在 C:\Users\xxxx\AppData\Local\Temp 生成临时文件。这些临时文件是使用 Microsoft.CSharp.CSharpCodeProvider().CompileAssemblyFromSource 生成的。对于每个动态程序集,都会生成以下文件(.tmp、.out、.err、.dll、.pdb、.cmdline、.cs)。我试着用

result.TempFiles.KeepFiles = false;

但这并不是自动删除这些临时文件。如何在 C# 应用程序执行结束之前删除这些临时文件?

最佳答案

KeepFiles 似乎只是一个 flag :

Each temporary file in the collection has an associated keep file flag that determines, on a per-file basis, whether that file is to be kept or deleted. Files are automatically kept or deleted on completion of the compilation based on their associated keep files value. However, after compilation is complete, files that were kept can be released by setting KeepFiles false and calling the Delete method. This will result in all files being deleted.

要么需要调用 TempFileCollection.Delete或使用 TempFileCollection.Dispose() :

当您使用完集合时:

result.TempFiles.Delete();

或者

result.TempFiles.Dispose();

它们是等价的。

关于c# - 删除在 C# 应用程序中使用 CompileAssemblyFromSource 生成的临时文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30773707/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com