少年修仙传客户端基础资源
dabaoji
2025-06-09 8ee0256378cbf5dbc9d76ed10b60b65a844ef4dd
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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.IO;
#if UNITY_XCODE_API_BUILD
using UnityEditor.iOS.Xcode.PBX;
#else
using UnityEditor.iOS.Xcode.Custom.PBX;
#endif
 
#if UNITY_XCODE_API_BUILD
namespace UnityEditor.iOS.Xcode
#else
namespace UnityEditor.iOS.Xcode.Custom
#endif
{
    using PBXBuildFileSection           = KnownSectionBase<PBXBuildFileData>;
    using PBXFileReferenceSection       = KnownSectionBase<PBXFileReferenceData>;
    using PBXGroupSection               = KnownSectionBase<PBXGroupData>;
    using PBXContainerItemProxySection  = KnownSectionBase<PBXContainerItemProxyData>;
    using PBXReferenceProxySection      = KnownSectionBase<PBXReferenceProxyData>;
    using PBXSourcesBuildPhaseSection   = KnownSectionBase<PBXSourcesBuildPhaseData>;
    using PBXFrameworksBuildPhaseSection= KnownSectionBase<PBXFrameworksBuildPhaseData>;
    using PBXResourcesBuildPhaseSection = KnownSectionBase<PBXResourcesBuildPhaseData>;
    using PBXCopyFilesBuildPhaseSection = KnownSectionBase<PBXCopyFilesBuildPhaseData>;
    using PBXShellScriptBuildPhaseSection = KnownSectionBase<PBXShellScriptBuildPhaseData>;
    using PBXVariantGroupSection        = KnownSectionBase<PBXVariantGroupData>;
    using PBXNativeTargetSection        = KnownSectionBase<PBXNativeTargetData>;
    using PBXTargetDependencySection    = KnownSectionBase<PBXTargetDependencyData>;
    using XCBuildConfigurationSection   = KnownSectionBase<XCBuildConfigurationData>;
    using XCConfigurationListSection    = KnownSectionBase<XCConfigurationListData>;
    using UnknownSection                = KnownSectionBase<PBXObjectData>;
 
    // Determines the tree the given path is relative to
    public enum PBXSourceTree
    {
        Absolute,   // The path is absolute
        Source,     // The path is relative to the source folder
        Group,      // The path is relative to the folder it's in. This enum is used only internally,
        // do not use it as function parameter
        Build,      // The path is relative to the build products folder
        Developer,  // The path is relative to the developer folder
        Sdk         // The path is relative to the sdk folder
    }
 
    public class PBXProject
    {
        PBXProjectData m_Data = new PBXProjectData();
 
        // convenience accessors for public members of data. This is temporary; will be fixed by an interface change
        // of PBXProjectData
        internal PBXContainerItemProxySection containerItems { get { return m_Data.containerItems; } }
        internal PBXReferenceProxySection references         { get { return m_Data.references; } }
        internal PBXSourcesBuildPhaseSection sources         { get { return m_Data.sources; } }
        internal PBXFrameworksBuildPhaseSection frameworks   { get { return m_Data.frameworks; } }
        internal PBXResourcesBuildPhaseSection resources     { get { return m_Data.resources; } }
        internal PBXCopyFilesBuildPhaseSection copyFiles     { get { return m_Data.copyFiles; } }
        internal PBXShellScriptBuildPhaseSection shellScripts { get { return m_Data.shellScripts; } }
        internal PBXNativeTargetSection nativeTargets        { get { return m_Data.nativeTargets; } }
        internal PBXTargetDependencySection targetDependencies { get { return m_Data.targetDependencies; } }
        internal PBXVariantGroupSection variantGroups        { get { return m_Data.variantGroups; } }
        internal XCBuildConfigurationSection buildConfigs    { get { return m_Data.buildConfigs; } }
        internal XCConfigurationListSection buildConfigLists { get { return m_Data.buildConfigLists; } }
        internal PBXProjectSection project                   { get { return m_Data.project; } }
 
        internal PBXBuildFileData BuildFilesGet(string guid) { return m_Data.BuildFilesGet(guid); }
        internal void BuildFilesAdd(string targetGuid, PBXBuildFileData buildFile) { m_Data.BuildFilesAdd(targetGuid, buildFile); }
        internal void BuildFilesRemove(string targetGuid, string fileGuid) { m_Data.BuildFilesRemove(targetGuid, fileGuid); }
        internal PBXBuildFileData BuildFilesGetForSourceFile(string targetGuid, string fileGuid) { return m_Data.BuildFilesGetForSourceFile(targetGuid, fileGuid); }
        internal IEnumerable<PBXBuildFileData> BuildFilesGetAll() { return m_Data.BuildFilesGetAll(); }
        internal void FileRefsAdd(string realPath, string projectPath, PBXGroupData parent, PBXFileReferenceData fileRef) { m_Data.FileRefsAdd(realPath, projectPath, parent, fileRef); }
        internal PBXFileReferenceData FileRefsGet(string guid) { return m_Data.FileRefsGet(guid); }
        internal PBXFileReferenceData FileRefsGetByRealPath(string path, PBXSourceTree sourceTree) { return m_Data.FileRefsGetByRealPath(path, sourceTree); }
        internal PBXFileReferenceData FileRefsGetByProjectPath(string path) { return m_Data.FileRefsGetByProjectPath(path); }
        internal void FileRefsRemove(string guid) { m_Data.FileRefsRemove(guid); }
        internal PBXGroupData GroupsGet(string guid) { return m_Data.GroupsGet(guid); }
        internal PBXGroupData GroupsGetByChild(string childGuid) { return m_Data.GroupsGetByChild(childGuid); }
        internal PBXGroupData GroupsGetMainGroup() { return m_Data.GroupsGetMainGroup(); }
        internal PBXGroupData GroupsGetByProjectPath(string sourceGroup) { return m_Data.GroupsGetByProjectPath(sourceGroup); }
        internal void GroupsAdd(string projectPath, PBXGroupData parent, PBXGroupData gr) { m_Data.GroupsAdd(projectPath, parent, gr); }
        internal void GroupsAddDuplicate(PBXGroupData gr) { m_Data.GroupsAddDuplicate(gr); }
        internal void GroupsRemove(string guid) { m_Data.GroupsRemove(guid); }
        internal FileGUIDListBase BuildSectionAny(PBXNativeTargetData target, string path, bool isFolderRef) { return m_Data.BuildSectionAny(target, path, isFolderRef); }
        internal FileGUIDListBase BuildSectionAny(string sectionGuid) { return m_Data.BuildSectionAny(sectionGuid); }
 
        /// <summary>
        /// Returns the path to PBX project in the given Unity build path. This function can only 
        /// be used in Unity-generated projects
        /// </summary>
        /// <param name="buildPath">The project build path</param>
        /// <returns>The path to the PBX project file that can later be opened via ReadFromFile function</returns> 
        public static string GetPBXProjectPath(string buildPath)
        {
            return PBXPath.Combine(buildPath, "Unity-iPhone.xcodeproj/project.pbxproj");
        }
 
        /// <summary>
        /// Returns the default main target name in Unity project.
        /// The returned target name can then be used to retrieve the GUID of the target via TargetGuidByName 
        /// function. This function can only be used in Unity-generated projects.
        /// </summary>
        /// <returns>The default main target name.</returns>
        public static string GetUnityTargetName()
        {
            return "Unity-iPhone";
        }
 
        /// <summary>
        /// Returns the default test target name in Unity project.
        /// The returned target name can then be used to retrieve the GUID of the target via TargetGuidByName 
        /// function. This function can only be used in Unity-generated projects.
        /// </summary>
        /// <returns>The default test target name.</returns>
        public static string GetUnityTestTargetName()
        {
            return "Unity-iPhone Tests";
        }
 
        /// <summary>
        /// Returns the GUID of the project. The project GUID identifies a project-wide native target which
        /// is used to set project-wide properties. This GUID can be passed to any functions that accepts 
        /// target GUIDs as parameters.
        /// </summary>
        /// <returns>The GUID of the project.</returns>
        public string ProjectGuid()
        {
            return project.project.guid;
        }
 
        /// <summary>
        /// Returns the GUID of the native target with the given name.
        /// In projects produced by Unity the main target can be retrieved via GetUnityTargetName function, 
        /// whereas the test target name can be retrieved by GetUnityTestTargetName function.
        /// </summary>
        /// <returns>The name of the native target.</returns>
        /// <param name="name">The GUID identifying the native target.</param>
        public string TargetGuidByName(string name)
        {
            foreach (var entry in nativeTargets.GetEntries())
                if (entry.Value.name == name)
                    return entry.Key;
            return null;
        }
 
        /// <summary>
        /// Checks if files with the given extension are known to PBXProject.
        /// </summary>
        /// <returns>Returns <c>true</c> if is the extension is known, <c>false</c> otherwise.</returns>
        /// <param name="ext">The file extension (leading dot is not necessary, but accepted).</param>
        public static bool IsKnownExtension(string ext)
        {
            return FileTypeUtils.IsKnownExtension(ext);
        }
 
        /// <summary>
        /// Checks if files with the given extension are known to PBXProject.
        /// Returns <c>true</c> if the extension is not known by PBXProject.
        /// </summary>
        /// <returns>Returns <c>true</c> if is the extension is known, <c>false</c> otherwise.</returns>
        /// <param name="ext">The file extension (leading dot is not necessary, but accepted).</param>
        public static bool IsBuildable(string ext)
        {
            return FileTypeUtils.IsBuildableFile(ext);
        }
 
        // The same file can be referred to by more than one project path.
        private string AddFileImpl(string path, string projectPath, PBXSourceTree tree, bool isFolderReference)
        {
            path = PBXPath.FixSlashes(path);
            projectPath = PBXPath.FixSlashes(projectPath);
 
            if (!isFolderReference && Path.GetExtension(path) != Path.GetExtension(projectPath))
                throw new Exception("Project and real path extensions do not match");
 
            string guid = FindFileGuidByProjectPath(projectPath);
            if (guid == null)
                guid = FindFileGuidByRealPath(path);
            if (guid == null)
            {
                PBXFileReferenceData fileRef;
                if (isFolderReference)
                    fileRef = PBXFileReferenceData.CreateFromFolderReference(path, PBXPath.GetFilename(projectPath), tree);
                else
                    fileRef = PBXFileReferenceData.CreateFromFile(path, PBXPath.GetFilename(projectPath), tree);
                PBXGroupData parent = CreateSourceGroup(PBXPath.GetDirectory(projectPath));
                parent.children.AddGUID(fileRef.guid);
                FileRefsAdd(path, projectPath, parent, fileRef);
                guid = fileRef.guid;
            }
            return guid;
        }
 
        /// <summary>
        /// Adds a new file reference to the list of known files.
        /// The group structure is automatically created to correspond to the project path.
        /// To add the file to the list of files to build, pass the returned value to [[AddFileToBuild]].
        /// </summary>
        /// <returns>The GUID of the added file. It can later be used to add the file for building to targets, etc.</returns>
        /// <param name="path">The physical path to the file on the filesystem.</param>
        /// <param name="projectPath">The project path to the file.</param>
        /// <param name="sourceTree">The source tree the path is relative to. By default it's [[PBXSourceTree.Source]].
        /// The [[PBXSourceTree.Group]] tree is not supported.</param>
        public string AddFile(string path, string projectPath, PBXSourceTree sourceTree = PBXSourceTree.Source)
        {
            if (sourceTree == PBXSourceTree.Group)
                throw new Exception("sourceTree must not be PBXSourceTree.Group");
            return AddFileImpl(path, projectPath, sourceTree, false);
        }
 
        /// <summary>
        /// Adds a new folder reference to the list of known files.
        /// The group structure is automatically created to correspond to the project path.
        /// To add the folder reference to the list of files to build, pass the returned value to [[AddFileToBuild]].
        /// </summary>
        /// <returns>The GUID of the added folder reference. It can later be used to add the file for building to targets, etc.</returns>
        /// <param name="path">The physical path to the folder on the filesystem.</param>
        /// <param name="projectPath">The project path to the folder.</param>
        /// <param name="sourceTree">The source tree the path is relative to. By default it's [[PBXSourceTree.Source]].
        /// The [[PBXSourceTree.Group]] tree is not supported.</param>
        public string AddFolderReference(string path, string projectPath, PBXSourceTree sourceTree = PBXSourceTree.Source)
        {
            if (sourceTree == PBXSourceTree.Group)
                throw new Exception("sourceTree must not be PBXSourceTree.Group");
            return AddFileImpl(path, projectPath, sourceTree, true);
        }
 
        private void AddBuildFileImpl(string targetGuid, string fileGuid, bool weak, string compileFlags)
        {
            PBXNativeTargetData target = nativeTargets[targetGuid];
            PBXFileReferenceData fileRef = FileRefsGet(fileGuid);
            
            string ext = Path.GetExtension(fileRef.path);
 
            if (FileTypeUtils.IsBuildable(ext, fileRef.isFolderReference) &&
                BuildFilesGetForSourceFile(targetGuid, fileGuid) == null)
            {
                PBXBuildFileData buildFile = PBXBuildFileData.CreateFromFile(fileGuid, weak, compileFlags);
                BuildFilesAdd(targetGuid, buildFile);
                BuildSectionAny(target, ext, fileRef.isFolderReference).files.AddGUID(buildFile.guid);
            }
        }
 
        /// <summary>
        /// Configures file for building for the given native target.
        /// A projects containing multiple native targets, a single file or folder reference can be 
        /// configured to be built in all, some or none of the targets. The file or folder reference is 
        /// added to appropriate build section depending on the file extension.
        /// </summary>
        /// <param name="targetGuid">The GUID of the target as returned by [[TargetGuidByName()]].</param>
        /// <param name="fileGuid">The file guid returned by [[AddFile]] or [[AddFolderReference]].</param>
        public void AddFileToBuild(string targetGuid, string fileGuid)
        {
            AddBuildFileImpl(targetGuid, fileGuid, false, null);
        }
 
        /// <summary>
        /// Configures file for building for the given native target with specific compiler flags.
        /// The function is equivalent to [[AddFileToBuild()]] except that compile flags are specified.
        /// A projects containing multiple native targets, a single file or folder reference can be 
        /// configured to be built in all, some or none of the targets. The file or folder reference is 
        /// added to appropriate build section depending on the file extension.
        /// </summary>
        /// <param name="targetGuid">The GUID of the target as returned by [[TargetGuidByName()]].</param>
        /// <param name="fileGuid">The file guid returned by [[AddFile]] or [[AddFolderReference]].</param>
        /// <param name="compileFlags">Compile flags to use.</param>
        public void AddFileToBuildWithFlags(string targetGuid, string fileGuid, string compileFlags)
        {
            AddBuildFileImpl(targetGuid, fileGuid, false, compileFlags);
        }
 
        /// <summary>
        /// Configures file for building for the given native target on specific build section.
        /// The function is equivalent to [[AddFileToBuild()]] except that specific build section is specified.
        /// A projects containing multiple native targets, a single file or folder reference can be 
        /// configured to be built in all, some or none of the targets. The file or folder reference is 
        /// added to appropriate build section depending on the file extension.
        /// </summary>
        /// <param name="targetGuid">The GUID of the target as returned by [[TargetGuidByName()]].</param>
        /// <param name="sectionGuid">The GUID of the section to add the file to.</param>
        /// <param name="fileGuid">The file guid returned by [[AddFile]] or [[AddFolderReference]].</param>
        public void AddFileToBuildSection(string targetGuid, string sectionGuid, string fileGuid)
        {
            PBXBuildFileData buildFile = PBXBuildFileData.CreateFromFile(fileGuid, false, null);
            BuildFilesAdd(targetGuid, buildFile);
            BuildSectionAny(sectionGuid).files.AddGUID(buildFile.guid);
        }
 
        /// <summary>
        /// Returns compile flags set for the specific file.
        /// Null is returned if the file has no configured compile flags or the file is not configured for
        /// building on the given target.
        /// </summary>
        /// <returns>The compile flags for the specified file.</returns>
        /// <param name="targetGuid">The GUID of the target as returned by [[TargetGuidByName()]].</param>
        /// <param name="fileGuid">The GUID of the file.</param>
        public List<string> GetCompileFlagsForFile(string targetGuid, string fileGuid)
        {
            var buildFile = BuildFilesGetForSourceFile(targetGuid, fileGuid);
            if (buildFile == null)
                return null;
            if (buildFile.compileFlags == null)
                return new List<string>();
            return new List<string>(buildFile.compileFlags.Split(new char[]{' '}, StringSplitOptions.RemoveEmptyEntries));
        }
 
        /// <summary>
        /// Sets the compilation flags for the given file in the given target.
        /// </summary>
        /// <param name="targetGuid">The GUID of the target as returned by [[TargetGuidByName()]].</param>
        /// <param name="fileGuid">The GUID of the file.</param>
        /// <param name="compileFlags">The list of compile flags or null if the flags should be unset.</param>
        public void SetCompileFlagsForFile(string targetGuid, string fileGuid, List<string> compileFlags)
        {
            var buildFile = BuildFilesGetForSourceFile(targetGuid, fileGuid);
            if (buildFile == null)
                return;
            if (compileFlags == null)
                buildFile.compileFlags = null;
            else
                buildFile.compileFlags = string.Join(" ", compileFlags.ToArray());
        }
 
        /// <summary>
        /// Adds an asset tag for the given file.
        /// The asset tags identify resources that will be downloaded via On Demand Resources functionality. 
        /// A request for specific tag will initiate download of all files, configured for that tag.
        /// </summary>
        /// <param name="targetGuid">The GUID of the target as returned by [[TargetGuidByName()]].</param>
        /// <param name="fileGuid">The GUID of the file.</param>
        /// <param name="tag">The name of the asset tag.</param>
        public void AddAssetTagForFile(string targetGuid, string fileGuid, string tag)
        {
            var buildFile = BuildFilesGetForSourceFile(targetGuid, fileGuid);
            if (buildFile == null)
                return;
            if (!buildFile.assetTags.Contains(tag))
                buildFile.assetTags.Add(tag);
            if (!project.project.knownAssetTags.Contains(tag))
                project.project.knownAssetTags.Add(tag);
        }
 
        /// <summary>
        /// Removes an asset tag for the given file.
        /// The function does nothing if the file is not configured for building in the given target or if
        /// the asset tag is not present in the list of asset tags configured for file. If the file was the
        /// last file referring to the given tag across the Xcode project, then the tag is removed from the
        /// list of known tags.
        /// </summary>
        /// <param name="targetGuid">The GUID of the target as returned by [[TargetGuidByName()]].</param>
        /// <param name="fileGuid">The GUID of the file.</param>
        /// <param name="tag">The name of the asset tag.</param>
        public void RemoveAssetTagForFile(string targetGuid, string fileGuid, string tag)
        {
            var buildFile = BuildFilesGetForSourceFile(targetGuid, fileGuid);
            if (buildFile == null)
                return;
            buildFile.assetTags.Remove(tag);
            // remove from known tags if this was the last one
            foreach (var buildFile2 in BuildFilesGetAll())
            {
                if (buildFile2.assetTags.Contains(tag))
                    return;
            }
            project.project.knownAssetTags.Remove(tag);
        }
 
        /// <summary>
        /// Adds the asset tag to the list of tags to download during initial installation.
        /// The function does nothing if there are no files that use the given asset tag across the project.
        /// </summary>
        /// <param name="targetGuid">The GUID of the target as returned by [[TargetGuidByName()]].</param>
        /// <param name="tag">The name of the asset tag.</param>
        public void AddAssetTagToDefaultInstall(string targetGuid, string tag)
        {
            if (!project.project.knownAssetTags.Contains(tag))
                return;
            AddBuildProperty(targetGuid, "ON_DEMAND_RESOURCES_INITIAL_INSTALL_TAGS", tag);
        }
 
        /// <summary>
        /// Removes the asset tag from the list of tags to download during initial installation.
        /// The function does nothing if the tag is not already configured for downloading during 
        /// initial installation.
        /// </summary>
        /// <param name="targetGuid">The GUID of the target as returned by [[TargetGuidByName()]].</param>
        /// <param name="tag">The name of the asset tag.</param>
        public void RemoveAssetTagFromDefaultInstall(string targetGuid, string tag)
        {
            UpdateBuildProperty(targetGuid, "ON_DEMAND_RESOURCES_INITIAL_INSTALL_TAGS", null, new[]{tag});
        }
 
        /// <summary>
        /// Removes an asset tag.
        /// Removes the given asset tag from the list of configured asset tags for all files on all targets,
        /// the list of asset tags configured for initial installation and the list of known asset tags in 
        /// the Xcode project.
        /// </summary>
        /// <param name="tag">The name of the asset tag.</param>
        public void RemoveAssetTag(string tag)
        {
            foreach (var buildFile in BuildFilesGetAll())
                buildFile.assetTags.Remove(tag);
            foreach (var targetGuid in nativeTargets.GetGuids())
                RemoveAssetTagFromDefaultInstall(targetGuid, tag);
            project.project.knownAssetTags.Remove(tag);
        }
 
        /// <summary>
        /// Checks if the project contains a file with the given physical path.
        /// The search is performed across all absolute source trees.
        /// </summary>
        /// <returns>Returns <c>true</c> if the project contains the file, <c>false</c> otherwise.</returns>
        /// <param name="path">The physical path of the file.</param>
        public bool ContainsFileByRealPath(string path)
        {
            return FindFileGuidByRealPath(path) != null;
        }
 
        /// <summary>
        /// Checks if the project contains a file with the given physical path.
        /// </summary>
        /// <returns>Returns <c>true</c> if the project contains the file, <c>false</c> otherwise.</returns>
        /// <param name="path">The physical path of the file.</param>
        /// <param name="sourceTree">The source tree path is relative to. The [[PBXSourceTree.Group]] tree is not supported.</param>
        public bool ContainsFileByRealPath(string path, PBXSourceTree sourceTree)
        {
            if (sourceTree == PBXSourceTree.Group)
                throw new Exception("sourceTree must not be PBXSourceTree.Group");
            return FindFileGuidByRealPath(path, sourceTree) != null;
        }
 
        /// <summary>
        /// Checks if the project contains a file with the given project path.
        /// </summary>
        /// <returns>Returns <c>true</c> if the project contains the file, <c>false</c> otherwise.</returns>
        /// <param name="path">The project path of the file.</param>
        public bool ContainsFileByProjectPath(string path)
        {
            return FindFileGuidByProjectPath(path) != null;
        }
 
        /// <summary>
        /// Checks whether the given system framework is a dependency of a target.
        /// The function assumes system frameworks are located in System/Library/Frameworks folder in the SDK source tree.
        /// </summary>
        /// <returns>Returns <c>true</c> if the given framework is a dependency of the given target,
        /// <c>false</c> otherwise.</returns>
        /// <param name="targetGuid">The GUID of the target as returned by [[TargetGuidByName()]].</param>
        /// <param name="framework">The name of the framework. The extension of the filename must be ".framework".</param>
        public bool ContainsFramework(string targetGuid, string framework)
        {
            var fileGuid = FindFileGuidByRealPath("System/Library/Frameworks/" + framework, PBXSourceTree.Sdk);
            if (fileGuid == null)
                return false;
 
            var buildFile = BuildFilesGetForSourceFile(targetGuid, fileGuid);
            return (buildFile != null);
        }
 
        /// <summary>
        /// Adds a system framework dependency for the specified target.
        /// The function assumes system frameworks are located in System/Library/Frameworks folder in the SDK source tree. 
        /// The framework is added to Frameworks logical folder in the project.
        /// </summary>
        /// <param name="targetGuid">The GUID of the target as returned by [[TargetGuidByName()]].</param>
        /// <param name="framework">The name of the framework. The extension of the filename must be ".framework".</param>
        /// <param name="weak"><c>true</c> if the framework is optional (i.e. weakly linked) required, 
        /// <c>false</c> if the framework is required.</param>
        public void AddFrameworkToProject(string targetGuid, string framework, bool weak)
        {
            string fileGuid = AddFile("System/Library/Frameworks/" + framework, "Frameworks/" + framework, PBXSourceTree.Sdk);
            AddBuildFileImpl(targetGuid, fileGuid, weak, null);
        }
 
        /// <summary>
        /// Removes a system framework dependency for the specified target.
        /// The function assumes system frameworks are located in System/Library/Frameworks folder in the SDK source tree.
        /// </summary>
        /// <param name="targetGuid">The GUID of the target as returned by [[TargetGuidByName()]].</param>
        /// <param name="framework">The name of the framework. The extension of the filename must be ".framework".</param>
        public void RemoveFrameworkFromProject(string targetGuid, string framework)
        {
            var fileGuid = FindFileGuidByRealPath("System/Library/Frameworks/" + framework, PBXSourceTree.Sdk);
            if (fileGuid == null)
                return;
 
            BuildFilesRemove(targetGuid, fileGuid);
        }
 
        // Allow user to add a Capability
        public bool AddCapability(string targetGuid, PBXCapabilityType capability, string entitlementsFilePath = null, bool addOptionalFramework = false)
        {
            // If the capability requires entitlements then you have to provide the name of it or we don't add the capability.
            if (capability.requiresEntitlements && entitlementsFilePath == "")
            {
                throw new Exception("Couldn't add the Xcode Capability " + capability.id + " to the PBXProject file because this capability requires an entitlement file.");
            }
            var p = project.project;
 
            // If an entitlement with a different name was added for another capability
            // we don't add this capacity.
            if (p.entitlementsFile != null && entitlementsFilePath != null && p.entitlementsFile != entitlementsFilePath)
            {
                if (p.capabilities.Count > 0)
                    throw new WarningException("Attention, it seems that you have multiple entitlements file. Only one will be added the Project : " + p.entitlementsFile);
 
                return false;
            }
 
            // Add the capability only if it doesn't already exist.
            if (p.capabilities.Contains(new PBXCapabilityType.TargetCapabilityPair(targetGuid, capability)))
            {
                throw new WarningException("This capability has already been added. Method ignored");
            }
 
            p.capabilities.Add(new PBXCapabilityType.TargetCapabilityPair(targetGuid, capability));
 
            // Add the required framework.
            if (capability.framework != "" && !capability.optionalFramework ||
               (capability.framework != "" && capability.optionalFramework && addOptionalFramework))
            {
                AddFrameworkToProject(targetGuid, capability.framework, false);
            }
 
            // Finally add the entitlement code signing if it wasn't added before.
            if (entitlementsFilePath != null && p.entitlementsFile == null)
            {
                p.entitlementsFile = entitlementsFilePath;
                AddFileImpl(entitlementsFilePath,  entitlementsFilePath, PBXSourceTree.Source, false);
                SetBuildProperty(targetGuid, "CODE_SIGN_ENTITLEMENTS", PBXPath.FixSlashes(entitlementsFilePath));
            }
            return true;
        }
 
        // The Xcode project needs a team set to be able to complete code signing or to add some capabilities.
        public void SetTeamId(string targetGuid, string teamId)
        {
            SetBuildProperty(targetGuid, "DEVELOPMENT_TEAM", teamId);
            project.project.teamIDs.Add(targetGuid, teamId);
        }
 
        /// <summary>
        /// Finds a file with the given physical path in the project, if any.
        /// </summary>
        /// <returns>The GUID of the file if the search succeeded, null otherwise.</returns>
        /// <param name="path">The physical path of the file.</param>
        /// <param name="sourceTree">The source tree path is relative to. The [[PBXSourceTree.Group]] tree is not supported.</param>
        public string FindFileGuidByRealPath(string path, PBXSourceTree sourceTree)
        {
            if (sourceTree == PBXSourceTree.Group)
                throw new Exception("sourceTree must not be PBXSourceTree.Group");
            path = PBXPath.FixSlashes(path);
            var fileRef = FileRefsGetByRealPath(path, sourceTree);
            if (fileRef != null)
                return fileRef.guid;
            return null;
        }
 
        /// <summary>
        /// Finds a file with the given physical path in the project, if any.
        /// The search is performed across all absolute source trees.
        /// </summary>
        /// <returns>The GUID of the file if the search succeeded, null otherwise.</returns>
        /// <param name="path">The physical path of the file.</param>
        public string FindFileGuidByRealPath(string path)
        {
            path = PBXPath.FixSlashes(path);
 
            foreach (var tree in FileTypeUtils.AllAbsoluteSourceTrees())
            {
                string res = FindFileGuidByRealPath(path, tree);
                if (res != null)
                    return res;
            }
            return null;
        }
 
        /// <summary>
        /// Finds a file with the given project path in the project, if any.
        /// </summary>
        /// <returns>The GUID of the file if the search succeeded, null otherwise.</returns>
        /// <param name="path">The project path of the file.</param>
        public string FindFileGuidByProjectPath(string path)
        {
            path = PBXPath.FixSlashes(path);
            var fileRef = FileRefsGetByProjectPath(path);
            if (fileRef != null)
                return fileRef.guid;
            return null;
        }
 
        /// <summary>
        /// Removes given file from the list of files to build for the given target.
        /// </summary>
        /// <param name="targetGuid">The GUID of the target as returned by [[TargetGuidByName()]].</param>
        /// <param name="fileGuid">The GUID of the file or folder reference.</param>
        public void RemoveFileFromBuild(string targetGuid, string fileGuid)
        {
            var buildFile = BuildFilesGetForSourceFile(targetGuid, fileGuid);
            if (buildFile == null)
                return;
            BuildFilesRemove(targetGuid, fileGuid);
 
            string buildGuid = buildFile.guid;
            if (buildGuid != null)
            {
                foreach (var section in sources.GetEntries())
                    section.Value.files.RemoveGUID(buildGuid);
                foreach (var section in resources.GetEntries())
                    section.Value.files.RemoveGUID(buildGuid);
                foreach (var section in copyFiles.GetEntries())
                    section.Value.files.RemoveGUID(buildGuid);
                foreach (var section in frameworks.GetEntries())
                    section.Value.files.RemoveGUID(buildGuid);
            }
        }
 
        /// <summary>
        /// Removes the given file from project.
        /// The file is removed from the list of files to build for each native target and also removed 
        /// from the list of known files.
        /// </summary>
        /// <param name="fileGuid">The GUID of the file or folder reference.</param>
        public void RemoveFile(string fileGuid)
        {
            if (fileGuid == null)
                return;
 
            // remove from parent
            PBXGroupData parent = GroupsGetByChild(fileGuid);
            if (parent != null)
                parent.children.RemoveGUID(fileGuid);
            RemoveGroupIfEmpty(parent);
 
            // remove actual file
            foreach (var target in nativeTargets.GetEntries())
                RemoveFileFromBuild(target.Value.guid, fileGuid);
            FileRefsRemove(fileGuid);
        }
 
        void RemoveGroupIfEmpty(PBXGroupData gr)
        {
            if (gr.children.Count == 0 && gr != GroupsGetMainGroup())
            {
                // remove from parent
                PBXGroupData parent = GroupsGetByChild(gr.guid);
                parent.children.RemoveGUID(gr.guid);
                RemoveGroupIfEmpty(parent);
 
                // remove actual group
                GroupsRemove(gr.guid);
            }
        }
 
        private void RemoveGroupChildrenRecursive(PBXGroupData parent)
        {
            List<string> children = new List<string>(parent.children);
            parent.children.Clear();
            foreach (string guid in children)
            {
                PBXFileReferenceData file = FileRefsGet(guid);
                if (file != null)
                {
                    foreach (var target in nativeTargets.GetEntries())
                        RemoveFileFromBuild(target.Value.guid, guid);
                    FileRefsRemove(guid);
                    continue;
                }
 
                PBXGroupData gr = GroupsGet(guid);
                if (gr != null)
                {
                    RemoveGroupChildrenRecursive(gr);
                    GroupsRemove(gr.guid);
                    continue;
                }
            }
        }
 
        internal void RemoveFilesByProjectPathRecursive(string projectPath)
        {
            projectPath = PBXPath.FixSlashes(projectPath);
            PBXGroupData gr = GroupsGetByProjectPath(projectPath);
            if (gr == null)
                return;
            RemoveGroupChildrenRecursive(gr);
            RemoveGroupIfEmpty(gr);
        }
 
        // Returns null on error
        internal List<string> GetGroupChildrenFiles(string projectPath)
        {
            projectPath = PBXPath.FixSlashes(projectPath);
            PBXGroupData gr = GroupsGetByProjectPath(projectPath);
            if (gr == null)
                return null;
            var res = new List<string>();
            foreach (var guid in gr.children)
            {
                PBXFileReferenceData fileRef = FileRefsGet(guid);
                if (fileRef != null)
                    res.Add(fileRef.name);
            }
            return res;
        }
 
        // Returns an empty dictionary if no group or files are found
        internal HashSet<string> GetGroupChildrenFilesRefs(string projectPath)
        {
            projectPath = PBXPath.FixSlashes(projectPath);
            PBXGroupData gr = GroupsGetByProjectPath(projectPath);
            if (gr == null)
                return new HashSet<string>();
            HashSet<string> res = new HashSet<string>();
            foreach (var guid in gr.children)
            {
                PBXFileReferenceData fileRef = FileRefsGet(guid);
                if (fileRef != null)
                    res.Add(fileRef.path);
            }
            return res == null ? new HashSet<string> () : res;
        }
 
        internal HashSet<string> GetFileRefsByProjectPaths(IEnumerable<string> paths)
        {
            HashSet<string> ret = new HashSet<string>();
            foreach (string path in paths)
            {
                string fixedPath = PBXPath.FixSlashes(path);
                var fileRef = FileRefsGetByProjectPath(fixedPath);
                if (fileRef != null)
                    ret.Add(fileRef.path);
            }
            return ret;
        }
 
        private PBXGroupData GetPBXGroupChildByName(PBXGroupData group, string name)
        {
            foreach (string guid in group.children)
            {
                var gr = GroupsGet(guid);
                if (gr != null && gr.name == name)
                    return gr;
            }
            return null;
        }
 
        /// Creates source group identified by sourceGroup, if needed, and returns it.
        /// If sourceGroup is empty or null, root group is returned
        internal PBXGroupData CreateSourceGroup(string sourceGroup)
        {
            sourceGroup = PBXPath.FixSlashes(sourceGroup);
 
            if (sourceGroup == null || sourceGroup == "")
                return GroupsGetMainGroup();
 
            PBXGroupData gr = GroupsGetByProjectPath(sourceGroup);
            if (gr != null)
                return gr;
 
            // the group does not exist -- create new
            gr = GroupsGetMainGroup();
 
            var elements = PBXPath.Split(sourceGroup);
            string projectPath = null;
            foreach (string pathEl in elements)
            {
                if (projectPath == null)
                    projectPath = pathEl;
                else
                    projectPath += "/" + pathEl;
 
                PBXGroupData child = GetPBXGroupChildByName(gr, pathEl);
                if (child != null)
                    gr = child;
                else
                {
                    PBXGroupData newGroup = PBXGroupData.Create(pathEl, pathEl, PBXSourceTree.Group);
                    gr.children.AddGUID(newGroup.guid);
                    GroupsAdd(projectPath, gr, newGroup);
                    gr = newGroup;
                }
            }
            return gr;
        }
 
        /// <summary>
        /// Creates a new native target.
        /// Target-specific build configurations are automatically created for each known build configuration name.
        /// Note, that this is a requirement that follows from the structure of Xcode projects, not an implementation
        /// detail of this function. The function creates a product file reference in the "Products" project folder 
        /// which refers to the target artifact that is built via this target.
        /// </summary>
        /// <returns>The GUID of the new target.</returns>
        /// <param name="name">The name of the new target.</param>
        /// <param name="ext">The file extension of the target artifact (leading dot is not necessary, but accepted).</param>
        /// <param name="type">The type of the target. For example:
        /// "com.apple.product-type.app-extension" - App extension,
        /// "com.apple.product-type.application.watchapp2" - WatchKit 2 application</param>
        public string AddTarget(string name, string ext, string type)
        {
            var buildConfigList = XCConfigurationListData.Create();
            buildConfigLists.AddEntry(buildConfigList);
            
            // create build file reference
            string fullName = name + "." + FileTypeUtils.TrimExtension(ext);
            var productFileRef = AddFile(fullName, "Products/" + fullName, PBXSourceTree.Build);
            var newTarget = PBXNativeTargetData.Create(name, productFileRef, type, buildConfigList.guid);
            nativeTargets.AddEntry(newTarget);
            project.project.targets.Add(newTarget.guid);
 
            foreach (var buildConfigName in BuildConfigNames())
                AddBuildConfigForTarget(newTarget.guid, buildConfigName);
            
            return newTarget.guid;
        }
 
        private IEnumerable<string> GetAllTargetGuids()
        {
            var targets = new List<string>();
 
            targets.Add(project.project.guid);
            targets.AddRange(nativeTargets.GetGuids());
 
            return targets;
        }
 
        /// <summary>
        /// Returns the file reference of the artifact created by building target.
        /// </summary>
        /// <returns>The file reference of the artifact created by building target.</returns>
        /// <param name="targetGuid">The GUID of the target as returned by [[TargetGuidByName()]].</param>
        public string GetTargetProductFileRef(string targetGuid)
        {
            return nativeTargets[targetGuid].productReference;
        }
 
        /// <summary>
        /// Sets up a dependency between two targets.
        /// </summary>
        /// <param name="targetGuid">The GUID of the target that is depending on the dependency.</param>
        /// <param name="targetDependencyGuid">The GUID of the dependency target</param>
        internal void AddTargetDependency(string targetGuid, string targetDependencyGuid)
        {
            string dependencyName = nativeTargets[targetDependencyGuid].name;
            var containerProxy = PBXContainerItemProxyData.Create(project.project.guid, "1", targetDependencyGuid, dependencyName);
            containerItems.AddEntry(containerProxy);
 
            var targetDependency = PBXTargetDependencyData.Create(targetDependencyGuid, containerProxy.guid);
            targetDependencies.AddEntry(targetDependency);
 
            nativeTargets[targetGuid].dependencies.AddGUID(targetDependency.guid);
        }
 
        // Returns the GUID of the new configuration
        // targetGuid can be either native target or the project target.
        private string AddBuildConfigForTarget(string targetGuid, string name)
        {
            if (BuildConfigByName(targetGuid, name) != null)
            {
                throw new Exception(String.Format("A build configuration by name {0} already exists for target {1}",
                                                  targetGuid, name));
            }
            var buildConfig = XCBuildConfigurationData.Create(name);
            buildConfigs.AddEntry(buildConfig);
 
            buildConfigLists[GetConfigListForTarget(targetGuid)].buildConfigs.AddGUID(buildConfig.guid);
            return buildConfig.guid;
        }
 
        private void RemoveBuildConfigForTarget(string targetGuid, string name)
        {
            var buildConfigGuid = BuildConfigByName(targetGuid, name);
            if (buildConfigGuid == null)
                return;
            buildConfigs.RemoveEntry(buildConfigGuid);
            buildConfigLists[GetConfigListForTarget(targetGuid)].buildConfigs.RemoveGUID(buildConfigGuid);
        }
 
        /// <summary>
        /// Returns the GUID of build configuration with the given name for the specific target.
        /// Null is returned if such configuration does not exist.
        /// </summary>
        /// <returns>The GUID of the build configuration or null if it does not exist.</returns>
        /// <param name="targetGuid">The GUID of the target as returned by [[TargetGuidByName()]].</param>
        /// <param name="name">The name of the build configuration.</param>
        public string BuildConfigByName(string targetGuid, string name)
        {
            foreach (string guid in buildConfigLists[GetConfigListForTarget(targetGuid)].buildConfigs)
            {
                var buildConfig = buildConfigs[guid];
                if (buildConfig != null && buildConfig.name == name)
                    return buildConfig.guid;
            }
            return null;
        }
 
        /// <summary>
        /// Returns the names of the build configurations available in the project.
        /// The number and names of the build configurations is a project-wide setting. Each target has the
        /// same number of build configurations and the names of these build configurations is the same.
        /// In other words, [[BuildConfigByName()]] will succeed for all targets in the project and all
        /// build configuration names returned by this function.
        /// </summary>
        /// <returns>An array of build config names.</returns>
        public IEnumerable<string> BuildConfigNames()
        {
            var names = new List<string>();
            // We use the project target to fetch the build configs
            foreach (var guid in buildConfigLists[project.project.buildConfigList].buildConfigs)
                names.Add(buildConfigs[guid].name);
 
            return names;
        }
 
        /// <summary>
        /// Creates a new set of build configurations for all targets in the project.
        /// The number and names of the build configurations is a project-wide setting. Each target has the
        /// same number of build configurations and the names of these build configurations is the same.
        /// The created configurations are initially empty. Care must be taken to fill them with reasonable 
        /// defaults.
        /// The function throws an exception if a build configuration with the given name already exists.
        /// </summary>
        /// <param name="name">The name of the build configuration.</param>
        public void AddBuildConfig(string name)
        {
            foreach (var targetGuid in GetAllTargetGuids())
                AddBuildConfigForTarget(targetGuid, name);
        }
 
        /// <summary>
        /// Removes all build configurations with the given name from all targets in the project.
        /// The number and names of the build configurations is a project-wide setting. Each target has the
        /// same number of build configurations and the names of these build configurations is the same.
        /// The function does nothing if the build configuration with the specified name does not exist.
        /// </summary>
        /// <param name="name">The name of the build configuration.</param>
        public void RemoveBuildConfig(string name)
        {
            foreach (var targetGuid in GetAllTargetGuids())
                RemoveBuildConfigForTarget(targetGuid, name);   
        }
 
        /// <summary>
        /// Returns the GUID of sources build phase for the given target.
        /// </summary>
        /// <returns>Returns the GUID of the existing phase or null if it does not exist.</returns>
        /// <param name="targetGuid">The GUID of the target as returned by [[TargetGuidByName()]].</param>
        public string GetSourcesBuildPhaseByTarget(string targetGuid)
        {
            var target = nativeTargets[targetGuid];
            foreach (var phaseGuid in target.phases) {
                var phaseAny = BuildSectionAny(phaseGuid);
                if (phaseAny is PBXSourcesBuildPhaseData)
                    return phaseGuid;
            }
            return null;
        }
 
        /// <summary>
        /// Creates a new sources build phase for given target.
        /// If the target already has sources build phase configured for it, the function returns the
        /// existing phase. The new phase is placed at the end of the list of build phases configured 
        /// for the target.
        /// </summary>
        /// <returns>Returns the GUID of the new phase.</returns>
        /// <param name="targetGuid">The GUID of the target as returned by [[TargetGuidByName()]].</param>
        public string AddSourcesBuildPhase(string targetGuid)
        {
            var phaseGuid = GetSourcesBuildPhaseByTarget(targetGuid);
            if (phaseGuid != null)
                return phaseGuid;
 
            var phase = PBXSourcesBuildPhaseData.Create();
            sources.AddEntry(phase);
            nativeTargets[targetGuid].phases.AddGUID(phase.guid);
            return phase.guid;
        }
 
        /// <summary>
        /// Returns the GUID of resources build phase for the given target.
        /// </summary>
        /// <returns>Returns the GUID of the existing phase or null if it does not exist.</returns>
        /// <param name="targetGuid">The GUID of the target as returned by [[TargetGuidByName()]].</param>
        public string GetResourcesBuildPhaseByTarget(string targetGuid)
        {
            var target = nativeTargets[targetGuid];
            foreach (var phaseGuid in target.phases) {
                var phaseAny = BuildSectionAny(phaseGuid);
                if (phaseAny is PBXResourcesBuildPhaseData)
                    return phaseGuid;
            }
            return null;
        }
 
        /// <summary>
        /// Creates a new resources build phase for given target.
        /// If the target already has resources build phase configured for it, the function returns the
        /// existing phase. The new phase is placed at the end of the list of build phases configured 
        /// for the target.
        /// </summary>
        /// <returns>Returns the GUID of the new phase.</returns>
        /// <param name="targetGuid">The GUID of the target as returned by [[TargetGuidByName()]].</param>
        public string AddResourcesBuildPhase(string targetGuid)
        {
            var phaseGuid = GetResourcesBuildPhaseByTarget(targetGuid);
            if (phaseGuid != null)
                return phaseGuid;
 
            var phase = PBXResourcesBuildPhaseData.Create();
            resources.AddEntry(phase);
            nativeTargets[targetGuid].phases.AddGUID(phase.guid);
            return phase.guid;
        }
 
        /// <summary>
        /// Returns the GUID of frameworks build phase for the given target.
        /// </summary>
        /// <returns>Returns the GUID of the existing phase or null if it does not exist.</returns>
        /// <param name="targetGuid">The GUID of the target as returned by [[TargetGuidByName()]].</param>
        public string GetFrameworksBuildPhaseByTarget(string targetGuid)
        {
            var target = nativeTargets[targetGuid];
            foreach (var phaseGuid in target.phases) {
                var phaseAny = BuildSectionAny(phaseGuid);
                if (phaseAny is PBXFrameworksBuildPhaseData)
                    return phaseGuid;
            }
            return null;
        }
 
        /// <summary>
        /// Creates a new frameworks build phase for given target.
        /// If the target already has frameworks build phase configured for it, the function returns the
        /// existing phase. The new phase is placed at the end of the list of build phases configured 
        /// for the target.
        /// </summary>
        /// <returns>Returns the GUID of the new phase.</returns>
        /// <param name="targetGuid">The GUID of the target as returned by [[TargetGuidByName()]].</param>
        public string AddFrameworksBuildPhase(string targetGuid)
        {
            var phaseGuid = GetFrameworksBuildPhaseByTarget(targetGuid);
            if (phaseGuid != null)
                return phaseGuid;
 
            var phase = PBXFrameworksBuildPhaseData.Create();
            frameworks.AddEntry(phase);
            nativeTargets[targetGuid].phases.AddGUID(phase.guid);
            return phase.guid;
        }
 
        /// <summary>
        /// Returns the GUID of matching copy files build phase for the given target.
        /// The parameters of existing copy files build phase are matched to the arguments of this
        /// function and the GUID of the phase is returned only if a matching build phase is found.
        /// </summary>
        /// <returns>Returns the GUID of the matching phase or null if it does not exist.</returns>
        /// <param name="targetGuid">The GUID of the target as returned by [[TargetGuidByName()]].</param>
        /// <param name="name">The name of the phase.</param>
        /// <param name="dstPath">The destination path.</param>
        /// <param name="subfolderSpec">The "subfolder spec". The following usages are known:
        /// "10" for embedding frameworks;
        /// "13" for embedding app extension content;
        /// "16" for embedding watch content</param>
        public string GetCopyFilesBuildPhaseByTarget(string targetGuid, string name, string dstPath, string subfolderSpec)
        {
            var target = nativeTargets[targetGuid];
            foreach (var phaseGuid in target.phases) {
                var phaseAny = BuildSectionAny(phaseGuid);
                if (phaseAny is PBXCopyFilesBuildPhaseData)
                {
                    var copyPhase = (PBXCopyFilesBuildPhaseData) phaseAny;
                    if (copyPhase.name == name && copyPhase.dstPath == dstPath && 
                        copyPhase.dstSubfolderSpec == subfolderSpec)
                    {
                        return phaseGuid;
                    }
                }
            }
            return null;
        }
 
        /// <summary>
        /// Creates a new copy files build phase for given target.
        /// If the target already has copy files build phase with the same name, dstPath and subfolderSpec 
        /// configured for it, the function returns the existing phase. 
        /// The new phase is placed at the end of the list of build phases configured for the target.
        /// </summary>
        /// <returns>Returns the GUID of the new phase.</returns>
        /// <param name="targetGuid">The GUID of the target as returned by [[TargetGuidByName()]].</param>
        /// <param name="name">The name of the phase.</param>
        /// <param name="dstPath">The destination path.</param>
        /// <param name="subfolderSpec">The "subfolder spec". The following usages are known:
        /// "10" for embedding frameworks;
        /// "13" for embedding app extension content;
        /// "16" for embedding watch content</param>
        public string AddCopyFilesBuildPhase(string targetGuid, string name, string dstPath, string subfolderSpec)
        {
            var phaseGuid = GetCopyFilesBuildPhaseByTarget(targetGuid, name, dstPath, subfolderSpec);
            if (phaseGuid != null)
                return phaseGuid;
 
            var phase = PBXCopyFilesBuildPhaseData.Create(name, dstPath, subfolderSpec);
            copyFiles.AddEntry(phase);
            nativeTargets[targetGuid].phases.AddGUID(phase.guid);
            return phase.guid;
        }
 
        internal string GetConfigListForTarget(string targetGuid)
        {
            if (targetGuid == project.project.guid)
                return project.project.buildConfigList;
            else
            return nativeTargets[targetGuid].buildConfigList;
        }
 
        // Sets the baseConfigurationReference key for a XCBuildConfiguration. 
        // If the argument is null, the base configuration is removed.
        internal void SetBaseReferenceForConfig(string configGuid, string baseReference)
        {
            buildConfigs[configGuid].baseConfigurationReference = baseReference;
        }
 
        internal PBXBuildFileData FindFrameworkByFileGuid(PBXCopyFilesBuildPhaseData phase, string fileGuid)
        {
            foreach (string buildFileDataGuid in phase.files)
            {
                var buildFile = BuildFilesGet(buildFileDataGuid);
                if (buildFile.fileRef == fileGuid)
                    return buildFile;
            }
            return null;
        }
 
        /// <summary>
        /// Adds a value to build property list in all build configurations for the specified target.
        /// Duplicate build properties are ignored. Values for names "LIBRARY_SEARCH_PATHS" and 
        /// "FRAMEWORK_SEARCH_PATHS" are quoted if they contain spaces.
        /// </summary>
        /// <param name="targetGuid">The GUID of the target as returned by [[TargetGuidByName()]].</param>
        /// <param name="name">The name of the build property.</param>
        /// <param name="value">The value of the build property.</param>
        public void AddBuildProperty(string targetGuid, string name, string value)
        {
            foreach (string guid in buildConfigLists[GetConfigListForTarget(targetGuid)].buildConfigs)
                AddBuildPropertyForConfig(guid, name, value);
        }
 
        /// <summary>
        /// Adds a value to build property list in all build configurations for the specified targets.
        /// Duplicate build properties are ignored. Values for names "LIBRARY_SEARCH_PATHS" and 
        /// "FRAMEWORK_SEARCH_PATHS" are quoted if they contain spaces.
        /// </summary>
        /// <param name="targetGuids">The GUIDs of the target as returned by [[TargetGuidByName()]].</param>
        /// <param name="name">The name of the build property.</param>
        /// <param name="value">The value of the build property.</param>
        public void AddBuildProperty(IEnumerable<string> targetGuids, string name, string value)
        {
            foreach (string t in targetGuids)
                AddBuildProperty(t, name, value);
        }
 
        /// <summary>
        /// Adds a value to build property list of the given build configuration
        /// Duplicate build properties are ignored. Values for names "LIBRARY_SEARCH_PATHS" and 
        /// "FRAMEWORK_SEARCH_PATHS" are quoted if they contain spaces.
        /// </summary>
        /// <param name="configGuid">The GUID of the build configuration as returned by [[BuildConfigByName()]].</param>
        /// <param name="name">The name of the build property.</param>
        /// <param name="value">The value of the build property.</param>
        public void AddBuildPropertyForConfig(string configGuid, string name, string value)
        {
            buildConfigs[configGuid].AddProperty(name, value);
        }
 
        /// <summary>
        /// Adds a value to build property list of the given build configurations
        /// Duplicate build properties are ignored. Values for names "LIBRARY_SEARCH_PATHS" and 
        /// "FRAMEWORK_SEARCH_PATHS" are quoted if they contain spaces.
        /// </summary>
        /// <param name="configGuids">The GUIDs of the build configurations as returned by [[BuildConfigByName()]].</param>
        /// <param name="name">The name of the build property.</param>
        /// <param name="value">The value of the build property.</param>
        public void AddBuildPropertyForConfig(IEnumerable<string> configGuids, string name, string value)
        {
            foreach (string guid in configGuids)
                AddBuildPropertyForConfig(guid, name, value);
        }
 
        /// <summary>
        /// Adds a value to build property list in all build configurations for the specified target.
        /// Duplicate build properties are ignored. Values for names "LIBRARY_SEARCH_PATHS" and 
        /// "FRAMEWORK_SEARCH_PATHS" are quoted if they contain spaces.
        /// </summary>
        /// <param name="targetGuid">The GUID of the target as returned by [[TargetGuidByName()]].</param>
        /// <param name="name">The name of the build property.</param>
        /// <param name="value">The value of the build property.</param>
        public void SetBuildProperty(string targetGuid, string name, string value)
        {
            foreach (string guid in buildConfigLists[GetConfigListForTarget(targetGuid)].buildConfigs)
                SetBuildPropertyForConfig(guid, name, value);
        }
 
        /// <summary>
        /// Adds a value to build property list in all build configurations for the specified targets.
        /// Duplicate build properties are ignored. Values for names "LIBRARY_SEARCH_PATHS" and 
        /// "FRAMEWORK_SEARCH_PATHS" are quoted if they contain spaces.
        /// </summary>
        /// <param name="targetGuids">The GUIDs of the target as returned by [[TargetGuidByName()]].</param>
        /// <param name="name">The name of the build property.</param>
        /// <param name="value">The value of the build property.</param>
        public void SetBuildProperty(IEnumerable<string> targetGuids, string name, string value)
        {
            foreach (string t in targetGuids)
                SetBuildProperty(t, name, value);
        }
        public void SetBuildPropertyForConfig(string configGuid, string name, string value)
        {
            buildConfigs[configGuid].SetProperty(name, value);
        }
        public void SetBuildPropertyForConfig(IEnumerable<string> configGuids, string name, string value)
        {
            foreach (string guid in configGuids)
                SetBuildPropertyForConfig(guid, name, value);
        }
 
        internal void RemoveBuildProperty(string targetGuid, string name)
        {
            foreach (string guid in buildConfigLists[GetConfigListForTarget(targetGuid)].buildConfigs)
                RemoveBuildPropertyForConfig(guid, name);
        }
        internal void RemoveBuildProperty(IEnumerable<string> targetGuids, string name)
        {
            foreach (string t in targetGuids)
                RemoveBuildProperty(t, name);
        }
        internal void RemoveBuildPropertyForConfig(string configGuid, string name)
        {
            buildConfigs[configGuid].RemoveProperty(name);
        }
        internal void RemoveBuildPropertyForConfig(IEnumerable<string> configGuids, string name)
        {
            foreach (string guid in configGuids)
                RemoveBuildPropertyForConfig(guid, name);
        }
 
        internal void RemoveBuildPropertyValueList(string targetGuid, string name, IEnumerable<string> valueList)
        {
            foreach (string guid in buildConfigLists[GetConfigListForTarget(targetGuid)].buildConfigs)
                RemoveBuildPropertyValueListForConfig(guid, name, valueList);
        }
        internal void RemoveBuildPropertyValueList(IEnumerable<string> targetGuids, string name, IEnumerable<string> valueList)
        {
            foreach (string t in targetGuids)
                RemoveBuildPropertyValueList(t, name, valueList);
        }
        internal void RemoveBuildPropertyValueListForConfig(string configGuid, string name, IEnumerable<string> valueList)
        {
            buildConfigs[configGuid].RemovePropertyValueList(name, valueList);
        }
        internal void RemoveBuildPropertyValueListForConfig(IEnumerable<string> configGuids, string name, IEnumerable<string> valueList)
        {
            foreach (string guid in configGuids)
                RemoveBuildPropertyValueListForConfig(guid, name, valueList);
        }
 
        /// Interprets the value of the given property as a set of space-delimited strings, then
        /// removes strings equal to items to removeValues and adds strings in addValues.
        public void UpdateBuildProperty(string targetGuid, string name, 
                                        IEnumerable<string> addValues, IEnumerable<string> removeValues)
        {
            foreach (string guid in buildConfigLists[GetConfigListForTarget(targetGuid)].buildConfigs)
                UpdateBuildPropertyForConfig(guid, name, addValues, removeValues);
        }
        public void UpdateBuildProperty(IEnumerable<string> targetGuids, string name, 
                                        IEnumerable<string> addValues, IEnumerable<string> removeValues)
        {
            foreach (string t in targetGuids)
                UpdateBuildProperty(t, name, addValues, removeValues);
        }
        public void UpdateBuildPropertyForConfig(string configGuid, string name, 
                                                 IEnumerable<string> addValues, IEnumerable<string> removeValues)
        {
            var config = buildConfigs[configGuid];
            if (config != null)
            {
                if (removeValues != null)
                    foreach (var v in removeValues)
                        config.RemovePropertyValue(name, v);
                if (addValues != null)
                    foreach (var v in addValues)
                        config.AddProperty(name, v);
            }
        }
        public void UpdateBuildPropertyForConfig(IEnumerable<string> configGuids, string name, 
                                                 IEnumerable<string> addValues, IEnumerable<string> removeValues)
        {
            foreach (string guid in configGuids)
                UpdateBuildProperty(guid, name, addValues, removeValues);
        }
 
        internal string ShellScriptByName(string targetGuid, string name)
        {
            foreach (var phase in nativeTargets[targetGuid].phases)
            {
                var script = shellScripts[phase];
                if (script != null && script.name == name)
                    return script.guid;
            }
            return null;
        }
 
        internal void AppendShellScriptBuildPhase(string targetGuid, string name, string shellPath, string shellScript)
        {
            PBXShellScriptBuildPhaseData shellScriptPhase = PBXShellScriptBuildPhaseData.Create(name, shellPath, shellScript);
 
            shellScripts.AddEntry(shellScriptPhase);
            nativeTargets[targetGuid].phases.AddGUID(shellScriptPhase.guid);
        }
 
        internal void AppendShellScriptBuildPhase(IEnumerable<string> targetGuids, string name, string shellPath, string shellScript)
        {
            PBXShellScriptBuildPhaseData shellScriptPhase = PBXShellScriptBuildPhaseData.Create(name, shellPath, shellScript);
 
            shellScripts.AddEntry(shellScriptPhase);
            foreach (string guid in targetGuids)
            {
                nativeTargets[guid].phases.AddGUID(shellScriptPhase.guid);
            }
        }
 
        public void ReadFromFile(string path)
        {
            ReadFromString(File.ReadAllText(path));
        }
 
        public void ReadFromString(string src)
        {
            TextReader sr = new StringReader(src);
            ReadFromStream(sr);
        }
 
        public void ReadFromStream(TextReader sr)
        {
            m_Data.ReadFromStream(sr);
        }
 
        public void WriteToFile(string path)
        {
            File.WriteAllText(path, WriteToString());
        }
 
        public void WriteToStream(TextWriter sw)
        {
            sw.Write(WriteToString());
        }
 
        public string WriteToString()
        {
            return m_Data.WriteToString();
        }
 
        internal PBXProjectObjectData GetProjectInternal()
        {
            return project.project;
        }
 
        /*
         * Allows the setting of target attributes in the project section such as Provisioning Style and Team ID for each target
         *
         * The Target Attributes are structured like so:
         * attributes = {
         *      TargetAttributes = {
         *          1D6058900D05DD3D006BFB54 = {
         *              DevelopmentTeam = Z6SFPV59E3;
         *              ProvisioningStyle = Manual;
         *          };
         *          5623C57217FDCB0800090B9E = {
         *              DevelopmentTeam = Z6SFPV59E3;
         *              ProvisioningStyle = Manual;
         *              TestTargetID = 1D6058900D05DD3D006BFB54;
         *          };
         *      };
         *  };
         */
        internal void SetTargetAttributes(string key, string value)
        {
            PBXElementDict properties = project.project.GetPropertiesRaw();
            PBXElementDict attributes;
            PBXElementDict targetAttributes;
            if (properties.Contains("attributes"))
            {
                attributes = properties["attributes"] as PBXElementDict;
            }
            else
            {
                attributes = properties.CreateDict("attributes");
            }
 
            if (attributes.Contains("TargetAttributes"))
            {
                targetAttributes = attributes["TargetAttributes"] as PBXElementDict;
            } 
            else
            {
                targetAttributes = attributes.CreateDict("TargetAttributes");
            }
 
            foreach (KeyValuePair<string, PBXNativeTargetData> target in nativeTargets.GetEntries()) {
                PBXElementDict targetAttributesRaw;
                if (targetAttributes.Contains(target.Key))
                {
                    targetAttributesRaw = targetAttributes[target.Key].AsDict();
                }
                else
                {
                    targetAttributesRaw = targetAttributes.CreateDict(target.Key);
                }
                targetAttributesRaw.SetString(key, value); 
            }
            project.project.UpdateVars();
 
        }
    }
} // namespace UnityEditor.iOS.Xcode