From 5d12f99eaf099006192857f8f5efc5e200e8adc8 Mon Sep 17 00:00:00 2001 From: Nikolaj Date: Mon, 7 Sep 2020 12:01:25 +0200 Subject: [PATCH] SImplify roslyn compiler Since the old assemblies actually gets deleted now we no longer need to check if the old assembly file exists --- .../RoslynCompiler.cs | 20 +++---------------- 1 file changed, 3 insertions(+), 17 deletions(-) diff --git a/src/Umbraco.ModelsBuilder.Embedded/RoslynCompiler.cs b/src/Umbraco.ModelsBuilder.Embedded/RoslynCompiler.cs index f390412c88..256b429ad9 100644 --- a/src/Umbraco.ModelsBuilder.Embedded/RoslynCompiler.cs +++ b/src/Umbraco.ModelsBuilder.Embedded/RoslynCompiler.cs @@ -39,35 +39,21 @@ namespace Umbraco.ModelsBuilder.Embedded public void CompileToFile(string pathToSourceFile, string saveLocation) { - // TODO: Get proper temp file location/filename var sourceCode = File.ReadAllText(pathToSourceFile); - // 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); - } - - } - - private void CompileToFile(string outputFile, string sourceCode, string assemblyName, IEnumerable references) - { var sourceText = SourceText.From(sourceCode); var syntaxTree = SyntaxFactory.ParseSyntaxTree(sourceText, _parseOptions); - var compilation = CSharpCompilation.Create(assemblyName, + var compilation = CSharpCompilation.Create("ModelsGeneratedAssembly", new[] { syntaxTree }, - references: references, + references: _refs, options: new CSharpCompilationOptions(_outputKind, optimizationLevel: OptimizationLevel.Release, // Not entirely certain that assemblyIdentityComparer is nececary? assemblyIdentityComparer: DesktopAssemblyIdentityComparer.Default)); - compilation.Emit(outputFile); + compilation.Emit(saveLocation); } }