Skip to content

Commit

Permalink
Only write launchsettings if changed
Browse files Browse the repository at this point in the history
This avoids unnecessary refreshes in the compiler.
  • Loading branch information
kzu committed Oct 7, 2020
1 parent e7dd91b commit 7410fc1
Showing 1 changed file with 13 additions and 8 deletions.
21 changes: 13 additions & 8 deletions src/SmallSharp/LaunchSettingsGenerator.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
using System.Linq;
using Microsoft.CodeAnalysis;
using System.Collections.Generic;
using Newtonsoft.Json.Linq;
using System.IO;
using System.Linq;
using Microsoft.CodeAnalysis;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;

namespace SmallSharp
{
Expand Down Expand Up @@ -33,10 +32,16 @@ where compile
if (context.AnalyzerConfigOptions.GlobalOptions.TryGetValue("build_property.MSBuildProjectDirectory", out var directory))
{
Directory.CreateDirectory(Path.Combine(directory, "Properties"));
File.WriteAllText(
Path.Combine(directory, "Properties", "launchSettings.json"),
settings.ToString(Formatting.Indented));
var filePath = Path.Combine(directory, "Properties", "launchSettings.json");
var json = settings.ToString(Formatting.Indented);

// Only write if different content.
if (File.Exists(filePath) &&
File.ReadAllText(filePath) == json)
return;

File.WriteAllText(filePath, json);
}
}
}
}
}

0 comments on commit 7410fc1

Please sign in to comment.