Frage

Wenn Sie die CODEDOMProvider-Klasse in .NET verwenden, nachdem die Kompilierung abgeschlossen ist, können Sie die Ausgabebaugruppe nicht löschen.Ich möchte die Ausgabebaugruppe löschen können.Datei.Delete gibt einen Zugriff zurück, der ausnahmslos abgelehnt wird. generasacodicetagpre.

editieren Als Arbeit umgekehrt Ich verwende einen statischen Konstruktor auf der Klasse, der den Temp-Ordner durchsucht, und löscht zuvor erstellte Baugruppen.

War es hilfreich?

Lösung

I suspect the problem is that the assembly is loaded (in memory), and has the output file open, just as any other assembly that is currently loaded will have a handle to its executable file.

It's also possible (although I consider it unlikely) that the dom instance or the CompilerResults instance has a reference to the opened file. Neither is IDisposable, so I suspect they're not holding the file open.

Possible solutions:

You can compile the assembly to memory. That is, don't output a file. That solves the immediate problem. However, you still have the problem that the compiled assembly remains in memory. There's no way to unload an assembly without tearing down the app domain.

You can create a separate app domain to do the compile, and then communicate the results back to your main app domain. You can then shut down the compiler app domain, which will remove the compiled assembly from memory and also release any file handles that are referencing the file you just created. Your main program can then delete the file in question.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top