Don't try to save a file that already exists

This commit is contained in:
Nikolaj
2020-09-03 13:30:34 +02:00
parent 7b27a56ee9
commit 1bbb6844ac

View File

@@ -44,7 +44,15 @@ namespace Umbraco.ModelsBuilder.Embedded
// TODO: Get proper temp file location/filename
var sourceCode = File.ReadAllText(pathToSourceFile);
CompileToFile(saveLocation, sourceCode, "ModelsGeneratedAssembly", _refs);
// If someone adds a property to an existing document type, and then later removes it again
// The hash of the TypeModel will be the same, and we'll get an error because we can't overwrite the file because it's in use
// this will clear the hash file and the assembly will be recompiled for no reason.
// TODO: Handle this in a less dumb way.
if (!File.Exists(saveLocation))
{
CompileToFile(saveLocation, sourceCode, "ModelsGeneratedAssembly", _refs);
}
return Assembly.LoadFile(saveLocation);
}