99using System . Xml ;
1010using Lsj . Util . Collections ;
1111using Lsj . Util . JSON ;
12+ using Newtonsoft . Json ;
13+ using Newtonsoft . Json . Linq ;
1214
1315namespace UsingMSBuildCopyOutputFileToFastDebug
1416{
@@ -27,27 +29,19 @@ public bool Execute()
2729
2830 var text = File . ReadAllText ( file ) ;
2931
30- var o = JSONParser . Parse ( text ) ;
31- var profiles = o . profiles ;
32- var data = profiles . data ;
33- if ( data is SafeDictionary < string , object > d )
32+ var root = ( JObject ) JsonConvert . DeserializeObject ( text ) ;
33+ var profilesObject = ( JObject ) root [ " profiles" ] ;
34+
35+ foreach ( var keyValuePair in profilesObject )
3436 {
35- foreach ( var keyValuePair in d )
37+ var commandName = keyValuePair . Value [ "commandName" ] ;
38+ if ( commandName ? . ToString ( ) == "Executable" )
3639 {
37- if ( keyValuePair . Value is JSONObject jsonObject )
40+ var executablePath = keyValuePair . Value [ "executablePath" ] ;
41+ if ( executablePath != null )
3842 {
39- if ( jsonObject . TryGetMember ( new CustomGetMemberBinder ( "ExecutablePath" , true ) ,
40- out var filePath ) )
41- {
42- var path = filePath ? . ToString ( ) ;
43-
44- if ( ! string . IsNullOrEmpty ( path ) )
45- {
46- LaunchMainProjectPath = Path . GetDirectoryName ( path ) ;
47- Console . WriteLine ( $ "读取到 { LaunchMainProjectPath } 文件夹") ;
48- return true ;
49- }
50- }
43+ LaunchMainProjectPath = executablePath . ToString ( ) ;
44+ return true ;
5145 }
5246 }
5347 }
@@ -57,18 +51,4 @@ public bool Execute()
5751
5852 public string LaunchMainProjectPath { set ; get ; }
5953 }
60-
61- public class CustomGetMemberBinder : GetMemberBinder
62- {
63- /// <inheritdoc />
64- public CustomGetMemberBinder ( string name , bool ignoreCase ) : base ( name , ignoreCase )
65- {
66- }
67-
68- /// <inheritdoc />
69- public override DynamicMetaObject FallbackGetMember ( DynamicMetaObject target , DynamicMetaObject errorSuggestion )
70- {
71- return null ;
72- }
73- }
7454}
0 commit comments