Datei: NDOEnhancer/ProjectAssets.cs
Last Commit (006a7c7)
1 | using System; |
2 | using System.Collections.Generic; |
3 | using System.IO; |
4 | using System.Linq; |
5 | using System.Text; |
6 | using System.Text.RegularExpressions; |
7 | using System.Threading.Tasks; |
8 | using TinyJSON; |
9 | |
10 | namespace NDOEnhancer |
11 | { |
12 | ····class ProjectAssets |
13 | ····{ |
14 | ········static ProjectDescription projectDescription; |
15 | ········static ProjectAssets() |
16 | ········{ |
17 | ············projectDescription = (ProjectDescription) AppDomain.CurrentDomain.GetData( "ProjectDescription" ); |
18 | ········} |
19 | |
20 | ········public static string GetPackageDir( string packageName ) |
21 | ········{ |
22 | ············var json = new JSON(); |
23 | ············JSON.Object root; |
24 | ············var objPath = Path.Combine(projectDescription.ProjPath, "obj"); |
25 | ············var assetsPath = Path.Combine( objPath, "project.assets.json" ); |
26 | ············if (assetsPath == null) |
27 | ············{ |
28 | ················Console.WriteLine( $"Can't find assets file: {assetsPath}" ); |
29 | ················return null; |
30 | ············} |
31 | ············using (TextReader tr = new StreamReader( assetsPath )) |
32 | ················root = json.Parse( tr ).Value.AsObject(); |
33 | |
34 | ············var targets = root["targets"].AsObject(); |
35 | var standardKey = targets. First( o=>o. StartsWith( ". NETStandard, Version=") ) ; |
36 | ············var standard = targets[standardKey].AsObject(); |
37 | var packageKey = standard. First( o=>o. StartsWith( packageName + '/', StringComparison. OrdinalIgnoreCase) ) ; |
38 | ············var package = standard[packageKey].AsObject(); |
39 | ············var compile = package["compile"].AsObject().First(); |
40 | ············var relPath = packageKey + "/" + compile; |
41 | ············if (Path.DirectorySeparatorChar != '/') |
42 | ················relPath = relPath.Replace( '/', Path.DirectorySeparatorChar ); |
43 | ············//Regex regex = new Regex(@"netstandard\d\.\d"); |
44 | ············//relPath = regex.Replace( relPath, "net452" ); |
45 | ············return relPath; |
46 | ········} |
47 | |
48 | ········public static IEnumerable<string> GetPackageDirectories( string pattern ) |
49 | ········{ |
50 | ············var json = new JSON(); |
51 | ············JSON.Object root; |
52 | ············var objPath = Path.Combine(projectDescription.ProjPath, "obj"); |
53 | ············var assetsPath = Path.Combine( objPath, "project.assets.json" ); |
54 | ············if (assetsPath == null) |
55 | ············{ |
56 | ················Console.WriteLine( $"Can't find assets file: {assetsPath}" ); |
57 | ················return Enumerable.Empty<string>(); |
58 | ············} |
59 | ············using (TextReader tr = new StreamReader( assetsPath )) |
60 | ················root = json.Parse( tr ).Value.AsObject(); |
61 | |
62 | ············var targets = root["targets"].AsObject(); |
63 | ············var standardKey = targets.FirstOrDefault( o => o.StartsWith( ".NETStandard,Version=" ) || o.StartsWith( ".NETCoreApp,Version=" ) || o.StartsWith( "net" ) ); |
64 | ············if (standardKey == null) |
65 | ············{ |
66 | ················Console.WriteLine("Can't find any .NETStandard or .NETCoreApp target in the project.assets.json file"); |
67 | ················return Enumerable.Empty<string>(); |
68 | ············} |
69 | ············var standard = targets[standardKey].AsObject(); |
70 | ············Regex regex = new Regex(pattern + '/'); |
71 | ············var packageKeys = standard.Where(o=>regex.Match(o).Success); |
72 | ············var paths = packageKeys.Select(packageKey=> |
73 | ············{ |
74 | ················var package = standard[packageKey].AsObject(); |
75 | ················var compile = package["compile"].AsObject().First(); |
76 | ················var relPath = packageKey + "/" + compile; |
77 | ················if (Path.DirectorySeparatorChar != '/') |
78 | ····················relPath = relPath.Replace( '/', Path.DirectorySeparatorChar ); |
79 | ················//Regex regx = new Regex(@"netstandard\d\.\d"); |
80 | ················//relPath = regx.Replace( relPath, "net452" ); |
81 | ················return relPath; |
82 | ············} ); |
83 | ············return paths; |
84 | ········} |
85 | ····} |
86 | } |
87 |
New Commit (15fdc4b)
1 | using System; |
2 | using System.Collections.Generic; |
3 | using System.IO; |
4 | using System.Linq; |
5 | using System.Text; |
6 | using System.Text.RegularExpressions; |
7 | using System.Threading.Tasks; |
8 | using TinyJSON; |
9 | |
10 | namespace NDOEnhancer |
11 | { |
12 | ····class ProjectAssets |
13 | ····{ |
14 | ········static ProjectDescription projectDescription; |
15 | ········static ProjectAssets() |
16 | ········{ |
17 | ············projectDescription = (ProjectDescription) AppDomain.CurrentDomain.GetData( "ProjectDescription" ); |
18 | ········} |
19 | |
20 | ········public static string GetPackageDir( string packageName ) |
21 | ········{ |
22 | ············var json = new JSON(); |
23 | ············JSON.Object root; |
24 | ············var objPath = Path.Combine(projectDescription.ProjPath, "obj"); |
25 | ············var assetsPath = Path.Combine( objPath, "project.assets.json" ); |
26 | ············if (assetsPath == null) |
27 | ············{ |
28 | ················Console.WriteLine( $"Can't find assets file: {assetsPath}" ); |
29 | ················return null; |
30 | ············} |
31 | ············using (TextReader tr = new StreamReader( assetsPath )) |
32 | ················root = json.Parse( tr ).Value.AsObject(); |
33 | |
34 | ············var targets = root["targets"].AsObject(); |
35 | var standardKey = targets. FirstOrDefault( o=>o. StartsWith( ". NETStandard, Version=") ) ; |
36 | ············if (standardKey == null) |
37 | ················standardKey = targets.First(); |
38 | ············var standard = targets[standardKey].AsObject(); |
39 | var packageKey = standard. FirstOrDefault( o=>o. StartsWith( packageName + '/', StringComparison. OrdinalIgnoreCase) ) ; |
40 | ············if (packageKey == null) |
41 | ················throw new Exception( $"Package {packageName} not found in project.assets.json" ); |
42 | ············var package = standard[packageKey].AsObject(); |
43 | ············var compile = package["compile"].AsObject().First(); |
44 | ············var relPath = packageKey + "/" + compile; |
45 | ············if (Path.DirectorySeparatorChar != '/') |
46 | ················relPath = relPath.Replace( '/', Path.DirectorySeparatorChar ); |
47 | ············//Regex regex = new Regex(@"netstandard\d\.\d"); |
48 | ············//relPath = regex.Replace( relPath, "net452" ); |
49 | ············return relPath; |
50 | ········} |
51 | |
52 | ········public static IEnumerable<string> GetPackageDirectories( string pattern ) |
53 | ········{ |
54 | ············var json = new JSON(); |
55 | ············JSON.Object root; |
56 | ············var objPath = Path.Combine(projectDescription.ProjPath, "obj"); |
57 | ············var assetsPath = Path.Combine( objPath, "project.assets.json" ); |
58 | ············if (assetsPath == null) |
59 | ············{ |
60 | ················Console.WriteLine( $"Can't find assets file: {assetsPath}" ); |
61 | ················return Enumerable.Empty<string>(); |
62 | ············} |
63 | ············using (TextReader tr = new StreamReader( assetsPath )) |
64 | ················root = json.Parse( tr ).Value.AsObject(); |
65 | |
66 | ············var targets = root["targets"].AsObject(); |
67 | ············var standardKey = targets.FirstOrDefault( o => o.StartsWith( ".NETStandard,Version=" ) || o.StartsWith( ".NETCoreApp,Version=" ) || o.StartsWith( "net" ) ); |
68 | ············if (standardKey == null) |
69 | ············{ |
70 | ················Console.WriteLine("Can't find any .NETStandard or .NETCoreApp target in the project.assets.json file"); |
71 | ················return Enumerable.Empty<string>(); |
72 | ············} |
73 | ············var standard = targets[standardKey].AsObject(); |
74 | ············Regex regex = new Regex(pattern + '/'); |
75 | ············var packageKeys = standard.Where(o=>regex.Match(o).Success); |
76 | ············var paths = packageKeys.Select(packageKey=> |
77 | ············{ |
78 | ················var package = standard[packageKey].AsObject(); |
79 | ················var compile = package["compile"].AsObject().First(); |
80 | ················var relPath = packageKey + "/" + compile; |
81 | ················if (Path.DirectorySeparatorChar != '/') |
82 | ····················relPath = relPath.Replace( '/', Path.DirectorySeparatorChar ); |
83 | ················//Regex regx = new Regex(@"netstandard\d\.\d"); |
84 | ················//relPath = regx.Replace( relPath, "net452" ); |
85 | ················return relPath; |
86 | ············} ); |
87 | ············return paths; |
88 | ········} |
89 | ····} |
90 | } |
91 |