-
Notifications
You must be signed in to change notification settings - Fork 0
/
EFCoreRemoveDesignerCompilationTask.cs
37 lines (31 loc) · 1.28 KB
/
EFCoreRemoveDesignerCompilationTask.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
using System.IO;
using System.Linq;
using Microsoft.Build.Framework;
using Task = Microsoft.Build.Utilities.Task;
namespace MSBuild.EntityFrameworkCore.RemoveDesignerCompilation
{
public class EFCoreRemoveDesignerCompilationTask : Task
{
[Required]
public string MigrationFilesPath { get; set; }
[Required]
public string DBContextNamespace { get; set; }
public int DesignerFileCountToKeep { get; set; } = 2;
[Output]
public string[] LatestDesignerFiles { get; set; }
public override bool Execute()
{
var efCoreFileManipulator = new EFCoreFileManipulator(Log);
var directory = new DirectoryInfo(MigrationFilesPath);
efCoreFileManipulator.ProcessDirectory(directory, DBContextNamespace);
var latestFiles = directory.EnumerateFiles("*.Designer.cs").OrderByDescending(x => x.Name).Take(DesignerFileCountToKeep);
LatestDesignerFiles = latestFiles.Select(x => x.FullName).ToArray();
foreach (var file in latestFiles)
{
Log.LogMessage(MessageImportance.High, $"RDC: Keeping file {file}");
}
Log.LogMessage(MessageImportance.High, $"RDC: Done");
return !Log.HasLoggedErrors;
}
}
}