Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix incremental builds #32860

Merged
merged 2 commits into from
Jan 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 24 additions & 5 deletions src/dotnet-ef/Project.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,16 +53,35 @@ public static Project FromFile(

Directory.CreateDirectory(buildExtensionsDir);

byte[] efTargets;
using (var input = typeof(Resources).Assembly.GetManifestResourceStream(
"Microsoft.EntityFrameworkCore.Tools.Resources.EntityFrameworkCore.targets")!)
{
efTargets = new byte[input.Length];
input.Read(efTargets);
}

var efTargetsPath = Path.Combine(
buildExtensionsDir,
Path.GetFileName(file) + ".EntityFrameworkCore.targets");
using (var input = typeof(Resources).Assembly.GetManifestResourceStream(
"Microsoft.EntityFrameworkCore.Tools.Resources.EntityFrameworkCore.targets")!)
using (var output = File.OpenWrite(efTargetsPath))

bool FileMatches()
{
try
{
return !File.ReadAllBytes(efTargetsPath).SequenceEqual(efTargets);
}
catch
{
return false;
}
}

// Avoid touching the targets file, if it matches what we need, to enable incremental builds
if (!File.Exists(efTargetsPath) || !FileMatches())
{
// NB: Copy always in case it changes
Reporter.WriteVerbose(Resources.WritingFile(efTargetsPath));
input.CopyTo(output);
File.WriteAllBytes(efTargetsPath, efTargets);
}

IDictionary<string, string> metadata;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@ public ModelCodeGeneratorTestFixture()

using (var input = typeof(ModelCodeGeneratorTestBase).Assembly.GetManifestResourceStream(
"Microsoft.EntityFrameworkCore.Resources.CSharpDbContextGenerator.tt"))
using (var output = File.OpenWrite(Path.Combine(templatesDir, "DbContext.t4")))
using (var output = File.Create(Path.Combine(templatesDir, "DbContext.t4")))
{
input.CopyTo(output);
}

using (var input = typeof(ModelCodeGeneratorTestBase).Assembly.GetManifestResourceStream(
"Microsoft.EntityFrameworkCore.Resources.CSharpEntityTypeGenerator.tt"))
using (var output = File.OpenWrite(Path.Combine(templatesDir, "EntityType.t4")))
using (var output = File.Create(Path.Combine(templatesDir, "EntityType.t4")))
{
input.CopyTo(output);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public BuildFileResult Build()

var targetPath = Path.Combine(TargetDir ?? Path.GetTempPath(), projectName + ".dll");

using (var stream = File.OpenWrite(targetPath))
using (var stream = File.Create(targetPath))
{
var result = compilation.Emit(stream);
if (!result.Success)
Expand Down
Loading