solv 0.21.0

SOLution Validation tool that analyzes Microsoft Visual Studio solutions
Documentation
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
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
use crate::error::Collector;
use crate::{Consume, calculate_percent, ux};
use comfy_table::{Attribute, Cell};
use crossterm::style::Stylize;
use num_format::{Locale, ToFormattedString};
use petgraph::Direction;
use petgraph::algo::DfsSpace;
use petgraph::graph::{DiGraph, NodeIndex};
use petgraph::prelude::DiGraphMap;
use solp::api::{Solution, SolutionConfiguration};
use std::cell::RefCell;
use std::collections::{BTreeSet, HashMap, HashSet};
use std::fmt;
use std::fmt::Display;
use std::fs;
use std::path::{Path, PathBuf};

trait Validator {
    /// does validation
    fn validate(&mut self, statistic: &mut Statistic);
    /// will return true if validation succeeded false otherwise
    fn validation_result(&self) -> bool;
    /// prints validation results if any
    fn print_results(&self);
}

pub struct Validate {
    show_only_problems: bool,
    errors: RefCell<Collector>,
    statistic: RefCell<Statistic>,
}

#[derive(Default)]
struct Statistic {
    cycles: u64,
    danglings: u64,
    not_found: u64,
    missings: u64,
    parsed: u64,
    not_parsed: u64,
    redundant_refs: u64,
    total: u64,
}

impl Display for Statistic {
    #[allow(clippy::cast_possible_truncation)]
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        writeln!(f, "{}", " Statistic:".dark_red().bold())?;

        let mut table = ux::new_table();

        table.set_header([
            Cell::new("Category").add_attribute(Attribute::Bold),
            Cell::new("# Solutions").add_attribute(Attribute::Bold),
            Cell::new("%").add_attribute(Attribute::Bold),
        ]);

        let cycles_percent = calculate_percent(self.cycles as i32, self.total as i32);
        let missings_percent = calculate_percent(self.missings as i32, self.total as i32);
        let danglings_percent = calculate_percent(self.danglings as i32, self.total as i32);
        let not_found_percent = calculate_percent(self.not_found as i32, self.total as i32);
        let redundant_refs_percent =
            calculate_percent(self.redundant_refs as i32, self.total as i32);
        let parsed_percent = calculate_percent(self.parsed as i32, self.total as i32);
        let not_parsed_percent = calculate_percent(self.not_parsed as i32, self.total as i32);
        let total_percent = calculate_percent(self.total as i32, self.total as i32);

        table.add_row([
            Cell::new("Successfully parsed"),
            Cell::new(self.parsed.to_formatted_string(&Locale::en))
                .add_attribute(Attribute::Italic),
            Cell::new(format!("{parsed_percent:.2}%")).add_attribute(Attribute::Italic),
        ]);

        table.add_row([
            Cell::new("Contain dependencies cycles"),
            Cell::new(self.cycles.to_formatted_string(&Locale::en))
                .add_attribute(Attribute::Italic),
            Cell::new(format!("{cycles_percent:.2}%")).add_attribute(Attribute::Italic),
        ]);

        table.add_row([
            Cell::new("Contain project configurations outside solution's list"),
            Cell::new(self.missings.to_formatted_string(&Locale::en))
                .add_attribute(Attribute::Italic),
            Cell::new(format!("{missings_percent:.2}%")).add_attribute(Attribute::Italic),
        ]);

        table.add_row([
            Cell::new("Contain dangling project configurations"),
            Cell::new(self.danglings.to_formatted_string(&Locale::en))
                .add_attribute(Attribute::Italic),
            Cell::new(format!("{danglings_percent:.2}%")).add_attribute(Attribute::Italic),
        ]);

        table.add_row([
            Cell::new("Contain projects that not exists"),
            Cell::new(self.not_found.to_formatted_string(&Locale::en))
                .add_attribute(Attribute::Italic),
            Cell::new(format!("{not_found_percent:.2}%")).add_attribute(Attribute::Italic),
        ]);

        table.add_row([
            Cell::new("Contain redundant project references"),
            Cell::new(self.redundant_refs.to_formatted_string(&Locale::en))
                .add_attribute(Attribute::Italic),
            Cell::new(format!("{redundant_refs_percent:.2}%")).add_attribute(Attribute::Italic),
        ]);

        table.add_row([
            Cell::new("Not parsed"),
            Cell::new(self.not_parsed.to_formatted_string(&Locale::en))
                .add_attribute(Attribute::Italic),
            Cell::new(format!("{not_parsed_percent:.2}%")).add_attribute(Attribute::Italic),
        ]);

        table.add_row(["", "", ""]);
        table.add_row([
            Cell::new("Total"),
            Cell::new(self.total.to_formatted_string(&Locale::en)).add_attribute(Attribute::Italic),
            Cell::new(format!("{total_percent:.2}%")).add_attribute(Attribute::Italic),
        ]);

        writeln!(f, "{table}")
    }
}

impl Validate {
    #[must_use]
    pub fn new(show_only_problems: bool) -> Self {
        Self {
            show_only_problems,
            errors: RefCell::new(Collector::new()),
            statistic: RefCell::new(Statistic::default()),
        }
    }
}

#[derive(Default)]
struct FixStatistic {
    parsed: u64,
    fixed_solutions: u64,
    fixed_projects: u64,
    removed_refs: u64,
    failed_projects: u64,
    not_parsed: u64,
    total: u64,
}

impl Display for FixStatistic {
    #[allow(clippy::cast_possible_truncation)]
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        writeln!(f, "{}", " Fix statistic:".dark_red().bold())?;

        let mut table = ux::new_table();
        table.set_header([
            Cell::new("Category").add_attribute(Attribute::Bold),
            Cell::new("#").add_attribute(Attribute::Bold),
            Cell::new("%").add_attribute(Attribute::Bold),
        ]);

        let parsed_percent = calculate_percent(self.parsed as i32, self.total as i32);
        let fixed_solutions_percent =
            calculate_percent(self.fixed_solutions as i32, self.total as i32);
        let not_parsed_percent = calculate_percent(self.not_parsed as i32, self.total as i32);
        let total_percent = calculate_percent(self.total as i32, self.total as i32);

        table.add_row([
            Cell::new("Successfully parsed solutions"),
            Cell::new(self.parsed.to_formatted_string(&Locale::en))
                .add_attribute(Attribute::Italic),
            Cell::new(format!("{parsed_percent:.2}%")).add_attribute(Attribute::Italic),
        ]);
        table.add_row([
            Cell::new("Not parsed solutions"),
            Cell::new(self.not_parsed.to_formatted_string(&Locale::en))
                .add_attribute(Attribute::Italic),
            Cell::new(format!("{not_parsed_percent:.2}%")).add_attribute(Attribute::Italic),
        ]);
        table.add_row([
            Cell::new("Solutions with applied fixes"),
            Cell::new(self.fixed_solutions.to_formatted_string(&Locale::en))
                .add_attribute(Attribute::Italic),
            Cell::new(format!("{fixed_solutions_percent:.2}%")).add_attribute(Attribute::Italic),
        ]);
        table.add_row([
            Cell::new("Updated project files"),
            Cell::new(self.fixed_projects.to_formatted_string(&Locale::en))
                .add_attribute(Attribute::Italic),
            Cell::new(String::new()).add_attribute(Attribute::Italic),
        ]);
        table.add_row([
            Cell::new("Failed to update project files"),
            Cell::new(self.failed_projects.to_formatted_string(&Locale::en))
                .add_attribute(Attribute::Italic),
            Cell::new(String::new()).add_attribute(Attribute::Italic),
        ]);
        table.add_row([
            Cell::new("Redundant references removed"),
            Cell::new(self.removed_refs.to_formatted_string(&Locale::en))
                .add_attribute(Attribute::Italic),
            Cell::new(String::new()).add_attribute(Attribute::Italic),
        ]);
        table.add_row(["", "", ""]);
        table.add_row([
            Cell::new("Total solutions"),
            Cell::new(self.total.to_formatted_string(&Locale::en)).add_attribute(Attribute::Italic),
            Cell::new(format!("{total_percent:.2}%")).add_attribute(Attribute::Italic),
        ]);

        writeln!(f, "{table}")
    }
}

pub struct ValidateFix {
    errors: RefCell<Collector>,
    statistic: RefCell<FixStatistic>,
    failed: RefCell<Vec<(PathBuf, String)>>,
}

impl ValidateFix {
    #[must_use]
    pub fn new() -> Self {
        Self {
            errors: RefCell::new(Collector::new()),
            statistic: RefCell::new(FixStatistic::default()),
            failed: RefCell::new(Vec::new()),
        }
    }
}

impl Default for ValidateFix {
    fn default() -> Self {
        Self::new()
    }
}

impl Consume for ValidateFix {
    fn ok(&mut self, solution: &Solution) {
        self.statistic.borrow_mut().parsed += 1;

        let mut detector = Redundants::new(solution);
        let mut unused = Statistic::default();
        detector.validate(&mut unused);

        let mut refs_by_project: HashMap<PathBuf, HashSet<String>> = HashMap::new();
        for redundant in detector.redundants {
            refs_by_project
                .entry(redundant.project)
                .or_default()
                .insert(redundant.redundant_reference.clone());
        }

        let mut solution_was_fixed = false;
        for (project_path, refs) in refs_by_project {
            match remove_redundant_reference_lines(&project_path, &refs) {
                Ok(removed) => {
                    if removed > 0 {
                        let mut stat = self.statistic.borrow_mut();
                        stat.fixed_projects += 1;
                        stat.removed_refs += removed as u64;
                        solution_was_fixed = true;
                    }
                }
                Err(err) => {
                    self.statistic.borrow_mut().failed_projects += 1;
                    self.failed
                        .borrow_mut()
                        .push((project_path, err.to_string()));
                }
            }
        }
        if solution_was_fixed {
            self.statistic.borrow_mut().fixed_solutions += 1;
        }
    }

    fn err(&self, path: &str) {
        self.errors.borrow_mut().add_path(path);
    }
}

impl Display for ValidateFix {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        let mut statistic = self.statistic.borrow_mut();
        statistic.not_parsed = self.errors.borrow().count();
        statistic.total = statistic.parsed + statistic.not_parsed;
        write!(f, "{statistic}")?;

        let failed = self.failed.borrow();
        if !failed.is_empty() {
            writeln!(f)?;
            writeln!(
                f,
                " {}",
                "Failed to update project files:".dark_red().bold()
            )?;
            for (path, error) in failed.iter() {
                writeln!(f, "   {}: {}", path.to_string_lossy(), error)?;
            }
        }

        if self.errors.borrow().count() > 0 {
            write!(f, "{}", self.errors.borrow())?;
        }
        Ok(())
    }
}

impl Consume for Validate {
    fn ok(&mut self, solution: &Solution) {
        let mut validators: [Box<dyn Validator>; 5] = [
            Box::new(Cycles::new(solution)),
            Box::new(Danglings::new(solution)),
            Box::new(NotFouund::new(solution)),
            Box::new(Missings::new(solution)),
            Box::new(Redundants::new(solution)),
        ];

        let valid_solution = validators.iter_mut().fold(true, |mut res, validator| {
            validator.validate(&mut self.statistic.borrow_mut());
            res &= validator.validation_result();
            res
        });

        if !self.show_only_problems || !valid_solution {
            ux::print_solution_path(solution.path);
        }
        for v in &validators {
            if !v.validation_result() {
                v.print_results();
            }
        }

        if !self.show_only_problems && valid_solution {
            println!(
                "   {}",
                "No problems found in solution.".dark_green().bold()
            );
            println!();
        }
        if !valid_solution {
            println!();
        }
        self.statistic.borrow_mut().total += 1;
    }

    fn err(&self, path: &str) {
        self.errors.borrow_mut().add_path(path);
    }
}

impl Display for Validate {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        let mut statistic = self.statistic.borrow_mut();
        statistic.not_parsed = self.errors.borrow().count();
        statistic.parsed = statistic.total;
        statistic.total += statistic.not_parsed;
        write!(f, "{statistic}")?;
        if self.errors.borrow().count() > 0 {
            write!(f, "{}", self.errors.borrow())
        } else {
            Ok(())
        }
    }
}

struct NotFouund<'a> {
    solution: &'a Solution<'a>,
    bad_paths: BTreeSet<PathBuf>,
}

impl<'a> NotFouund<'a> {
    pub fn new(solution: &'a Solution<'a>) -> Self {
        Self {
            solution,
            bad_paths: BTreeSet::new(),
        }
    }
}

impl Validator for NotFouund<'_> {
    fn validate(&mut self, statistic: &mut Statistic) {
        let dir = crate::parent_of(self.solution.path);
        self.bad_paths = self
            .solution
            .iterate_projects_without_web_sites()
            .filter_map(|p| crate::try_make_local_path(dir, p.path_or_uri))
            .filter_map(|full_path| {
                // we need only not found paths
                full_path.canonicalize().err()?;
                Some(full_path)
            })
            .collect();
        if !self.validation_result() {
            statistic.not_found += 1;
        }
    }

    fn validation_result(&self) -> bool {
        self.bad_paths.is_empty()
    }

    fn print_results(&self) {
        let items = self.bad_paths.iter().filter_map(|p| p.as_path().to_str());
        ux::print_one_column_table(
            "Unexist project path",
            Some(comfy_table::Color::DarkYellow),
            items,
        );
    }
}

struct Danglings<'a> {
    solution: &'a Solution<'a>,
}

impl<'a> Danglings<'a> {
    pub fn new(solution: &'a Solution<'a>) -> Self {
        Self { solution }
    }
}

impl Validator for Danglings<'_> {
    fn validate(&mut self, statistic: &mut Statistic) {
        if !self.validation_result() {
            statistic.danglings += 1;
        }
    }

    fn validation_result(&self) -> bool {
        self.solution.dangling_project_configurations.is_none()
    }

    fn print_results(&self) {
        if let Some(danglings) = &self.solution.dangling_project_configurations {
            ux::print_one_column_table(
                "Dangling project configurations that can be safely removed",
                Some(comfy_table::Color::DarkYellow),
                danglings.iter(),
            );
        }
    }
}

struct Missings<'a> {
    solution: &'a Solution<'a>,
    missings: HashMap<&'a str, Vec<SolutionConfiguration<'a>>>,
}

impl<'a> Missings<'a> {
    pub fn new(solution: &'a Solution<'a>) -> Self {
        Self {
            solution,
            missings: HashMap::new(),
        }
    }
}

impl Validator for Missings<'_> {
    fn validate(&mut self, statistic: &mut Statistic) {
        self.missings = self
            .solution
            .projects
            .iter()
            .filter_map(|p| {
                let mut result = vec![];
                let configurations = p.configurations.as_ref()?;
                for c in configurations {
                    let solution_conf = SolutionConfiguration {
                        configuration: c.solution_configuration,
                        platform: c.platform,
                    };
                    if !self.solution.configurations.contains(&solution_conf) {
                        result.push(solution_conf);
                    }
                }
                if result.is_empty() {
                    None
                } else {
                    Some((p.id, result))
                }
            })
            .collect();

        if !self.validation_result() {
            statistic.missings += 1;
        }
    }

    fn validation_result(&self) -> bool {
        self.missings.is_empty()
    }

    fn print_results(&self) {
        println!("  {}", "Solution contains project configurations that are outside solution's configuration|platform list:".dark_yellow().bold());

        let mut table = ux::new_table();
        table.set_header([
            Cell::new("Project ID").add_attribute(Attribute::Bold),
            Cell::new("Configuration|Platform").add_attribute(Attribute::Bold),
        ]);

        for (id, configs) in &self.missings {
            for config in configs {
                table.add_row([
                    Cell::new(*id),
                    Cell::new(format!("{}|{}", config.configuration, config.platform)),
                ]);
            }
        }

        println!("{table}");
    }
}

struct Cycles<'a> {
    solution: &'a Solution<'a>,
    cycles_detected: bool,
}

impl<'a> Cycles<'a> {
    pub fn new(solution: &'a Solution<'a>) -> Self {
        Self {
            solution,
            cycles_detected: false,
        }
    }
}

impl<'a> Validator for Cycles<'a> {
    fn validate(&mut self, statistic: &mut Statistic) {
        let mut graph = DiGraphMap::<&'a str, ()>::new();
        for to in &self.solution.projects {
            graph.add_node(to.id);
            if let Some(depends_from) = &to.depends_from {
                for from in depends_from {
                    if !graph.contains_node(from) {
                        graph.add_node(from);
                    }
                    graph.add_edge(from, to.id, ());
                }
            }
        }

        let mut space = DfsSpace::new(&graph);
        self.cycles_detected = petgraph::algo::toposort(&graph, Some(&mut space)).is_err();
        if self.cycles_detected {
            statistic.cycles += 1;
        }
    }

    fn validation_result(&self) -> bool {
        !self.cycles_detected
    }

    fn print_results(&self) {
        println!(
            "   {}",
            "Solution contains project dependencies cycles"
                .dark_red()
                .bold()
        );
    }
}

/// A single redundant project reference detected in a project: `project`
/// directly references `redundant_reference`, but the same reference is also
/// reachable transitively through some other direct reference of `project`,
/// so the direct reference can be safely removed.
struct RedundantRef {
    project: PathBuf,
    redundant_reference: String,
}

struct Redundants<'a> {
    solution: &'a Solution<'a>,
    redundants: Vec<RedundantRef>,
}

impl<'a> Redundants<'a> {
    pub fn new(solution: &'a Solution<'a>) -> Self {
        Self {
            solution,
            redundants: Vec::new(),
        }
    }

    /// Builds a directed graph where an edge `from -> to` means
    /// project `to` directly references project `from`
    /// (i.e., `to` depends on `from`).
    fn build_graph(&self) -> DiGraph<PathBuf, String> {
        let projects = crate::collect_msbuild_projects(self.solution);
        let mut graph = DiGraph::<PathBuf, String>::new();
        let mut nodes: HashMap<PathBuf, NodeIndex> = HashMap::new();

        for prj in projects {
            let to_path = prj.path.canonicalize().unwrap_or_else(|_| prj.path.clone());
            let to = Self::ensure_node(&mut graph, &mut nodes, &to_path);

            let Some(project) = prj.project else { continue };
            let Some(item_groups) = project.item_group else {
                continue;
            };
            let Some(parent) = prj.path.parent() else {
                continue;
            };

            for ig in item_groups {
                let Some(refs) = ig.project_reference else {
                    continue;
                };
                for reference in refs {
                    let include = reference.include.clone();
                    #[cfg(target_os = "windows")]
                    let normalized_include = include.as_str();
                    #[cfg(not(target_os = "windows"))]
                    let normalized_include = decorate_path(&include);

                    let joined = parent.join(normalized_include);
                    let Ok(reference_path) = joined.canonicalize() else {
                        continue;
                    };

                    let from = Self::ensure_node(&mut graph, &mut nodes, &reference_path);
                    // do not create self-loops
                    if from == to {
                        continue;
                    }
                    if graph.find_edge(from, to).is_none() {
                        graph.add_edge(from, to, include);
                    }
                }
            }
        }
        graph
    }

    fn ensure_node(
        graph: &mut DiGraph<PathBuf, String>,
        nodes: &mut HashMap<PathBuf, NodeIndex>,
        path: &Path,
    ) -> NodeIndex {
        if let Some(ix) = nodes.get(path) {
            *ix
        } else {
            let ix = graph.add_node(path.to_path_buf());
            nodes.insert(path.to_path_buf(), ix);
            ix
        }
    }

    /// Returns true if `target` is reachable from `start` without visiting
    /// `forbidden`. This is used to verify whether a direct reference
    /// `start -> forbidden` is still implied transitively through another
    /// predecessor of `forbidden` after effectively removing that edge.
    fn has_path_avoiding_node(
        graph: &DiGraph<PathBuf, String>,
        start: NodeIndex,
        target: NodeIndex,
        forbidden: NodeIndex,
    ) -> bool {
        if start == forbidden || target == forbidden {
            return false;
        }
        if start == target {
            return true;
        }

        let mut visited: HashSet<NodeIndex> = HashSet::new();
        let mut stack: Vec<NodeIndex> = vec![start];

        while let Some(current) = stack.pop() {
            if !visited.insert(current) {
                continue;
            }
            for next in graph.neighbors_directed(current, Direction::Outgoing) {
                if next == forbidden {
                    continue;
                }
                if next == target {
                    return true;
                }
                if !visited.contains(&next) {
                    stack.push(next);
                }
            }
        }

        false
    }

    /// For each node N, looks at all its direct predecessors P (i.e., projects
    /// directly referenced by N). An edge `p -> N` is considered redundant if
    /// there exists another direct predecessor `p'` of N (with `p' != p`) such
    /// that there is a path `p -> ... -> p'` in the graph. In that case, N
    /// already receives a transitive dependency on `p` through `p'`, so the
    /// direct reference `p -> N` is unnecessary.
    fn find_redundants(graph: &DiGraph<PathBuf, String>) -> Vec<RedundantRef> {
        let mut result: Vec<RedundantRef> = Vec::new();

        for node in graph.node_indices() {
            let direct_preds: Vec<NodeIndex> = graph
                .neighbors_directed(node, Direction::Incoming)
                .collect();
            if direct_preds.len() < 2 {
                continue;
            }

            for &candidate in &direct_preds {
                // `candidate -> node` is redundant when another direct
                // predecessor `other` of `node` already depends (directly or
                // transitively) on `candidate`, i.e., there is a path
                // `candidate -> ... -> other`. In that case `node` will reach
                // `candidate` transitively through `other` and the direct
                // `candidate -> node` edge is unnecessary.
                let reachable_via_other = direct_preds
                    .iter()
                    .filter(|&&other| other != candidate)
                    .any(|&other| Self::has_path_avoiding_node(graph, candidate, other, node));

                if reachable_via_other {
                    let Some(edge) = graph.find_edge(candidate, node) else {
                        continue;
                    };
                    result.push(RedundantRef {
                        project: graph[node].clone(),
                        redundant_reference: graph[edge].clone(),
                    });
                }
            }
        }

        result.sort_by(|a, b| {
            a.project
                .cmp(&b.project)
                .then_with(|| a.redundant_reference.cmp(&b.redundant_reference))
        });
        result
    }
}

impl Validator for Redundants<'_> {
    fn validate(&mut self, statistic: &mut Statistic) {
        let graph = self.build_graph();
        self.redundants = Self::find_redundants(&graph);
        if !self.validation_result() {
            statistic.redundant_refs += 1;
        }
    }

    fn validation_result(&self) -> bool {
        self.redundants.is_empty()
    }

    fn print_results(&self) {
        if self.redundants.is_empty() {
            return;
        }
        println!(
            "  {}",
            "Solution contains redundant project references that can be replaced by transitive dependencies:"
                .dark_yellow()
                .bold()
        );

        // `self.redundants` is sorted by (project, redundant_reference), so a
        // linear pass is enough to build stable project groups.
        let mut current_project: Option<&Path> = None;
        let mut current_rows: Vec<String> = Vec::new();
        for r in &self.redundants {
            if current_project != Some(r.project.as_path()) {
                if let Some(project) = current_project {
                    ux::print_one_column_table(
                        &project.to_string_lossy(),
                        Some(comfy_table::Color::DarkBlue),
                        current_rows.drain(..),
                    );
                }
                current_project = Some(r.project.as_path());
            }
            current_rows.push(r.redundant_reference.clone());
        }

        if let Some(project) = current_project {
            ux::print_one_column_table(
                &project.to_string_lossy(),
                Some(comfy_table::Color::DarkBlue),
                current_rows.into_iter(),
            );
        }
        println!();
    }
}

fn remove_redundant_reference_lines(
    path: &Path,
    redundant_refs: &HashSet<String>,
) -> std::io::Result<usize> {
    if redundant_refs.is_empty() {
        return Ok(0);
    }

    let input = fs::read(path)?;
    let spans = find_redundant_reference_spans(&input, redundant_refs);
    if spans.is_empty() {
        return Ok(0);
    }

    // Build effective spans and compute output size in a single pass.
    // Each effective span extends the original span to also remove surrounding
    // whitespace/newlines that would otherwise leave blank lines.
    let mut effective_spans: Vec<(usize, usize)> = Vec::with_capacity(spans.len());
    let mut output_size = input.len();
    let mut prev_end = 0usize;
    for (start, end) in &spans {
        let extended_start = expand_start_over_line_whitespace(&input, *start, prev_end);
        let extended_end = expand_end_over_line_whitespace(&input, *end);
        output_size -= extended_end.saturating_sub(extended_start);
        effective_spans.push((extended_start, extended_end));
        prev_end = extended_end;
    }

    // Build output by copying kept regions.
    let mut output = Vec::with_capacity(output_size);
    let mut cursor = 0usize;
    for (start, end) in &effective_spans {
        if cursor < *start {
            output.extend_from_slice(&input[cursor..*start]);
        }
        cursor = *end;
    }
    if cursor < input.len() {
        output.extend_from_slice(&input[cursor..]);
    }

    fs::write(path, &output)?;
    Ok(spans.len())
}

/// Walks back from `start` while the preceding bytes on the same line are
/// horizontal whitespace, so that a leading indentation in front of the
/// `<ProjectReference ...>` element gets removed together with the element
/// itself. The walk-back is bounded by `lower_bound` (typically the previous
/// span's end) to avoid clobbering previously kept content.
fn expand_start_over_line_whitespace(input: &[u8], mut start: usize, lower_bound: usize) -> usize {
    while start > lower_bound {
        let c = input[start - 1];
        if c == b'\n' {
            break;
        }
        if c == b' ' || c == b'\t' || c == b'\r' {
            start -= 1;
            continue;
        }
        // Non-whitespace content sits on the same line before the tag; we
        // must keep that content, so do not extend the removed range.
        return start;
    }
    start
}

/// Walks forward from `end` while the trailing bytes on the same line are
/// horizontal whitespace, and consumes a single line terminator if found, so
/// that an empty line left behind by the removed element disappears too.
fn expand_end_over_line_whitespace(input: &[u8], mut end: usize) -> usize {
    let len = input.len();
    let saved = end;
    while end < len {
        let c = input[end];
        if c == b' ' || c == b'\t' || c == b'\r' {
            end += 1;
            continue;
        }
        if c == b'\n' {
            return end + 1;
        }
        // Non-whitespace content sits on the same line after the tag; keep it.
        return saved;
    }
    end
}

/// Scans the raw bytes of an MSBuild project file for `<ProjectReference ...>`
/// elements (both self-closing and with an explicit `</ProjectReference>`
/// closing tag, possibly spanning multiple lines as XML allows) whose
/// `Include` attribute value is contained in `redundant_refs`. Returns the
/// byte ranges `[start, end)` of every such element occurrence, in input
/// order, where `start` is the position of `<` and `end` is one past the
/// final `>` of the element.
fn find_redundant_reference_spans(
    input: &[u8],
    redundant_refs: &HashSet<String>,
) -> Vec<(usize, usize)> {
    const TAG: &[u8] = b"<ProjectReference";
    const TAG_FIRST: u8 = TAG[0]; // '<'
    const TAG_NEXT: u8 = TAG[1]; // 'P'
    const TAG_LEN: usize = TAG.len();
    const CLOSE_TAG: &[u8] = b"</ProjectReference>";
    const CLOSE_TAG_LEN: usize = CLOSE_TAG.len();
    let len = input.len();
    let mut spans: Vec<(usize, usize)> = Vec::with_capacity(4);
    let mut i = 0usize;

    while i + TAG_LEN <= len {
        // Fast path: check first two bytes before doing a full slice comparison.
        // This eliminates ~99% of positions without allocating any slice.
        if input[i] != TAG_FIRST || input.get(i + 1) != Some(&TAG_NEXT) {
            i += 1;
            continue;
        }
        // Quick check: the character after `<ProjectReference` must NOT be
        // alphanumeric or underscore (to reject `<ProjectReferenceCore>`, etc.).
        let after = input.get(i + TAG_LEN).copied().unwrap_or(0);
        if after.is_ascii_alphanumeric() || after == b'_' {
            i += 1;
            continue;
        }
        // Full slice comparison for the remaining candidates.
        if &input[i..i + TAG_LEN] != TAG {
            i += 1;
            continue;
        }

        // The tag name must be terminated by whitespace, '/', or '>' to avoid
        // matching things like `<ProjectReferenceXxx`.
        let after = input.get(i + TAG_LEN).copied().unwrap_or(0);
        if !(after == b' ' || after == b'\t' || after == b'\n' || after == b'\r'
            || after == b'/' || after == b'>')
        {
            i += 1;
            continue;
        }

        // Find end of opening tag, accounting for quoted attribute values that
        // may contain '>' characters.
        let mut j = i + TAG_LEN;
        let mut in_quote: Option<u8> = None;
        let mut self_closing = false;
        let mut found_close = false;
        while j < len {
            let c = input[j];
            if let Some(q) = in_quote {
                if c == q {
                    in_quote = None;
                }
                j += 1;
            } else if c == b'"' || c == b'\'' {
                in_quote = Some(c);
                j += 1;
            } else if c == b'>' {
                if j > 0 && input[j - 1] == b'/' {
                    self_closing = true;
                }
                j += 1;
                found_close = true;
                break;
            } else {
                j += 1;
            }
        }
        if !found_close {
            // Malformed input — give up.
            break;
        }
        let opening_tag_end = j; // one past '>'

        // Slice of the attribute list (between `<ProjectReference` and the
        // terminating `>` or `/>`).
        let attrs_start = i + TAG_LEN;
        let attrs_end = if self_closing {
            opening_tag_end - 2
        } else {
            opening_tag_end - 1
        };
        let include = extract_include_value(&input[attrs_start..attrs_end]);

        let span_end = if self_closing {
            opening_tag_end
        } else {
            // Find matching `</ProjectReference>`. MSBuild project files do
            // not nest `<ProjectReference>` inside another `<ProjectReference>`,
            // so a plain forward scan is sufficient.
            let mut k = opening_tag_end;
            let mut close_pos = None;
            while k + CLOSE_TAG_LEN <= len {
                // Fast path: check first byte '<' and last byte '>' before full comparison.
                if input[k] == b'<' && input[k + CLOSE_TAG_LEN - 1] == b'>'
                    && &input[k..k + CLOSE_TAG_LEN] == CLOSE_TAG
                {
                    close_pos = Some(k + CLOSE_TAG_LEN);
                    break;
                }
                k += 1;
            }
            if let Some(p) = close_pos {
                p
            } else {
                // Malformed: skip past this opening tag and continue.
                i = opening_tag_end;
                continue;
            }
        };

        if let Some(inc) = include
            && redundant_refs.contains(inc)
        {
            spans.push((i, span_end));
        }

        i = span_end;
    }
    spans
}

fn extract_include_value(line: &[u8]) -> Option<&str> {
    let len = line.len();
    let include_bytes: &[u8] = b"Include";
    let mut i = 0;

    // Find "Include" without creating intermediate slices
    while i + include_bytes.len() <= len {
        // Fast path: check first byte 'I' before full comparison
        if line[i] == b'I' && &line[i..i + include_bytes.len()] == include_bytes {
            i += include_bytes.len();

            // Skip whitespace after "Include"
            while i < len && line[i].is_ascii_whitespace() {
                i += 1;
            }
            // Must be followed by '='
            if i < len && line[i] == b'=' {
                i += 1;

                // Skip whitespace after "="
                while i < len && line[i].is_ascii_whitespace() {
                    i += 1;
                }
                // Must be followed by a quote
                if i < len {
                    let quote = line[i];
                    if quote == b'"' || quote == b'\'' {
                        i += 1;
                        let value_start = i;
                        // Find closing quote
                        while i < len && line[i] != quote {
                            i += 1;
                        }
                        if i < len {
                            return std::str::from_utf8(&line[value_start..i]).ok();
                        }
                    }
                }
            }
            // Not a valid Include="..." pattern, continue searching
        }
        i += 1;
    }
    None
}

#[cfg(not(target_os = "windows"))]
fn decorate_path(path: &str) -> String {
    path.replace('\\', "/")
}

#[cfg(test)]
mod tests {
    use super::*;
    use std::fs;
    use std::time::{SystemTime, UNIX_EPOCH};

    #[test]
    fn integration_test_correct_solution() {
        // Arrange
        let solution = solp::parse_str(CORRECT_SOLUTION).unwrap();
        let mut validator = Validate::new(false);

        // Act
        validator.ok(&solution);

        // Assert
    }

    #[test]
    fn integration_test_solution_with_danglings() {
        // Arrange
        let solution = solp::parse_str(SOLUTION_WITH_DANGLINGS).unwrap();
        let mut validator = Validate::new(false);

        // Act
        validator.ok(&solution);

        // Assert
    }

    #[test]
    fn integration_test_solution_with_missings() {
        // Arrange
        let solution = solp::parse_str(SOLUTION_WITH_MISSING_PROJECT_CONFIGS).unwrap();
        let mut validator = Validate::new(false);

        // Act
        validator.ok(&solution);

        // Assert
    }

    #[test]
    fn integration_test_solution_with_cycles() {
        // Arrange
        let solution = solp::parse_str(SOLUTION_WITH_CYCLES).unwrap();
        let mut validator = Validate::new(false);

        // Act
        validator.ok(&solution);

        // Assert
    }

    #[test]
    fn dangling_validation_correct() {
        // Arrange
        let solution = solp::parse_str(CORRECT_SOLUTION).unwrap();
        let mut validator = Danglings::new(&solution);
        let mut statistic = Statistic::default();

        // Act
        validator.validate(&mut statistic);

        // Assert
        assert!(validator.validation_result());
    }

    #[test]
    fn cycles_validation_correct() {
        // Arrange
        let solution = solp::parse_str(CORRECT_SOLUTION).unwrap();
        let mut validator = Cycles::new(&solution);
        let mut statistic = Statistic::default();

        // Act
        validator.validate(&mut statistic);

        // Assert
        assert!(validator.validation_result());
        assert_eq!(0, statistic.cycles);
    }

    #[test]
    fn cycles_validation_incorrect() {
        // Arrange
        let solution = solp::parse_str(SOLUTION_WITH_CYCLES).unwrap();
        let mut validator = Cycles::new(&solution);
        let mut statistic = Statistic::default();

        // Act
        validator.validate(&mut statistic);

        // Assert
        assert!(!validator.validation_result());
        assert_eq!(1, statistic.cycles);
    }

    #[test]
    fn missing_validation_correct() {
        // Arrange
        let solution = solp::parse_str(CORRECT_SOLUTION).unwrap();
        let mut validator = Missings::new(&solution);
        let mut statistic = Statistic::default();

        // Act
        validator.validate(&mut statistic);

        // Assert
        assert!(validator.validation_result());
        assert_eq!(0, statistic.missings);
    }

    #[test]
    fn missing_validation_incorrect() {
        // Arrange
        let solution = solp::parse_str(SOLUTION_WITH_MISSING_PROJECT_CONFIGS).unwrap();
        let mut validator = Missings::new(&solution);
        let mut statistic = Statistic::default();

        // Act
        validator.validate(&mut statistic);

        // Assert
        assert!(!validator.validation_result());
        assert_eq!(1, statistic.missings);
    }

    #[test]
    fn dangling_validation_incorrect() {
        // Arrange
        let solution = solp::parse_str(SOLUTION_WITH_DANGLINGS).unwrap();
        let mut validator = Danglings::new(&solution);
        let mut statistic = Statistic::default();

        // Act
        validator.validate(&mut statistic);

        // Assert
        assert!(!validator.validation_result());
        assert_eq!(1, statistic.danglings);
    }

    #[test]
    fn print_statistic_test() {
        // Arrange
        let s = Statistic::default();

        // Act
        println!("{s}");

        // Assert
    }

    fn add_node(graph: &mut DiGraph<PathBuf, String>, name: &str) -> NodeIndex {
        graph.add_node(PathBuf::from(name))
    }

    #[test]
    fn redundants_empty_graph_has_no_redundants() {
        // Arrange
        let graph = DiGraph::<PathBuf, String>::new();

        // Act
        let redundants = Redundants::find_redundants(&graph);

        // Assert
        assert!(redundants.is_empty());
    }

    #[test]
    fn redundants_single_dependency_has_no_redundants() {
        // Arrange
        let mut graph = DiGraph::<PathBuf, String>::new();
        let a = add_node(&mut graph, "a");
        let b = add_node(&mut graph, "b");
        graph.add_edge(a, b, "a->b".to_owned());

        // Act
        let redundants = Redundants::find_redundants(&graph);

        // Assert
        assert!(redundants.is_empty());
    }

    #[test]
    fn redundants_simple_triangle_detects_redundant() {
        // Arrange:
        //   a -> b, a -> c, b -> c
        // 'a' is a direct ref of 'c', but already reachable transitively
        // through 'b' (a -> b -> c). So the direct edge a -> c is redundant.
        let mut graph = DiGraph::<PathBuf, String>::new();
        let a = add_node(&mut graph, "a");
        let b = add_node(&mut graph, "b");
        let c = add_node(&mut graph, "c");
        graph.add_edge(a, b, "a->b".to_owned());
        graph.add_edge(a, c, "..\\A\\A.csproj".to_owned());
        graph.add_edge(b, c, "..\\B\\B.csproj".to_owned());

        // Act
        let redundants = Redundants::find_redundants(&graph);

        // Assert
        assert_eq!(1, redundants.len());
        assert_eq!(PathBuf::from("c"), redundants[0].project);
        assert_eq!("..\\A\\A.csproj", redundants[0].redundant_reference);
    }

    #[test]
    fn redundants_independent_refs_are_not_redundant() {
        // Arrange:
        //   a -> c, b -> c (a and b are independent)
        let mut graph = DiGraph::<PathBuf, String>::new();
        let a = add_node(&mut graph, "a");
        let b = add_node(&mut graph, "b");
        let c = add_node(&mut graph, "c");
        graph.add_edge(a, c, "a->c".to_owned());
        graph.add_edge(b, c, "b->c".to_owned());

        // Act
        let redundants = Redundants::find_redundants(&graph);

        // Assert
        assert!(redundants.is_empty());
    }

    #[test]
    fn redundants_deep_chain() {
        // Arrange:
        //   a -> b -> c -> d, and a -> d (direct)
        // 'a' is a direct ref of 'd', reachable transitively via 'c' (a -> b -> c -> d).
        let mut graph = DiGraph::<PathBuf, String>::new();
        let a = add_node(&mut graph, "a");
        let b = add_node(&mut graph, "b");
        let c = add_node(&mut graph, "c");
        let d = add_node(&mut graph, "d");
        graph.add_edge(a, b, "a->b".to_owned());
        graph.add_edge(b, c, "b->c".to_owned());
        graph.add_edge(c, d, "c->d".to_owned());
        graph.add_edge(a, d, "..\\A\\A.csproj".to_owned());

        // Act
        let redundants = Redundants::find_redundants(&graph);

        // Assert
        assert_eq!(1, redundants.len());
        assert_eq!(PathBuf::from("d"), redundants[0].project);
        assert_eq!("..\\A\\A.csproj", redundants[0].redundant_reference);
    }

    #[test]
    fn redundants_path_via_target_node_is_not_redundant() {
        // Arrange:
        //   a -> n, b -> n, n -> b
        // There is a path a -> b, but only through n. Removing a -> n breaks
        // that path, so a -> n must not be considered redundant.
        let mut graph = DiGraph::<PathBuf, String>::new();
        let a = add_node(&mut graph, "a");
        let b = add_node(&mut graph, "b");
        let n = add_node(&mut graph, "n");
        graph.add_edge(a, n, "a->n".to_owned());
        graph.add_edge(b, n, "b->n".to_owned());
        graph.add_edge(n, b, "n->b".to_owned());

        // Act
        let redundants = Redundants::find_redundants(&graph);

        // Assert
        assert!(redundants.is_empty());
    }

    #[test]
    fn redundants_normalize_real_paths_and_detect_redundancy() {
        // Arrange
        let uniq = SystemTime::now()
            .duration_since(UNIX_EPOCH)
            .unwrap()
            .as_nanos();
        let root = std::env::temp_dir().join(format!("solv-redundants-{uniq}"));
        let a_dir = root.join("A");
        let b_dir = root.join("B");
        let app_dir = root.join("App");
        let shared_dir = root.join("Shared");

        fs::create_dir_all(&a_dir).unwrap();
        fs::create_dir_all(&b_dir).unwrap();
        fs::create_dir_all(&app_dir).unwrap();
        fs::create_dir_all(&shared_dir).unwrap();

        fs::write(
            shared_dir.join("Shared.csproj"),
            r#"<Project Sdk="Microsoft.NET.Sdk"></Project>"#,
        )
        .unwrap();

        fs::write(
            a_dir.join("A.csproj"),
            r#"
<Project Sdk="Microsoft.NET.Sdk">
  <ItemGroup>
    <ProjectReference Include="..\Shared\Shared.csproj" />
  </ItemGroup>
</Project>
"#,
        )
        .unwrap();

        fs::write(
            b_dir.join("B.csproj"),
            r#"
<Project Sdk="Microsoft.NET.Sdk">
  <ItemGroup>
    <ProjectReference Include="..\Shared\Shared.csproj" />
  </ItemGroup>
</Project>
"#,
        )
        .unwrap();

        fs::write(
            app_dir.join("App.csproj"),
            r#"
<Project Sdk="Microsoft.NET.Sdk">
  <ItemGroup>
    <ProjectReference Include="..\A\A.csproj" />
    <ProjectReference Include="..\Shared\Shared.csproj" />
  </ItemGroup>
</Project>
"#,
        )
        .unwrap();

        let sln = r#"
Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
Project("{{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}}") = "App", "App/App.csproj", "{{A1111111-1111-1111-1111-111111111111}}"
EndProject
Project("{{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}}") = "A", "A/A.csproj", "{{A2222222-2222-2222-2222-222222222222}}"
EndProject
Project("{{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}}") = "B", "B/B.csproj", "{{A3333333-3333-3333-3333-333333333333}}"
EndProject
Project("{{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}}") = "Shared", "Shared/../Shared/Shared.csproj", "{{A4444444-4444-4444-4444-444444444444}}"
EndProject
Global
    GlobalSection(SolutionConfigurationPlatforms) = preSolution
        Debug|Any CPU = Debug|Any CPU
    EndGlobalSection
    GlobalSection(ProjectConfigurationPlatforms) = postSolution
        {{A1111111-1111-1111-1111-111111111111}}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
        {{A2222222-2222-2222-2222-222222222222}}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
        {{A3333333-3333-3333-3333-333333333333}}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
        {{A4444444-4444-4444-4444-444444444444}}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
    EndGlobalSection
EndGlobal
"#;

        let mut solution = solp::parse_str(sln).unwrap();
        let sln_path = root.join("test.sln");
        let leaked_path: &'static str =
            Box::leak(sln_path.to_string_lossy().into_owned().into_boxed_str());
        solution.path = leaked_path;

        let mut validator = Redundants::new(&solution);

        // Act
        let graph = validator.build_graph();
        validator.redundants = Redundants::find_redundants(&graph);

        // Assert
        assert_eq!(4, graph.node_count());

        let app_path = app_dir.join("App.csproj").canonicalize().unwrap();
        assert!(
            validator
                .redundants
                .iter()
                .any(|r| r.project == app_path
                    && r.redundant_reference == "..\\Shared\\Shared.csproj")
        );

        // Cleanup
        fs::remove_dir_all(&root).unwrap();
    }

    #[test]
    fn remove_redundant_reference_lines_removes_only_target_line() {
        // Arrange
        let uniq = SystemTime::now()
            .duration_since(UNIX_EPOCH)
            .unwrap()
            .as_nanos();
        let root = std::env::temp_dir().join(format!("solv-fix-lines-{uniq}"));
        fs::create_dir_all(&root).unwrap();
        let project_path = root.join("App.csproj");
        let original = concat!(
            "<Project>\r\n",
            "  <ItemGroup>\r\n",
            "    <ProjectReference Include=\"..\\A\\A.csproj\" />\r\n",
            "    <ProjectReference Include=\"..\\B\\B.csproj\" />\r\n",
            "  </ItemGroup>\r\n",
            "</Project>\r\n",
        );
        fs::write(&project_path, original).unwrap();
        let mut refs = HashSet::new();
        refs.insert("..\\A\\A.csproj".to_string());

        // Act
        let removed = remove_redundant_reference_lines(&project_path, &refs).unwrap();
        let updated = fs::read(&project_path).unwrap();

        // Assert
        assert_eq!(1, removed);
        assert_eq!(
            updated,
            concat!(
                "<Project>\r\n",
                "  <ItemGroup>\r\n",
                "    <ProjectReference Include=\"..\\B\\B.csproj\" />\r\n",
                "  </ItemGroup>\r\n",
                "</Project>\r\n",
            )
            .as_bytes()
        );
        fs::remove_dir_all(&root).unwrap();
    }

    #[test]
    fn remove_redundant_reference_lines_removes_multiline_self_closing_tag() {
        // Arrange: <ProjectReference> spans three physical lines.
        let uniq = SystemTime::now()
            .duration_since(UNIX_EPOCH)
            .unwrap()
            .as_nanos();
        let root = std::env::temp_dir().join(format!("solv-fix-multiline-{uniq}"));
        fs::create_dir_all(&root).unwrap();
        let project_path = root.join("App.csproj");
        let original = concat!(
            "<Project>\n",
            "  <ItemGroup>\n",
            "    <ProjectReference\n",
            "        Include=\"..\\A\\A.csproj\"\n",
            "    />\n",
            "    <ProjectReference Include=\"..\\B\\B.csproj\" />\n",
            "  </ItemGroup>\n",
            "</Project>\n",
        );
        fs::write(&project_path, original).unwrap();
        let mut refs = HashSet::new();
        refs.insert("..\\A\\A.csproj".to_string());

        // Act
        let removed = remove_redundant_reference_lines(&project_path, &refs).unwrap();
        let updated = fs::read(&project_path).unwrap();

        // Assert
        assert_eq!(1, removed);
        assert_eq!(
            updated,
            concat!(
                "<Project>\n",
                "  <ItemGroup>\n",
                "    <ProjectReference Include=\"..\\B\\B.csproj\" />\n",
                "  </ItemGroup>\n",
                "</Project>\n",
            )
            .as_bytes()
        );
        fs::remove_dir_all(&root).unwrap();
    }

    #[test]
    fn remove_redundant_reference_lines_removes_multiline_with_explicit_close_tag() {
        // Arrange: <ProjectReference ...> ... </ProjectReference> spans 4 lines.
        let uniq = SystemTime::now()
            .duration_since(UNIX_EPOCH)
            .unwrap()
            .as_nanos();
        let root = std::env::temp_dir().join(format!("solv-fix-multiline-close-{uniq}"));
        fs::create_dir_all(&root).unwrap();
        let project_path = root.join("App.csproj");
        let original = concat!(
            "<Project>\r\n",
            "  <ItemGroup>\r\n",
            "    <ProjectReference\r\n",
            "        Include=\"..\\A\\A.csproj\">\r\n",
            "      <Private>true</Private>\r\n",
            "    </ProjectReference>\r\n",
            "    <ProjectReference Include=\"..\\B\\B.csproj\" />\r\n",
            "  </ItemGroup>\r\n",
            "</Project>\r\n",
        );
        fs::write(&project_path, original).unwrap();
        let mut refs = HashSet::new();
        refs.insert("..\\A\\A.csproj".to_string());

        // Act
        let removed = remove_redundant_reference_lines(&project_path, &refs).unwrap();
        let updated = fs::read(&project_path).unwrap();

        // Assert
        assert_eq!(1, removed);
        assert_eq!(
            updated,
            concat!(
                "<Project>\r\n",
                "  <ItemGroup>\r\n",
                "    <ProjectReference Include=\"..\\B\\B.csproj\" />\r\n",
                "  </ItemGroup>\r\n",
                "</Project>\r\n",
            )
            .as_bytes()
        );
        fs::remove_dir_all(&root).unwrap();
    }

    #[test]
    fn remove_redundant_reference_lines_keeps_file_unchanged_without_match() {
        // Arrange
        let uniq = SystemTime::now()
            .duration_since(UNIX_EPOCH)
            .unwrap()
            .as_nanos();
        let root = std::env::temp_dir().join(format!("solv-fix-lines-noop-{uniq}"));
        fs::create_dir_all(&root).unwrap();
        let project_path = root.join("App.csproj");
        let original = concat!(
            "<Project>\n",
            "  <ItemGroup>\n",
            "    <ProjectReference Include=\"..\\B\\B.csproj\" />\n",
            "  </ItemGroup>\n",
            "</Project>\n",
        );
        fs::write(&project_path, original).unwrap();
        let before = fs::read(&project_path).unwrap();
        let mut refs = HashSet::new();
        refs.insert("..\\A\\A.csproj".to_string());

        // Act
        let removed = remove_redundant_reference_lines(&project_path, &refs).unwrap();
        let after = fs::read(&project_path).unwrap();

        // Assert
        assert_eq!(0, removed);
        assert_eq!(before, after);
        fs::remove_dir_all(&root).unwrap();
    }

    #[test]
    fn integration_test_validate_fix_removes_redundant_reference() {
        // Arrange: create a realistic project structure with a redundant reference
        // Graph: Shared -> A -> App
        // App directly references both A and Shared, but Shared is reachable transitively
        // through A, so App's direct reference to Shared is redundant.
        let uniq = SystemTime::now()
            .duration_since(UNIX_EPOCH)
            .unwrap()
            .as_nanos();
        let root = std::env::temp_dir().join(format!("solv-validatefix-{uniq}"));
        let shared_dir = root.join("Shared");
        let a_dir = root.join("A");
        let app_dir = root.join("App");

        fs::create_dir_all(&shared_dir).unwrap();
        fs::create_dir_all(&a_dir).unwrap();
        fs::create_dir_all(&app_dir).unwrap();

        // Shared project - no dependencies
        fs::write(
            shared_dir.join("Shared.csproj"),
            r#"<Project Sdk="Microsoft.NET.Sdk"><PropertyGroup><TargetFramework>net6.0</TargetFramework></PropertyGroup></Project>"#,
        )
        .unwrap();

        // A project - references Shared
        fs::write(
            a_dir.join("A.csproj"),
            concat!(
                "<Project Sdk=\"Microsoft.NET.Sdk\">\n",
                "  <PropertyGroup><TargetFramework>net6.0</TargetFramework></PropertyGroup>\n",
                "  <ItemGroup>\n",
                "    <ProjectReference Include=\"..\\Shared\\Shared.csproj\" />\n",
                "  </ItemGroup>\n",
                "</Project>\n",
            ),
        )
        .unwrap();

        // App project - references both A and Shared (Shared is redundant)
        let app_original = concat!(
            "<Project Sdk=\"Microsoft.NET.Sdk\">\n",
            "  <PropertyGroup><TargetFramework>net6.0</TargetFramework></PropertyGroup>\n",
            "  <ItemGroup>\n",
            "    <ProjectReference Include=\"..\\A\\A.csproj\" />\n",
            "    <ProjectReference Include=\"..\\Shared\\Shared.csproj\" />\n",
            "  </ItemGroup>\n",
            "</Project>\n",
        );
        fs::write(app_dir.join("App.csproj"), app_original).unwrap();

        // Solution file
        let sln = r#"
Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "App", "App/App.csproj", "{A1111111-1111-1111-1111-111111111111}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "A", "A/A.csproj", "{A2222222-2222-2222-2222-222222222222}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Shared", "Shared/Shared.csproj", "{A4444444-4444-4444-4444-444444444444}"
EndProject
Global
    GlobalSection(SolutionConfigurationPlatforms) = preSolution
        Debug|Any CPU = Debug|Any CPU
    EndGlobalSection
    GlobalSection(ProjectConfigurationPlatforms) = postSolution
        {A1111111-1111-1111-1111-111111111111}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
        {A2222222-2222-2222-2222-222222222222}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
        {A4444444-4444-4444-4444-444444444444}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
    EndGlobalSection
EndGlobal
"#;

        let mut solution = solp::parse_str(sln).unwrap();
        let sln_path = root.join("test.sln");
        let leaked_path: &'static str =
            Box::leak(sln_path.to_string_lossy().into_owned().into_boxed_str());
        solution.path = leaked_path;

        // Act
        let mut validator = ValidateFix::new();
        validator.ok(&solution);

        // Assert
        // the redundant reference was removed from App.csproj
        let app_updated = fs::read_to_string(app_dir.join("App.csproj")).unwrap();
        assert!(
            !app_updated.contains("Shared.csproj"),
            "App.csproj should not contain reference to Shared.csproj after fix"
        );
        assert!(
            app_updated.contains("A.csproj"),
            "App.csproj should still contain reference to A.csproj"
        );

        // statistics
        assert_eq!(
            validator.statistic.borrow().fixed_projects,
            1,
            "Should be one fixed project"
        );
        assert_eq!(
            validator.statistic.borrow().removed_refs,
            1,
            "Should be one removed ref"
        );

        // Cleanup
        fs::remove_dir_all(&root).unwrap();
    }

    const CORRECT_SOLUTION: &str = r#"
Microsoft Visual Studio Solution File, Format Version 8.00
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "gtest", "gtest.vcproj", "{C8F6C172-56F2-4E76-B5FA-C3B423B31BE7}"
	ProjectSection(ProjectDependencies) = postProject
	EndProjectSection
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "gtest_main", "gtest_main.vcproj", "{3AF54C8A-10BF-4332-9147-F68ED9862032}"
	ProjectSection(ProjectDependencies) = postProject
	EndProjectSection
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "gtest_unittest", "gtest_unittest.vcproj", "{4D9FDFB5-986A-4139-823C-F4EE0ED481A1}"
	ProjectSection(ProjectDependencies) = postProject
	EndProjectSection
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "gtest_prod_test", "gtest_prod_test.vcproj", "{24848551-EF4F-47E8-9A9D-EA4D49BC3ECA}"
	ProjectSection(ProjectDependencies) = postProject
	EndProjectSection
EndProject
Global
	GlobalSection(SolutionConfiguration) = preSolution
		Debug = Debug
		Release = Release
	EndGlobalSection
	GlobalSection(ProjectConfiguration) = postSolution
		{C8F6C172-56F2-4E76-B5FA-C3B423B31BE7}.Debug.ActiveCfg = Debug|Win32
		{C8F6C172-56F2-4E76-B5FA-C3B423B31BE7}.Debug.Build.0 = Debug|Win32
		{C8F6C172-56F2-4E76-B5FA-C3B423B31BE7}.Release.ActiveCfg = Release|Win32
		{C8F6C172-56F2-4E76-B5FA-C3B423B31BE7}.Release.Build.0 = Release|Win32
		{3AF54C8A-10BF-4332-9147-F68ED9862032}.Debug.ActiveCfg = Debug|Win32
		{3AF54C8A-10BF-4332-9147-F68ED9862032}.Debug.Build.0 = Debug|Win32
		{3AF54C8A-10BF-4332-9147-F68ED9862032}.Release.ActiveCfg = Release|Win32
		{3AF54C8A-10BF-4332-9147-F68ED9862032}.Release.Build.0 = Release|Win32
		{4D9FDFB5-986A-4139-823C-F4EE0ED481A1}.Debug.ActiveCfg = Debug|Win32
		{4D9FDFB5-986A-4139-823C-F4EE0ED481A1}.Debug.Build.0 = Debug|Win32
		{4D9FDFB5-986A-4139-823C-F4EE0ED481A1}.Release.ActiveCfg = Release|Win32
		{4D9FDFB5-986A-4139-823C-F4EE0ED481A1}.Release.Build.0 = Release|Win32
		{24848551-EF4F-47E8-9A9D-EA4D49BC3ECA}.Debug.ActiveCfg = Debug|Win32
		{24848551-EF4F-47E8-9A9D-EA4D49BC3ECA}.Debug.Build.0 = Debug|Win32
		{24848551-EF4F-47E8-9A9D-EA4D49BC3ECA}.Release.ActiveCfg = Release|Win32
		{24848551-EF4F-47E8-9A9D-EA4D49BC3ECA}.Release.Build.0 = Release|Win32
	EndGlobalSection
	GlobalSection(ExtensibilityGlobals) = postSolution
	EndGlobalSection
	GlobalSection(ExtensibilityAddIns) = postSolution
	EndGlobalSection
EndGlobal
"#;

    const SOLUTION_WITH_MISSING_PROJECT_CONFIGS: &str = r#"
Microsoft Visual Studio Solution File, Format Version 11.00
# Visual Studio 2010
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "a", "a\a.csproj", "{78965571-A6C2-4161-95B1-813B46610EA7}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "b", "b\b.csproj", "{D9523F4D-6CB7-4431-85F6-8122F55EB144}"
EndProject
Global
	GlobalSection(SolutionConfigurationPlatforms) = preSolution
		Debug|Any CPU = Debug|Any CPU
		Release|Any CPU = Release|Any CPU
	EndGlobalSection
	GlobalSection(ProjectConfigurationPlatforms) = postSolution
		{78965571-A6C2-4161-95B1-813B46610EA7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
		{78965571-A6C2-4161-95B1-813B46610EA7}.Debug|Any CPU.Build.0 = Debug|Any CPU
		{78965571-A6C2-4161-95B1-813B46610EA7}.Debug|x86.ActiveCfg = Debug|Any CPU
		{78965571-A6C2-4161-95B1-813B46610EA7}.Debug|x86.Build.0 = Debug|Any CPU
		{78965571-A6C2-4161-95B1-813B46610EA7}.Release|Any CPU.ActiveCfg = Release|Any CPU
		{78965571-A6C2-4161-95B1-813B46610EA7}.Release|Any CPU.Build.0 = Release|Any CPU
		{D9523F4D-6CB7-4431-85F6-8122F55EB144}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
		{D9523F4D-6CB7-4431-85F6-8122F55EB144}.Debug|Any CPU.Build.0 = Debug|Any CPU
		{D9523F4D-6CB7-4431-85F6-8122F55EB144}.Debug|x86.ActiveCfg = Debug|Any CPU
		{D9523F4D-6CB7-4431-85F6-8122F55EB144}.Debug|x86.Build.0 = Debug|Any CPU
		{D9523F4D-6CB7-4431-85F6-8122F55EB144}.Release|Any CPU.ActiveCfg = Release|Any CPU
		{D9523F4D-6CB7-4431-85F6-8122F55EB144}.Release|Any CPU.Build.0 = Release|Any CPU
	EndGlobalSection
	GlobalSection(SolutionProperties) = preSolution
		HideSolutionNode = FALSE
	EndGlobalSection
EndGlobal
"#;

    const SOLUTION_WITH_DANGLINGS: &str = r#"
Microsoft Visual Studio Solution File, Format Version 8.00
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "gtest", "gtest.vcproj", "{C8F6C172-56F2-4E76-B5FA-C3B423B31BE7}"
	ProjectSection(ProjectDependencies) = postProject
	EndProjectSection
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "gtest_main", "gtest_main.vcproj", "{3AF54C8A-10BF-4332-9147-F68ED9862032}"
	ProjectSection(ProjectDependencies) = postProject
	EndProjectSection
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "gtest_unittest", "gtest_unittest.vcproj", "{4D9FDFB5-986A-4139-823C-F4EE0ED481A1}"
	ProjectSection(ProjectDependencies) = postProject
	EndProjectSection
EndProject
Global
	GlobalSection(SolutionConfiguration) = preSolution
		Debug = Debug
		Release = Release
	EndGlobalSection
	GlobalSection(ProjectConfiguration) = postSolution
		{C8F6C172-56F2-4E76-B5FA-C3B423B31BE7}.Debug.ActiveCfg = Debug|Win32
		{C8F6C172-56F2-4E76-B5FA-C3B423B31BE7}.Debug.Build.0 = Debug|Win32
		{C8F6C172-56F2-4E76-B5FA-C3B423B31BE7}.Release.ActiveCfg = Release|Win32
		{C8F6C172-56F2-4E76-B5FA-C3B423B31BE7}.Release.Build.0 = Release|Win32
		{3AF54C8A-10BF-4332-9147-F68ED9862032}.Debug.ActiveCfg = Debug|Win32
		{3AF54C8A-10BF-4332-9147-F68ED9862032}.Debug.Build.0 = Debug|Win32
		{3AF54C8A-10BF-4332-9147-F68ED9862032}.Release.ActiveCfg = Release|Win32
		{3AF54C8A-10BF-4332-9147-F68ED9862032}.Release.Build.0 = Release|Win32
		{4D9FDFB5-986A-4139-823C-F4EE0ED481A1}.Debug.ActiveCfg = Debug|Win32
		{4D9FDFB5-986A-4139-823C-F4EE0ED481A1}.Debug.Build.0 = Debug|Win32
		{4D9FDFB5-986A-4139-823C-F4EE0ED481A1}.Release.ActiveCfg = Release|Win32
		{4D9FDFB5-986A-4139-823C-F4EE0ED481A1}.Release.Build.0 = Release|Win32
		{24848551-EF4F-47E8-9A9D-EA4D49BC3ECA}.Debug.ActiveCfg = Debug|Win32
		{24848551-EF4F-47E8-9A9D-EA4D49BC3ECA}.Debug.Build.0 = Debug|Win32
		{24848551-EF4F-47E8-9A9D-EA4D49BC3ECA}.Release.ActiveCfg = Release|Win32
		{24848551-EF4F-47E8-9A9D-EA4D49BC3ECA}.Release.Build.0 = Release|Win32
	EndGlobalSection
	GlobalSection(ExtensibilityGlobals) = postSolution
	EndGlobalSection
	GlobalSection(ExtensibilityAddIns) = postSolution
	EndGlobalSection
EndGlobal
"#;

    const SOLUTION_WITH_CYCLES: &str = r#"
Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
VisualStudioVersion = 15.0.26403.0
MinimumVisualStudioVersion = 10.0.40219.1
Project("{930C7802-8A8C-48F9-8165-68863BCCD9DD}") = "logviewer.install", "logviewer.install\logviewer.install.wixproj", "{27060CA7-FB29-42BC-BA66-7FC80D498354}"
	ProjectSection(ProjectDependencies) = postProject
		{405827CB-84E1-46F3-82C9-D889892645AC} = {405827CB-84E1-46F3-82C9-D889892645AC}
		{CFBAE2FB-6E3F-44CF-9FC9-372D6EA8DD3D} = {CFBAE2FB-6E3F-44CF-9FC9-372D6EA8DD3D}
	EndProjectSection
EndProject
Project("{930C7802-8A8C-48F9-8165-68863BCCD9DD}") = "logviewer.install.bootstrap", "logviewer.install.bootstrap\logviewer.install.bootstrap.wixproj", "{1C0ED62B-D506-4E72-BBC2-A50D3926466E}"
	ProjectSection(ProjectDependencies) = postProject
		{27060CA7-FB29-42BC-BA66-7FC80D498354} = {27060CA7-FB29-42BC-BA66-7FC80D498354}
	EndProjectSection
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "solution items", "solution items", "{3B960F8F-AD5D-45E7-92C0-05B65E200AC4}"
	ProjectSection(SolutionItems) = preProject
		.editorconfig = .editorconfig
		appveyor.yml = appveyor.yml
		logviewer.xml = logviewer.xml
		WiX.msbuild = WiX.msbuild
	EndProjectSection
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "logviewer.tests", "logviewer.tests\logviewer.tests.csproj", "{939DD379-CDC8-47EF-8D37-0E5E71D99D30}"
	ProjectSection(ProjectDependencies) = postProject
		{383C08FC-9CAC-42E5-9B02-471561479A74} = {383C08FC-9CAC-42E5-9B02-471561479A74}
	EndProjectSection
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "logviewer.logic", "logviewer.logic\logviewer.logic.csproj", "{383C08FC-9CAC-42E5-9B02-471561479A74}"
	ProjectSection(ProjectDependencies) = postProject
		{939DD379-CDC8-47EF-8D37-0E5E71D99D30} = {939DD379-CDC8-47EF-8D37-0E5E71D99D30}
	EndProjectSection
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = ".nuget", ".nuget", "{B720ED85-58CF-4840-B1AE-55B0049212CC}"
	ProjectSection(SolutionItems) = preProject
		.nuget\NuGet.Config = .nuget\NuGet.Config
	EndProjectSection
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "logviewer.engine", "logviewer.engine\logviewer.engine.csproj", "{90E3A68D-C96D-4764-A1D0-F73D9F474BE4}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "logviewer.install.mca", "logviewer.install.mca\logviewer.install.mca.csproj", "{405827CB-84E1-46F3-82C9-D889892645AC}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "logviewer.ui", "logviewer.ui\logviewer.ui.csproj", "{CFBAE2FB-6E3F-44CF-9FC9-372D6EA8DD3D}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "logviewer.bench", "logviewer.bench\logviewer.bench.csproj", "{75E0C034-44C8-461B-A677-9A19566FE393}"
EndProject
Global
	GlobalSection(SolutionConfigurationPlatforms) = preSolution
		Debug|Any CPU = Debug|Any CPU
		Debug|Mixed Platforms = Debug|Mixed Platforms
		Debug|x86 = Debug|x86
		Release|Any CPU = Release|Any CPU
		Release|Mixed Platforms = Release|Mixed Platforms
		Release|x86 = Release|x86
	EndGlobalSection
	GlobalSection(ProjectConfigurationPlatforms) = postSolution
		{27060CA7-FB29-42BC-BA66-7FC80D498354}.Debug|Any CPU.ActiveCfg = Debug|x86
		{27060CA7-FB29-42BC-BA66-7FC80D498354}.Debug|Any CPU.Build.0 = Debug|x86
		{27060CA7-FB29-42BC-BA66-7FC80D498354}.Debug|Mixed Platforms.ActiveCfg = Debug|x86
		{27060CA7-FB29-42BC-BA66-7FC80D498354}.Debug|Mixed Platforms.Build.0 = Debug|x86
		{27060CA7-FB29-42BC-BA66-7FC80D498354}.Debug|x86.ActiveCfg = Debug|x86
		{27060CA7-FB29-42BC-BA66-7FC80D498354}.Debug|x86.Build.0 = Debug|x86
		{27060CA7-FB29-42BC-BA66-7FC80D498354}.Release|Any CPU.ActiveCfg = Release|x86
		{27060CA7-FB29-42BC-BA66-7FC80D498354}.Release|Any CPU.Build.0 = Release|x86
		{27060CA7-FB29-42BC-BA66-7FC80D498354}.Release|Mixed Platforms.ActiveCfg = Release|x86
		{27060CA7-FB29-42BC-BA66-7FC80D498354}.Release|Mixed Platforms.Build.0 = Release|x86
		{27060CA7-FB29-42BC-BA66-7FC80D498354}.Release|x86.ActiveCfg = Release|x86
		{27060CA7-FB29-42BC-BA66-7FC80D498354}.Release|x86.Build.0 = Release|x86
		{1C0ED62B-D506-4E72-BBC2-A50D3926466E}.Debug|Any CPU.ActiveCfg = Debug|x86
		{1C0ED62B-D506-4E72-BBC2-A50D3926466E}.Debug|Any CPU.Build.0 = Debug|x86
		{1C0ED62B-D506-4E72-BBC2-A50D3926466E}.Debug|Mixed Platforms.ActiveCfg = Debug|x86
		{1C0ED62B-D506-4E72-BBC2-A50D3926466E}.Debug|Mixed Platforms.Build.0 = Debug|x86
		{1C0ED62B-D506-4E72-BBC2-A50D3926466E}.Debug|x86.ActiveCfg = Debug|x86
		{1C0ED62B-D506-4E72-BBC2-A50D3926466E}.Debug|x86.Build.0 = Debug|x86
		{1C0ED62B-D506-4E72-BBC2-A50D3926466E}.Release|Any CPU.ActiveCfg = Release|x86
		{1C0ED62B-D506-4E72-BBC2-A50D3926466E}.Release|Any CPU.Build.0 = Release|x86
		{1C0ED62B-D506-4E72-BBC2-A50D3926466E}.Release|Mixed Platforms.ActiveCfg = Release|x86
		{1C0ED62B-D506-4E72-BBC2-A50D3926466E}.Release|Mixed Platforms.Build.0 = Release|x86
		{1C0ED62B-D506-4E72-BBC2-A50D3926466E}.Release|x86.ActiveCfg = Release|x86
		{1C0ED62B-D506-4E72-BBC2-A50D3926466E}.Release|x86.Build.0 = Release|x86
		{939DD379-CDC8-47EF-8D37-0E5E71D99D30}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
		{939DD379-CDC8-47EF-8D37-0E5E71D99D30}.Debug|Any CPU.Build.0 = Debug|Any CPU
		{939DD379-CDC8-47EF-8D37-0E5E71D99D30}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
		{939DD379-CDC8-47EF-8D37-0E5E71D99D30}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU
		{939DD379-CDC8-47EF-8D37-0E5E71D99D30}.Debug|x86.ActiveCfg = Debug|Any CPU
		{939DD379-CDC8-47EF-8D37-0E5E71D99D30}.Release|Any CPU.ActiveCfg = Release|Any CPU
		{939DD379-CDC8-47EF-8D37-0E5E71D99D30}.Release|Any CPU.Build.0 = Release|Any CPU
		{939DD379-CDC8-47EF-8D37-0E5E71D99D30}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
		{939DD379-CDC8-47EF-8D37-0E5E71D99D30}.Release|Mixed Platforms.Build.0 = Release|Any CPU
		{939DD379-CDC8-47EF-8D37-0E5E71D99D30}.Release|x86.ActiveCfg = Release|Any CPU
		{383C08FC-9CAC-42E5-9B02-471561479A74}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
		{383C08FC-9CAC-42E5-9B02-471561479A74}.Debug|Any CPU.Build.0 = Debug|Any CPU
		{383C08FC-9CAC-42E5-9B02-471561479A74}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
		{383C08FC-9CAC-42E5-9B02-471561479A74}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU
		{383C08FC-9CAC-42E5-9B02-471561479A74}.Debug|x86.ActiveCfg = Debug|Any CPU
		{383C08FC-9CAC-42E5-9B02-471561479A74}.Release|Any CPU.ActiveCfg = Release|Any CPU
		{383C08FC-9CAC-42E5-9B02-471561479A74}.Release|Any CPU.Build.0 = Release|Any CPU
		{383C08FC-9CAC-42E5-9B02-471561479A74}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
		{383C08FC-9CAC-42E5-9B02-471561479A74}.Release|Mixed Platforms.Build.0 = Release|Any CPU
		{383C08FC-9CAC-42E5-9B02-471561479A74}.Release|x86.ActiveCfg = Release|Any CPU
		{90E3A68D-C96D-4764-A1D0-F73D9F474BE4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
		{90E3A68D-C96D-4764-A1D0-F73D9F474BE4}.Debug|Any CPU.Build.0 = Debug|Any CPU
		{90E3A68D-C96D-4764-A1D0-F73D9F474BE4}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
		{90E3A68D-C96D-4764-A1D0-F73D9F474BE4}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU
		{90E3A68D-C96D-4764-A1D0-F73D9F474BE4}.Debug|x86.ActiveCfg = Debug|Any CPU
		{90E3A68D-C96D-4764-A1D0-F73D9F474BE4}.Release|Any CPU.ActiveCfg = Release|Any CPU
		{90E3A68D-C96D-4764-A1D0-F73D9F474BE4}.Release|Any CPU.Build.0 = Release|Any CPU
		{90E3A68D-C96D-4764-A1D0-F73D9F474BE4}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
		{90E3A68D-C96D-4764-A1D0-F73D9F474BE4}.Release|Mixed Platforms.Build.0 = Release|Any CPU
		{90E3A68D-C96D-4764-A1D0-F73D9F474BE4}.Release|x86.ActiveCfg = Release|Any CPU
		{405827CB-84E1-46F3-82C9-D889892645AC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
		{405827CB-84E1-46F3-82C9-D889892645AC}.Debug|Any CPU.Build.0 = Debug|Any CPU
		{405827CB-84E1-46F3-82C9-D889892645AC}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
		{405827CB-84E1-46F3-82C9-D889892645AC}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU
		{405827CB-84E1-46F3-82C9-D889892645AC}.Debug|x86.ActiveCfg = Debug|Any CPU
		{405827CB-84E1-46F3-82C9-D889892645AC}.Release|Any CPU.ActiveCfg = Release|Any CPU
		{405827CB-84E1-46F3-82C9-D889892645AC}.Release|Any CPU.Build.0 = Release|Any CPU
		{405827CB-84E1-46F3-82C9-D889892645AC}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
		{405827CB-84E1-46F3-82C9-D889892645AC}.Release|Mixed Platforms.Build.0 = Release|Any CPU
		{405827CB-84E1-46F3-82C9-D889892645AC}.Release|x86.ActiveCfg = Release|Any CPU
		{CFBAE2FB-6E3F-44CF-9FC9-372D6EA8DD3D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
		{CFBAE2FB-6E3F-44CF-9FC9-372D6EA8DD3D}.Debug|Any CPU.Build.0 = Debug|Any CPU
		{CFBAE2FB-6E3F-44CF-9FC9-372D6EA8DD3D}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
		{CFBAE2FB-6E3F-44CF-9FC9-372D6EA8DD3D}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU
		{CFBAE2FB-6E3F-44CF-9FC9-372D6EA8DD3D}.Debug|x86.ActiveCfg = Debug|Any CPU
		{CFBAE2FB-6E3F-44CF-9FC9-372D6EA8DD3D}.Release|Any CPU.ActiveCfg = Release|Any CPU
		{CFBAE2FB-6E3F-44CF-9FC9-372D6EA8DD3D}.Release|Any CPU.Build.0 = Release|Any CPU
		{CFBAE2FB-6E3F-44CF-9FC9-372D6EA8DD3D}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
		{CFBAE2FB-6E3F-44CF-9FC9-372D6EA8DD3D}.Release|Mixed Platforms.Build.0 = Release|Any CPU
		{CFBAE2FB-6E3F-44CF-9FC9-372D6EA8DD3D}.Release|x86.ActiveCfg = Release|Any CPU
		{75E0C034-44C8-461B-A677-9A19566FE393}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
		{75E0C034-44C8-461B-A677-9A19566FE393}.Debug|Any CPU.Build.0 = Debug|Any CPU
		{75E0C034-44C8-461B-A677-9A19566FE393}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
		{75E0C034-44C8-461B-A677-9A19566FE393}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU
		{75E0C034-44C8-461B-A677-9A19566FE393}.Debug|x86.ActiveCfg = Debug|Any CPU
		{75E0C034-44C8-461B-A677-9A19566FE393}.Debug|x86.Build.0 = Debug|Any CPU
		{75E0C034-44C8-461B-A677-9A19566FE393}.Release|Any CPU.ActiveCfg = Release|Any CPU
		{75E0C034-44C8-461B-A677-9A19566FE393}.Release|Any CPU.Build.0 = Release|Any CPU
		{75E0C034-44C8-461B-A677-9A19566FE393}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
		{75E0C034-44C8-461B-A677-9A19566FE393}.Release|Mixed Platforms.Build.0 = Release|Any CPU
		{75E0C034-44C8-461B-A677-9A19566FE393}.Release|x86.ActiveCfg = Release|Any CPU
		{75E0C034-44C8-461B-A677-9A19566FE393}.Release|x86.Build.0 = Release|Any CPU
	EndGlobalSection
	GlobalSection(SolutionProperties) = preSolution
		HideSolutionNode = FALSE
	EndGlobalSection
EndGlobal
"#;
}