forked from dotnetcore/WebApiClient
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProxyTask.cs
More file actions
82 lines (76 loc) · 2.24 KB
/
ProxyTask.cs
File metadata and controls
82 lines (76 loc) · 2.24 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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
using Microsoft.Build.Framework;
using Microsoft.Build.Utilities;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
namespace WebApiClient.BuildTask
{
/// <summary>
/// 表示插入代理IL任务
/// </summary>
public class ProxyTask : Task
{
/// <summary>
/// 插入代理的程序集
/// </summary>
[Required]
public string TargetAssembly { get; set; }
/// <summary>
/// 引用的程序集
/// 逗号分隔
/// </summary>
[Required]
public ITaskItem[] References { get; set; }
/// <summary>
/// 执行任务
/// </summary>
/// <returns></returns>
public override bool Execute()
{
var logger = new Logger(this.Log);
if (File.Exists(this.TargetAssembly) == false)
{
logger.Message($"找不到文件编译输出的程序集{this.TargetAssembly}");
return true;
}
try
{
logger.Message(this.GetType().AssemblyQualifiedName);
var searchDirectories = this.GetSearchDirectories().Distinct().ToArray();
using (var assembly = new CeAssembly(this.TargetAssembly, searchDirectories, logger))
{
assembly.WirteProxyTypes();
}
return true;
}
catch (Exception ex)
{
logger.Error(ex.Message);
return false;
}
}
/// <summary>
/// 返回依赖搜索目录
/// </summary>
/// <returns></returns>
private IEnumerable<string> GetSearchDirectories()
{
if (this.References == null)
{
yield break;
}
foreach (var item in this.References)
{
if (string.IsNullOrEmpty(item.ItemSpec) == false)
{
var path = Path.GetDirectoryName(item.ItemSpec);
if (Directory.Exists(path) == true)
{
yield return path;
}
}
}
}
}
}