From 200d85a1f9eb1735285e04c89ba66634e2bf07f3 Mon Sep 17 00:00:00 2001 From: Julien Roncaglia Date: Thu, 29 Mar 2018 15:49:12 +0200 Subject: [PATCH] Only write the targets file if it changed Fixes #13 --- src/dotnet-proj-info/Inspect.fs | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/src/dotnet-proj-info/Inspect.fs b/src/dotnet-proj-info/Inspect.fs index 6b30593c..f7b8832a 100644 --- a/src/dotnet-proj-info/Inspect.fs +++ b/src/dotnet-proj-info/Inspect.fs @@ -114,8 +114,20 @@ let writeTargetFile log templates targetFileDestPath = """ - log (sprintf "writing helper target file in '%s'" targetFileDestPath) - File.WriteAllText(targetFileDestPath, targetFileTemplate.Trim()) + let targetFileOnDisk = + if File.Exists(targetFileDestPath) then + try + Some (File.ReadAllText targetFileDestPath) + with + | _ -> None + else + None + + let newTargetFile = targetFileTemplate.Trim() + + if targetFileOnDisk <> Some newTargetFile then + log (sprintf "writing helper target file in '%s'" targetFileDestPath) + File.WriteAllText(targetFileDestPath, newTargetFile) Ok targetFileDestPath