From 1bbb6844ac7a7b5257cb203d550cb38a75e98155 Mon Sep 17 00:00:00 2001 From: Nikolaj Date: Thu, 3 Sep 2020 13:30:34 +0200 Subject: [PATCH] Don't try to save a file that already exists --- src/Umbraco.ModelsBuilder.Embedded/RoslynCompiler.cs | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/Umbraco.ModelsBuilder.Embedded/RoslynCompiler.cs b/src/Umbraco.ModelsBuilder.Embedded/RoslynCompiler.cs index 9449172033..d5442faa40 100644 --- a/src/Umbraco.ModelsBuilder.Embedded/RoslynCompiler.cs +++ b/src/Umbraco.ModelsBuilder.Embedded/RoslynCompiler.cs @@ -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); }