-
Notifications
You must be signed in to change notification settings - Fork 168
Expand file tree
/
Copy pathClearBuildTask.cs
More file actions
62 lines (56 loc) · 2.07 KB
/
ClearBuildTask.cs
File metadata and controls
62 lines (56 loc) · 2.07 KB
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
using Microsoft.Extensions.Logging;
using System;
using System.Collections.Generic;
using System.IO;
using System.Text;
using System.Threading.Tasks;
namespace SmartCode.App.BuildTasks
{
public class ClearBuildTask : IBuildTask
{
public ClearBuildTask(ILogger<ClearBuildTask> logger)
{
_logger = logger;
}
public bool Initialized => true;
public string Name => "Clear";
public Task Build(BuildContext context)
{
var paramters = context.Build.Paramters;
if (paramters == null) { return Task.CompletedTask; ; }
if (paramters.Value("Dirs", out string clearDirs))
{
var _clearDirs = clearDirs.Split(',');
foreach (var dir in _clearDirs)
{
var fullDir = Path.Combine(context.Project.OutputPath, dir);
_logger.LogInformation($"ClearBuildTask Delete directory:{fullDir} Start!");
if (Directory.Exists(fullDir))
{
Directory.Delete(fullDir, true);
}
_logger.LogInformation($"ClearBuildTask Delete directory:{fullDir} End!");
}
}
if (paramters.Value("Files", out string clearFiles))
{
var _clearFiles = clearFiles.Split(',');
foreach (var file in _clearFiles)
{
var fullfile = Path.Combine(context.Project.OutputPath, file);
_logger.LogInformation($"ClearBuildTask Delete file:{fullfile} Start!");
if (File.Exists(fullfile))
{
File.Delete(fullfile);
}
_logger.LogInformation($"ClearBuildTask Delete file:{fullfile} End!");
}
}
return Task.CompletedTask;
}
private readonly ILogger<ClearBuildTask> _logger;
public void Initialize(IDictionary<string, object> paramters)
{
}
}
}