summaryrefslogtreecommitdiffstatshomepage
path: root/3rdparty/genie/src/actions/vstudio/vstudio_vcxproj.lua
blob: 106996909da8dd6b04dd6cfc1ef69c6072e89c1a (plain) (blame)
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
--
-- vs2010_vcxproj.lua
-- Generate a Visual Studio 2010 C/C++ project.
-- Copyright (c) 2009-2011 Jason Perkins and the Premake project
--

	premake.vstudio.vc2010 = { }
	local vc2010 = premake.vstudio.vc2010
	local vstudio = premake.vstudio


	local function vs2010_config(prj)
		-- only include this bit if there's a Tegra platform in there
		for _, cfginfo in ipairs(prj.solution.vstudio_configs) do
			if cfginfo.src_platform == "TegraAndroid" then
				_p(1,'<PropertyGroup Label="NsightTegraProject">')
					_p(2,'<NsightTegraProjectRevisionNumber>11</NsightTegraProjectRevisionNumber>')
				_p(1,'</PropertyGroup>')
				break
			end
		end
		_p(1,'<ItemGroup Label="ProjectConfigurations">')
		for _, cfginfo in ipairs(prj.solution.vstudio_configs) do
				_p(2,'<ProjectConfiguration Include="%s">', premake.esc(cfginfo.name))
					_p(3,'<Configuration>%s</Configuration>',cfginfo.buildcfg)
					_p(3,'<Platform>%s</Platform>',cfginfo.platform)
				_p(2,'</ProjectConfiguration>')
		end
		_p(1,'</ItemGroup>')
	end

	local function vs2010_globals(prj)
		local action = premake.action.current()
		_p(1,'<PropertyGroup Label="Globals">')
			_p(2, '<ProjectGuid>{%s}</ProjectGuid>',prj.uuid)
			_p(2, '<RootNamespace>%s</RootNamespace>',prj.name)
			if vstudio.storeapp ~= "durango" then
				local windowsTargetPlatformVersion = prj.windowstargetplatformversion or action.vstudio.windowsTargetPlatformVersion
				if windowsTargetPlatformVersion ~= nil then
					_p(2,'<WindowsTargetPlatformVersion>%s</WindowsTargetPlatformVersion>',windowsTargetPlatformVersion)

					if windowsTargetPlatformVersion and string.startswith(windowsTargetPlatformVersion, "10.") then
						_p(2,'<WindowsTargetPlatformMinVersion>%s</WindowsTargetPlatformMinVersion>', prj.windowstargetplatformminversion or "10.0.10240.0")
					end
				end
			end
		--if prj.flags is required as it is not set at project level for tests???
		--vs200x generator seems to swap a config for the prj in test setup
		if prj.flags and prj.flags.Managed then
			local frameworkVersion = prj.framework or "4.0"
			_p(2, '<TargetFrameworkVersion>v%s</TargetFrameworkVersion>', frameworkVersion)
			_p(2, '<Keyword>ManagedCProj</Keyword>')
		elseif vstudio.iswinrt() then
			_p(2, '<DefaultLanguage>en-US</DefaultLanguage>')
			if vstudio.storeapp == "durango" then
				_p(2, '<Keyword>Win32Proj</Keyword>')
				_p(2, '<ApplicationEnvironment>title</ApplicationEnvironment>')
				_p(2, '<MinimumVisualStudioVersion>14.0</MinimumVisualStudioVersion>')
				_p(2, '<TargetRuntime>Native</TargetRuntime>')
			else
				_p(2, '<AppContainerApplication>true</AppContainerApplication>')
				_p(2, '<MinimumVisualStudioVersion>12.0</MinimumVisualStudioVersion>')
				_p(2, '<ApplicationType>Windows Store</ApplicationType>')
				_p(2, '<ApplicationTypeRevision>%s</ApplicationTypeRevision>', vstudio.storeapp)
			end
		else
			_p(2, '<Keyword>Win32Proj</Keyword>')
		end
		if _ACTION:sub(3) == "2015" or _ACTION:sub(3) == "2017" or _ACTION:sub(3) == "llvm" then
			_p(2,'<PreferredToolArchitecture>x64</PreferredToolArchitecture>')
		end
		if (_ACTION:sub(3) == "2017" or _ACTION:sub(3) == "llvm")
		and os.isdir(path.join(os.getenv("VSINSTALLDIR"), "VC/Tools/MSVC/14.14.26428")) then
			_p(2,'<VCToolsVersion>14.14.26428</VCToolsVersion>')
		end

		if not vstudio.xpwarning then
			_p(2, '<XPDeprecationWarning>false</XPDeprecationWarning>')
		end

		_p(1,'</PropertyGroup>')
	end

	function vc2010.config_type(config)
		local t =
		{
			SharedLib = "DynamicLibrary",
			StaticLib = "StaticLibrary",
			ConsoleApp = "Application",
			WindowedApp = "Application"
		}
		return t[config.kind]
	end



	local function if_config_and_platform()
		return 'Condition="\'$(Configuration)|$(Platform)\'==\'%s\'"'
	end

	local function optimisation(cfg)
		local result = "Disabled"
		for _, value in ipairs(cfg.flags) do
			if (value == "Optimize") then
				result = "Full"
			elseif (value == "OptimizeSize") then
				result = "MinSpace"
			elseif (value == "OptimizeSpeed") then
				result = "MaxSpeed"
			end
		end
		return result
	end


--
-- This property group describes a particular configuration: what
-- kind of binary it produces, and some global settings.
--

	function vc2010.configurationPropertyGroup(cfg, cfginfo)
		_p(1, '<PropertyGroup '..if_config_and_platform() ..' Label="Configuration">'
			, premake.esc(cfginfo.name))

		local is2019 = premake.action.current() == premake.action.get("vs2019")
		if is2019 then
		    _p(2, '<VCProjectVersion>%s</VCProjectVersion>', action.vstudio.toolsVersion)
			if cfg.flags.UnitySupport then
			    _p(2, '<EnableUnitySupport>true</EnableUnitySupport>')
			end
		end
		_p(2, '<ConfigurationType>%s</ConfigurationType>', vc2010.config_type(cfg))
		_p(2, '<UseDebugLibraries>%s</UseDebugLibraries>', iif(optimisation(cfg) == "Disabled","true","false"))
		_p(2, '<PlatformToolset>%s</PlatformToolset>',     premake.vstudio.toolset)

		if os.is64bit() then
			_p(2, '<PreferredToolArchitecture>x64</PreferredToolArchitecture>')
		end

		if cfg.flags.MFC then
			_p(2,'<UseOfMfc>%s</UseOfMfc>', iif(cfg.flags.StaticRuntime, "Static", "Dynamic"))
		end

		if cfg.flags.ATL or cfg.flags.StaticATL then
			_p(2,'<UseOfAtl>%s</UseOfAtl>', iif(cfg.flags.StaticATL, "Static", "Dynamic"))
		end

		if cfg.flags.Unicode then
			_p(2,'<CharacterSet>Unicode</CharacterSet>')
		end

		if cfg.flags.Managed then
			_p(2,'<CLRSupport>true</CLRSupport>')
		end

		if cfg.platform == "TegraAndroid" then
			if cfg.androidtargetapi then
				_p(2,'<AndroidTargetAPI>android-%s</AndroidTargetAPI>', cfg.androidtargetapi)
			end
			if cfg.androidminapi then
				_p(2,'<AndroidMinAPI>android-%s</AndroidMinAPI>', cfg.androidminapi)
			end
			if cfg.androidarch then
				_p(2,'<AndroidArch>%s</AndroidArch>', cfg.androidarch)
			end
			if cfg.androidndktoolchainversion then
				_p(2,'<NdkToolchainVersion>%s</NdkToolchainVersion>', cfg.androidndktoolchainversion)
			end
			if cfg.androidstltype then
				_p(2,'<AndroidStlType>%s</AndroidStlType>', cfg.androidstltype)
			end
		end

		if cfg.platform == "NX32" or cfg.platform == "NX64" then
			_p(2,'<NintendoSdkRoot>$(NINTENDO_SDK_ROOT)\\</NintendoSdkRoot>')
			_p(2,'<NintendoSdkSpec>NX</NintendoSdkSpec>')
			--TODO: Allow specification of the 'Develop' build type
			if premake.config.isdebugbuild(cfg) then
				_p(2,'<NintendoSdkBuildType>Debug</NintendoSdkBuildType>')
			else
				_p(2,'<NintendoSdkBuildType>Release</NintendoSdkBuildType>')
			end
		end

		-- Workaround for https://github.com/Microsoft/msbuild/issues/2353
		if cfg.flags.Symbols and (premake.action.current() == premake.action.get("vs2017") or is2019) then
			_p(2, '<DebugSymbols>true</DebugSymbols>')
		end

		_p(1,'</PropertyGroup>')
	end


	local function import_props(prj)
		for _, cfginfo in ipairs(prj.solution.vstudio_configs) do
			local cfg = premake.getconfig(prj, cfginfo.src_buildcfg, cfginfo.src_platform)
			_p(1,'<ImportGroup '..if_config_and_platform() ..' Label="PropertySheets">'
					,premake.esc(cfginfo.name))
				_p(2,'<Import Project="$(UserRootDir)\\Microsoft.Cpp.$(Platform).user.props" Condition="exists(\'$(UserRootDir)\\Microsoft.Cpp.$(Platform).user.props\')" Label="LocalAppDataPlatform" />')

			if #cfg.propertysheets > 0 then
				local dirs = cfg.propertysheets
				for _, dir in ipairs(dirs) do
					_p(2,'<Import Project="%s" />', path.translate(dir))
				end
			end

			_p(1,'</ImportGroup>')
		end
	end

	local function add_trailing_backslash(dir)
		if dir:len() > 0 and dir:sub(-1) ~= "\\" then
			return dir.."\\"
		end
		return dir
	end

	function vc2010.outputProperties(prj)
		for _, cfginfo in ipairs(prj.solution.vstudio_configs) do
			local cfg = premake.getconfig(prj, cfginfo.src_buildcfg, cfginfo.src_platform)
			local target = cfg.buildtarget
			local outdir = add_trailing_backslash(target.directory)
			local intdir = add_trailing_backslash(iif(action.vstudio.intDirAbsolute
							, path.translate(
								  path.join(prj.solution.location, cfg.objectsdir)
								, '\\')
							, cfg.objectsdir
							))

			_p(1,'<PropertyGroup '..if_config_and_platform() ..'>', premake.esc(cfginfo.name))

			_p(2,'<OutDir>%s</OutDir>', iif(outdir:len() > 0, premake.esc(outdir), ".\\"))

			if cfg.platform == "Xbox360" then
				_p(2,'<OutputFile>$(OutDir)%s</OutputFile>', premake.esc(target.name))
			end

			_p(2,'<IntDir>%s</IntDir>', premake.esc(intdir))
			_p(2,'<TargetName>%s</TargetName>', premake.esc(path.getbasename(target.name)))
			_p(2,'<TargetExt>%s</TargetExt>', premake.esc(path.getextension(target.name)))

			if cfg.kind == "SharedLib" then
				local ignore = (cfg.flags.NoImportLib ~= nil)
				_p(2,'<IgnoreImportLibrary>%s</IgnoreImportLibrary>', tostring(ignore))
			end

			if cfg.platform == "Durango" then
				_p(2, '<ReferencePath>$(Console_SdkLibPath);$(Console_SdkWindowsMetadataPath)</ReferencePath>')
				_p(2, '<LibraryPath>$(Console_SdkLibPath)</LibraryPath>')
				_p(2, '<LibraryWPath>$(Console_SdkLibPath);$(Console_SdkWindowsMetadataPath)</LibraryWPath>')
				_p(2, '<IncludePath>$(Console_SdkIncludeRoot)</IncludePath>')
				_p(2, '<ExecutablePath>$(Console_SdkRoot)bin;$(VCInstallDir)bin\\x86_amd64;$(VCInstallDir)bin;$(WindowsSDK_ExecutablePath_x86);$(VSInstallDir)Common7\\Tools\\bin;$(VSInstallDir)Common7\\tools;$(VSInstallDir)Common7\\ide;$(ProgramFiles)\\HTML Help Workshop;$(MSBuildToolsPath32);$(FxCopDir);$(PATH);</ExecutablePath>')

				if cfg.imagepath then
					_p(2, '<LayoutDir>%s</LayoutDir>', cfg.imagepath)
				else
					_p(2, '<LayoutDir>%s</LayoutDir>', prj.name)
				end

				if cfg.pullmappingfile ~= nil then
					_p(2,'<PullMappingFile>%s</PullMappingFile>', premake.esc(cfg.pullmappingfile))
				end

				_p(2, '<LayoutExtensionFilter>*.pdb;*.ilk;*.exp;*.lib;*.winmd;*.appxrecipe;*.pri;*.idb</LayoutExtensionFilter>')
				_p(2, '<IsolateConfigurationsOnDeploy>true</IsolateConfigurationsOnDeploy>')
			end

			if cfg.kind ~= "StaticLib" then
				_p(2,'<LinkIncremental>%s</LinkIncremental>', tostring(premake.config.isincrementallink(cfg)))
			end

			if cfg.applicationdatadir ~= nil then
				_p(2,'<ApplicationDataDir>%s</ApplicationDataDir>', premake.esc(cfg.applicationdatadir))
			end

			if cfg.flags.NoManifest then
				_p(2,'<GenerateManifest>false</GenerateManifest>')
			end

			_p(1,'</PropertyGroup>')
		end
	end

	local function runtime(cfg)
		local runtime
		local flags = cfg.flags
		if premake.config.isdebugbuild(cfg) then
			runtime = iif(flags.StaticRuntime and not flags.Managed, "MultiThreadedDebug", "MultiThreadedDebugDLL")
		else
			runtime = iif(flags.StaticRuntime and not flags.Managed, "MultiThreaded", "MultiThreadedDLL")
		end
		return runtime
	end

	local function precompiled_header(cfg)
      	if not cfg.flags.NoPCH and cfg.pchheader then
			_p(3,'<PrecompiledHeader>Use</PrecompiledHeader>')
			_p(3,'<PrecompiledHeaderFile>%s</PrecompiledHeaderFile>', cfg.pchheader)
		else
			_p(3,'<PrecompiledHeader></PrecompiledHeader>')
		end
	end

	local function preprocessor(indent,cfg,escape)
		if #cfg.defines > 0 then
			-- Visual Studio requires escaping of command line arguments to RC.
			local defines = table.concat(cfg.defines, ";")
			if escape then
				defines = defines:gsub('"', '\\"')
			end

			-- do not add `%(PreprocessorDefinitions)` if it's already part of defines
			local isPreprocessorDefinitionPresent = string.find(defines, "%%%(PreprocessorDefinitions%)")
			if isPreprocessorDefinitionPresent then
				_p(indent,'<PreprocessorDefinitions>%s</PreprocessorDefinitions>'
					,premake.esc(defines))
			else
				_p(indent,'<PreprocessorDefinitions>%s;%%(PreprocessorDefinitions)</PreprocessorDefinitions>'
					,premake.esc(defines))
			end
		else
			_p(indent,'<PreprocessorDefinitions></PreprocessorDefinitions>')
		end
	end

	local function include_dirs(indent,cfg)
		local includedirs = table.join(cfg.userincludedirs, cfg.includedirs, cfg.systemincludedirs)

		if #includedirs> 0 then
			_p(indent,'<AdditionalIncludeDirectories>%s;%%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>'
					,premake.esc(path.translate(table.concat(includedirs, ";"), '\\')))
		end
	end

	local function using_dirs(indent,cfg)
		if #cfg.usingdirs > 0 then
			_p(indent,'<AdditionalUsingDirectories>%s;%%(AdditionalUsingDirectories)</AdditionalUsingDirectories>'
					,premake.esc(path.translate(table.concat(cfg.usingdirs, ";"), '\\')))
		end
	end

	local function resource_compile(cfg)
		_p(2,'<ResourceCompile>')
			preprocessor(3,cfg,true)
			include_dirs(3,cfg)
		_p(2,'</ResourceCompile>')

	end

	local function cppstandard_vs2017_or_2019(cfg)
		if cfg.flags.CppLatest then
			_p(3, '<LanguageStandard>stdcpplatest</LanguageStandard>')
			_p(3, '<EnableModules>true</EnableModules>')
		elseif cfg.flags.Cpp17 then
			_p(3, '<LanguageStandard>stdcpp17</LanguageStandard>')
		elseif cfg.flags.Cpp14 then
			_p(3, '<LanguageStandard>stdcpp14</LanguageStandard>')
		end
	end

	local function exceptions(cfg)
		if cfg.platform == "Orbis" then
			if cfg.flags.NoExceptions then
				_p(3, '<CppExceptions>false</CppExceptions>')
			end
		elseif cfg.platform == "TegraAndroid" then
			if cfg.flags.NoExceptions then
				_p(3, '<GccExceptionHandling>false</GccExceptionHandling>')
			end
		else
			if cfg.flags.NoExceptions then
				_p(3, '<ExceptionHandling>false</ExceptionHandling>')
			elseif cfg.flags.SEH then
				_p(3, '<ExceptionHandling>Async</ExceptionHandling>')
			--SEH is not required for Managed and is implied
			end
		end
	end

	local function rtti(cfg)
		if cfg.flags.NoRTTI and not cfg.flags.Managed then
			_p(3,'<RuntimeTypeInfo>false</RuntimeTypeInfo>')
		end
	end

	local function calling_convention(cfg)
		if cfg.flags.FastCall then
			_p(3,'<CallingConvention>FastCall</CallingConvention>')
		elseif cfg.flags.StdCall then
			_p(3,'<CallingConvention>StdCall</CallingConvention>')
		end
	end

	local function wchar_t_builtin(cfg)
		if cfg.flags.NativeWChar then
			_p(3,'<TreatWChar_tAsBuiltInType>true</TreatWChar_tAsBuiltInType>')
		elseif cfg.flags.NoNativeWChar then
			_p(3,'<TreatWChar_tAsBuiltInType>false</TreatWChar_tAsBuiltInType>')
		end
	end

	local function sse(cfg)
		if cfg.flags.EnableSSE then
			_p(3, '<EnableEnhancedInstructionSet>StreamingSIMDExtensions</EnableEnhancedInstructionSet>')
		elseif cfg.flags.EnableSSE2 then
			_p(3, '<EnableEnhancedInstructionSet>StreamingSIMDExtensions2</EnableEnhancedInstructionSet>')
		elseif cfg.flags.EnableAVX then
			_p(3, '<EnableEnhancedInstructionSet>AdvancedVectorExtensions</EnableEnhancedInstructionSet>')
		elseif cfg.flags.EnableAVX2 then
			_p(3, '<EnableEnhancedInstructionSet>AdvancedVectorExtensions2</EnableEnhancedInstructionSet>')
		end
	end

	local function floating_point(cfg)
		if cfg.platform == "Orbis" then
			if cfg.flags.FloatFast then
				_p(3,'<FastMath>true</FastMath>')
			end
		elseif cfg.platform == "TegraAndroid" then
			-- TODO: tegra setting
		else
			if cfg.flags.FloatFast then
				_p(3,'<FloatingPointModel>Fast</FloatingPointModel>')
			elseif cfg.flags.FloatStrict and not cfg.flags.Managed then
				_p(3,'<FloatingPointModel>Strict</FloatingPointModel>')
			end
		end
	end


	local function debug_info(cfg)
	--
	--	EditAndContinue /ZI
	--	ProgramDatabase /Zi
	--	OldStyle C7 Compatable /Z7
	--
		local debug_info = ''
		if cfg.flags.Symbols then
			if cfg.flags.C7DebugInfo then
				debug_info = "OldStyle"
			elseif (action.vstudio.supports64bitEditContinue == false and cfg.platform == "x64")
				or not premake.config.iseditandcontinue(cfg)
			then
				debug_info = "ProgramDatabase"
			else
				debug_info = "EditAndContinue"
			end
		end

		_p(3,'<DebugInformationFormat>%s</DebugInformationFormat>',debug_info)
	end

	local function minimal_build(cfg)
		if premake.config.isdebugbuild(cfg) and cfg.flags.EnableMinimalRebuild then
			_p(3,'<MinimalRebuild>true</MinimalRebuild>')
		else
			_p(3,'<MinimalRebuild>false</MinimalRebuild>')
		end
	end

	local function compile_language(cfg)
		if cfg.options.ForceCPP then
			_p(3,'<CompileAs>CompileAsCpp</CompileAs>')
		else
			if cfg.language == "C" then
				_p(3,'<CompileAs>CompileAsC</CompileAs>')
			end
		end
	end

	local function forcedinclude_files(indent,cfg)
		if #cfg.forcedincludes > 0 then
			_p(indent,'<ForcedIncludeFiles>%s</ForcedIncludeFiles>'
					,premake.esc(path.translate(table.concat(cfg.forcedincludes, ";"), '\\')))
		end
	end

	local function vs10_clcompile(cfg)
		_p(2,'<ClCompile>')

		local unsignedChar = "/J "
		local buildoptions = cfg.buildoptions

		if cfg.platform == "Orbis" then
			unsignedChar = "-funsigned-char ";
			_p(3,'<GenerateDebugInformation>%s</GenerateDebugInformation>', tostring(cfg.flags.Symbols ~= nil))
		end

		if cfg.language == "C" and not cfg.options.ForceCPP then
			buildoptions = table.join(buildoptions, cfg.buildoptions_c)
		else
			buildoptions = table.join(buildoptions, cfg.buildoptions_cpp)
		end

		_p(3,'<AdditionalOptions>%s %s%%(AdditionalOptions)</AdditionalOptions>'
			, table.concat(premake.esc(buildoptions), " ")
			, iif(cfg.flags.UnsignedChar and cfg.platform ~= "TegraAndroid", unsignedChar, " ")
			)

		if cfg.platform == "TegraAndroid" then
			_p(3,'<SignedChar>%s</SignedChar>', tostring(cfg.flags.UnsignedChar == nil))
			_p(3,'<GenerateDebugInformation>%s</GenerateDebugInformation>', tostring(cfg.flags.Symbols ~= nil))
			if cfg.androidcppstandard then
				_p(3,'<CppLanguageStandard>%s</CppLanguageStandard>', cfg.androidcppstandard)
			end
		end

		if cfg.platform == "Orbis" then
			local opt = optimisation(cfg)
			if opt == "Disabled" then
				_p(3,'<OptimizationLevel>Level0</OptimizationLevel>')
			elseif opt == "MinSpace" then
				_p(3,'<OptimizationLevel>Levelz</OptimizationLevel>') -- Oz is more aggressive than Os
			elseif opt == "MaxSpeed" then
				_p(3,'<OptimizationLevel>Level3</OptimizationLevel>')
			else
				_p(3,'<OptimizationLevel>Level2</OptimizationLevel>')
			end
		elseif cfg.platform == "TegraAndroid" then
			local opt = optimisation(cfg)
			if opt == "Disabled" then
				_p(3,'<OptimizationLevel>O0</OptimizationLevel>')
			elseif opt == "MinSpace" then
				_p(3,'<OptimizationLevel>Os</OptimizationLevel>')
			elseif opt == "MaxSpeed" then
				_p(3,'<OptimizationLevel>O3</OptimizationLevel>')
			else
				_p(3,'<OptimizationLevel>O2</OptimizationLevel>')
			end
		else
			_p(3,'<Optimization>%s</Optimization>', optimisation(cfg))
		end

		include_dirs(3, cfg)
		using_dirs(3, cfg)
		preprocessor(3, cfg)
		minimal_build(cfg)

		if premake.config.isoptimizedbuild(cfg.flags) then
			-- Edit and continue is unstable with release/optimized projects. If the current project
			-- is optimized, but linker optimizations are disabled and has opted out of edit and continue
			-- support, then ensure that function level linking is disabled. This ensures that libs that
			-- do have edit and continue enabled don't run into undefined behavior at runtime when linking
			-- in optimized libs.
			if cfg.flags.NoOptimizeLink and cfg.flags.NoEditAndContinue then
				_p(3, '<StringPooling>false</StringPooling>')
				_p(3, '<FunctionLevelLinking>false</FunctionLevelLinking>')
			else
				_p(3, '<StringPooling>true</StringPooling>')
				_p(3, '<FunctionLevelLinking>true</FunctionLevelLinking>')
			end
		else
			_p(3, '<FunctionLevelLinking>true</FunctionLevelLinking>')
			if cfg.flags.NoRuntimeChecks then
				_p(3, '<BasicRuntimeChecks>Default</BasicRuntimeChecks>')
			elseif not cfg.flags.Managed then
				_p(3, '<BasicRuntimeChecks>EnableFastChecks</BasicRuntimeChecks>')
			end

			if cfg.flags.ExtraWarnings then
--				_p(3, '<SmallerTypeCheck>true</SmallerTypeCheck>')
			end
		end

		if cfg.platform == "Durango" or cfg.flags.NoWinRT then
			_p(3, '<CompileAsWinRT>false</CompileAsWinRT>')
		end

		_p(3, '<RuntimeLibrary>%s</RuntimeLibrary>', runtime(cfg))

		if cfg.flags.NoBufferSecurityCheck then
			_p(3, '<BufferSecurityCheck>false</BufferSecurityCheck>')
		end



		-- If we aren't running NoMultiprocessorCompilation and not wanting a minimal rebuild,
		-- then enable MultiProcessorCompilation.
		if not cfg.flags.NoMultiProcessorCompilation and not cfg.flags.EnableMinimalRebuild then
			_p(3, '<MultiProcessorCompilation>true</MultiProcessorCompilation>')
		else
			_p(3, '<MultiProcessorCompilation>false</MultiProcessorCompilation>')
		end

		precompiled_header(cfg)

		if cfg.platform == "Orbis" then
			if cfg.flags.PedanticWarnings then
				_p(3, '<Warnings>MoreWarnings</Warnings>')
				_p(3, '<ExtraWarnings>true</ExtraWarnings>')
			elseif cfg.flags.ExtraWarnings then
				_p(3, '<Warnings>NormalWarnings</Warnings>')
				_p(3, '<ExtraWarnings>true</ExtraWarnings>')
			elseif cfg.flags.MinimumWarnings then
				_p(3, '<Warnings>WarningsOff</Warnings>')
				_p(3, '<ExtraWarnings>false</ExtraWarnings>')
			else
				_p(3, '<Warnings>NormalWarnings</Warnings>')
				_p(3, '<ExtraWarnings>false</ExtraWarnings>')
			end
			if cfg.flags.FatalWarnings then
				_p(3, '<WarningsAsErrors>true</WarningsAsErrors>')
			end
		elseif cfg.platform == "TegraAndroid" then
			if cfg.flags.PedanticWarnings or cfg.flags.ExtraWarnings then
				_p(3, '<Warnings>AllWarnings</Warnings>')
			elseif cfg.flags.MinimumWarnings then
				_p(3, '<Warnings>DisableAllWarnings</Warnings>')
			else
				_p(3, '<Warnings>NormalWarnings</Warnings>')
			end
			if cfg.flags.FatalWarnings then
				_p(3, '<WarningsAsErrors>true</WarningsAsErrors>')
			end
		else
			if cfg.flags.PedanticWarnings then
				_p(3, '<WarningLevel>EnableAllWarnings</WarningLevel>')
			elseif cfg.flags.ExtraWarnings then
				_p(3, '<WarningLevel>Level4</WarningLevel>')
			elseif cfg.flags.MinimumWarnings then
				_p(3, '<WarningLevel>Level1</WarningLevel>')
			else
				_p(3 ,'<WarningLevel>Level3</WarningLevel>')
			end
		end

		if cfg.flags.FatalWarnings then
			_p(3, '<TreatWarningAsError>true</TreatWarningAsError>')
		end

		if premake.action.current() == premake.action.get("vs2017") or
		   premake.action.current() == premake.action.get("vs2019") then
			cppstandard_vs2017_or_2019(cfg)
		end

		exceptions(cfg)
		rtti(cfg)
		calling_convention(cfg)
		wchar_t_builtin(cfg)
		sse(cfg)
		floating_point(cfg)
		debug_info(cfg)

		if _ACTION:sub(3) == "llvm" then
			_p(3,'<SupportJustMyCode>false</SupportJustMyCode>')
		end

		if cfg.flags.Symbols then
			-- The compiler pdb should be different than the linker pdb, and
			-- the linker pdb is what should be distributed and used for
			-- debugging. But in the case of static libraries, they have no
			-- linker pdb, so then the compiler pdb should be in the output
			-- dir instead...
			if cfg.kind == "StaticLib" then
				_p(3, '<ProgramDataBaseFileName>$(OutDir)%s.pdb</ProgramDataBaseFileName>'
					, path.getbasename(cfg.buildtarget.name)
					)
			else
				_p(3, '<ProgramDataBaseFileName>$(IntDir)%s.compile.pdb</ProgramDataBaseFileName>'
					, path.getbasename(cfg.buildtarget.name)
					)
			end
		end

		if cfg.flags.Hotpatchable then
			_p(3, '<CreateHotpatchableImage>true</CreateHotpatchableImage>')
		end

		if cfg.flags.NoFramePointer then
			_p(3, '<OmitFramePointers>true</OmitFramePointers>')
		end

		if cfg.flags.UseFullPaths then
			_p(3, '<UseFullPaths>true</UseFullPaths>')
		end

		if cfg.flags.NoJMC then
			_p(3,'<SupportJustMyCode>false</SupportJustMyCode>' )
		end

		compile_language(cfg)

		forcedinclude_files(3,cfg);

		if vstudio.diagformat then
			_p(3, '<DiagnosticsFormat>%s</DiagnosticsFormat>', vstudio.diagformat)
		else
			_p(3, '<DiagnosticsFormat>Caret</DiagnosticsFormat>')
		end

		_p(2,'</ClCompile>')
	end


	local function event_hooks(cfg)
		if #cfg.postbuildcommands> 0 then
		    _p(2,'<PostBuildEvent>')
				_p(3,'<Command>%s</Command>',premake.esc(table.implode(cfg.postbuildcommands, "", "", "\r\n")))
			_p(2,'</PostBuildEvent>')
		end

		if #cfg.prebuildcommands> 0 then
		    _p(2,'<PreBuildEvent>')
				_p(3,'<Command>%s</Command>',premake.esc(table.implode(cfg.prebuildcommands, "", "", "\r\n")))
			_p(2,'</PreBuildEvent>')
		end

		if #cfg.prelinkcommands> 0 then
		    _p(2,'<PreLinkEvent>')
				_p(3,'<Command>%s</Command>',premake.esc(table.implode(cfg.prelinkcommands, "", "", "\r\n")))
			_p(2,'</PreLinkEvent>')
		end
	end

	local function additional_options(indent,cfg)
		if #cfg.linkoptions > 0 then
				_p(indent,'<AdditionalOptions>%s %%(AdditionalOptions)</AdditionalOptions>',
					table.concat(premake.esc(cfg.linkoptions), " "))
		end
	end

	local function link_target_machine(index,cfg)
		local platforms = {x32 = 'MachineX86', x64 = 'MachineX64'}
		if platforms[cfg.platform] then
			_p(index,'<TargetMachine>%s</TargetMachine>', platforms[cfg.platform])
		end
	end

	local function item_def_lib(prj, cfg)
		-- The Xbox360 project files are stored in another place in the project file.
		if cfg.kind == 'StaticLib' and cfg.platform ~= "Xbox360" then
			_p(1,'<Lib>')
				_p(2,'<OutputFile>$(OutDir)%s</OutputFile>',cfg.buildtarget.name)
				additional_options(2,cfg)
				link_target_machine(2,cfg)
				if _ACTION:sub(3) == "llvm" and prj.name == "portaudio" then -- MSVC-LLVM needs special help
					_p(2,'<AdditionalDependencies>ksuser.lib;%%(AdditionalDependencies)</AdditionalDependencies>')
				end
			_p(1,'</Lib>')
		end
	end

	local function import_lib(cfg)
		--Prevent the generation of an import library for a Windows DLL.
		if cfg.kind == "SharedLib" then
			local implibname = cfg.linktarget.fullpath
			_p(3,'<ImportLibrary>%s</ImportLibrary>',iif(cfg.flags.NoImportLib, cfg.objectsdir .. "\\" .. path.getname(implibname), implibname))
		end
	end

	local function hasmasmfiles(prj)
		local files = vc2010.getfilegroup(prj, "MASM")
		return #files > 0
	end

	local function ismanagedprj(prj, cfgname, pltname)
		local cfg = premake.getconfig(prj, cfgname, pltname)
		return cfg.flags.Managed == true
	end

	local function getcfglinks(cfg)
		local haswholearchive = #cfg.wholearchive > 0
		local msvcnaming 	  = premake.getnamestyle(cfg) == "windows"
		local iscppprj   	  = premake.iscppproject(cfg)
		local isnetprj   	  = premake.isdotnetproject(cfg)
		local linkobjs   	  = {}
		local links      	  = iif(haswholearchive
			, premake.getlinks(cfg, "all", "object")
			, premake.getlinks(cfg, "system", "fullpath")
			)

		for _, link in ipairs(links) do
			local name      = nil
			local directory = nil
			local whole     = nil

			if type(link) == "table" then
				-- if the link is to a managed project, we should ignore it
				-- as managed projects don't have lib files.
				if not ismanagedprj(link.project, cfg.name, cfg.platform) then
					-- project config
					name      = link.linktarget.basename
					directory = path.rebase(link.linktarget.directory, link.location, cfg.location)
					whole     = table.icontains(cfg.wholearchive, link.project.name)
				end
			else
				-- link name
				name      = link
				whole     = table.icontains(cfg.wholearchive, link)
			end

			if name then
				-- If we called premake.getlinks with "object", we need to
				-- re-add the file extensions since it didn't do it for us.
				if haswholearchive and msvcnaming then
					if iscppprj then
						name = name .. ".lib"
					elseif isnetprj then
						name = name .. ".dll"
					end
				end

				table.insert(linkobjs, {name=name, directory=directory, wholearchive=whole})
			end
		end

		return linkobjs
	end

	local function vs10_masm(prj, cfg)
		if hasmasmfiles(prj) then
			_p(2, '<MASM>')

			_p(3,'<AdditionalOptions>%s %%(AdditionalOptions)</AdditionalOptions>'
				, table.concat(premake.esc(table.join(cfg.buildoptions, cfg.buildoptions_asm)), " ")
				)

			local includedirs = table.join(cfg.userincludedirs, cfg.includedirs, cfg.systemincludedirs)

			if #includedirs > 0 then
				_p(3, '<IncludePaths>%s;%%(IncludePaths)</IncludePaths>'
					, premake.esc(path.translate(table.concat(includedirs, ";"), '\\'))
					)
			end

			-- table.join is used to create a copy rather than a reference
			local defines = table.join(cfg.defines)

			-- pre-defined preprocessor defines:
			-- _DEBUG:  For debug configurations
			-- _WIN32:  For 32-bit platforms
			-- _WIN64:  For 64-bit platforms
			-- _EXPORT: `EXPORT` for shared libraries, empty for other project kinds
			table.insertflat(defines, iif(premake.config.isdebugbuild(cfg), "_DEBUG", {}))
			table.insert(defines, iif(cfg.platform == "x64", "_WIN64", "_WIN32"))
			table.insert(defines, iif(prj.kind == "SharedLib", "_EXPORT=EXPORT", "_EXPORT="))

			_p(3, '<PreprocessorDefinitions>%s;%%(PreprocessorDefinitions)</PreprocessorDefinitions>'
				, premake.esc(table.concat(defines, ";"))
				)

			if cfg.flags.FatalWarnings then
				_p(3,'<TreatWarningsAsErrors>true</TreatWarningsAsErrors>')
			end

			-- MASM only has 3 warning levels where 3 is default, so we can ignore `ExtraWarnings`
			if cfg.flags.MinimumWarnings then
				_p(3,'<WarningLevel>0</WarningLevel>')
			else
				_p(3,'<WarningLevel>3</WarningLevel>')
			end

			_p(2, '</MASM>')
		end
	end

	local function additional_manifest(cfg)
		if(cfg.dpiawareness ~= nil) then
			_p(2,'<Manifest>')
				if(cfg.dpiawareness == "None") then
					_p(3, '<EnableDpiAwareness>false</EnableDpiAwareness>')
				end
				if(cfg.dpiawareness == "High") then
					_p(3, '<EnableDpiAwareness>true</EnableDpiAwareness>')
				end
				if(cfg.dpiawareness == "HighPerMonitor") then
					_p(3, '<EnableDpiAwareness>PerMonitorHighDPIAware</EnableDpiAwareness>')
				end
			_p(2,'</Manifest>')
		end
	end

--
-- Generate the <Link> element and its children.
--

	function vc2010.link(cfg)
		local vs2017OrLater = premake.action.current() == premake.action.get("vs2017") or
		    premake.action.current() == premake.action.get("vs2019")
		local vsllvm = premake.action.current() == premake.action.get("vsllvm")
		local links  = getcfglinks(cfg)

		_p(2,'<Link>')
		_p(3,'<SubSystem>%s</SubSystem>', iif(cfg.kind == "ConsoleApp", "Console", "Windows"))
		if (vs2017OrLater or vsllvm) and cfg.flags.FullSymbols then
			_p(3,'<GenerateDebugInformation>DebugFull</GenerateDebugInformation>')
		else
			_p(3,'<GenerateDebugInformation>%s</GenerateDebugInformation>', tostring(cfg.flags.Symbols ~= nil))
		end

		if cfg.flags.Symbols then
			_p(3, '<ProgramDatabaseFile>$(OutDir)%s.pdb</ProgramDatabaseFile>'
				, path.getbasename(cfg.buildtarget.name)
				)
		end

		if premake.config.islinkeroptimizedbuild(cfg.flags) then
			if cfg.platform == "Orbis" then
				_p(3,'<DataStripping>StripFuncsAndData</DataStripping>')
				_p(3,'<DuplicateStripping>true</DuplicateStripping>')
			else
				_p(3,'<EnableCOMDATFolding>true</EnableCOMDATFolding>')
				_p(3,'<OptimizeReferences>true</OptimizeReferences>')
			end
		elseif cfg.platform == "Orbis" and premake.config.iseditandcontinue(cfg) then
			_p(3,'<EditAndContinue>true</EditAndContinue>')
		end

		if cfg.finalizemetasource ~= nil then
			_p(3,'<FinalizeMetaSource>%s</FinalizeMetaSource>', premake.esc(cfg.finalizemetasource))
		end

		if cfg.kind ~= 'StaticLib' then
			vc2010.additionalDependencies(3, cfg, links)
			vc2010.additionalLibraryDirectories(3, cfg, links)
			_p(3,'<OutputFile>$(OutDir)%s</OutputFile>', cfg.buildtarget.name)

			if vc2010.config_type(cfg) == 'Application' and not cfg.flags.WinMain and not cfg.flags.Managed then
				if cfg.flags.Unicode then
					_p(3,'<EntryPointSymbol>wmainCRTStartup</EntryPointSymbol>')
				else
					_p(3,'<EntryPointSymbol>mainCRTStartup</EntryPointSymbol>')
				end
			end

			import_lib(cfg)

			local deffile = premake.findfile(cfg, ".def")
			if deffile then
				_p(3,'<ModuleDefinitionFile>%s</ModuleDefinitionFile>', deffile)
			end

			link_target_machine(3,cfg)
			additional_options(3,cfg)

			if cfg.flags.NoWinMD and vstudio.iswinrt() and prj.kind == "WindowedApp" then
				_p(3,'<GenerateWindowsMetadata>false</GenerateWindowsMetadata>' )
			end
		end

		if cfg.platform == "TegraAndroid" then
			if cfg.androidlinker then
				_p(3,'<UseLinker>%s</UseLinker>',cfg.androidlinker)
			end
		end

		if cfg.flags.Hotpatchable then
			_p(3, '<CreateHotPatchableImage>Enabled</CreateHotPatchableImage>')
		end

		_p(2,'</Link>')

		-- If any libraries are to be linked as whole archive, we need to
		-- handle the linking manually, since there is no project configuration
		-- option for that.
		if #cfg.wholearchive > 0 then
			_p(2, '<ProjectReference>')
			_p(3, '<LinkLibraryDependencies>false</LinkLibraryDependencies>')
			_p(2, '</ProjectReference>')
		end
	end


	function vc2010.additionalLibraryDirectories(tab, cfg, links)
		local dirs = cfg.libdirs

		for _, link in ipairs(links) do
			if link.directory and not table.icontains(dirs, link.directory) then
				table.insert(dirs, link.directory)
			end
		end

		_p(tab, '<AdditionalLibraryDirectories>%s;%%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>'
			, premake.esc(path.translate(table.concat(dirs, ';'), '\\'))
			)
	end

--
-- Generate the <Link/AdditionalDependencies> element, which links in system
-- libraries required by the project (but not sibling projects; that's handled
-- by an <ItemGroup/ProjectReference>).
--

	function vc2010.additionalDependencies(tab, cfg, links)
		if #links > 0 then
			local deps = ""

			if cfg.platform == "Orbis" then
				local iswhole = false
				for _, link in ipairs(links) do
					if link.wholearchive and not iswhole then
						deps = deps .. "--whole-archive;"
						iswhole = true
					elseif not link.wholearchive and iswhole then
						deps = deps .. "--no-whole-archive;"
						iswhole = false
					end

					deps = deps .. "-l" .. link.name .. ";"
				end
			else
				for _, link in ipairs(links) do
					if link.wholearchive then
						deps = deps .. "/WHOLEARCHIVE:" .. link.name .. ";"
					else
						deps = deps .. link.name .. ";"
					end
				end
			end

			-- On Android, we need to shove a linking group in to resolve libs
			-- with circular deps.
			if cfg.platform == "TegraAndroid" then
				deps = "-Wl,--start-group;" .. deps .. ";-Wl,--end-group"
			end

			_p(tab, '<AdditionalDependencies>%s;%s</AdditionalDependencies>'
				, deps
				, iif(cfg.platform == "Durango"
					, '%(XboxExtensionsDependencies)'
					, '%(AdditionalDependencies)'
					)
				)
		elseif cfg.platform == "Durango" then
			_p(tab, '<AdditionalDependencies>%%(XboxExtensionsDependencies)</AdditionalDependencies>')
		end
	end

--
-- Generate the <AntBuild> element and its children.
--

	function ant_build(prj, cfg)
		-- only include this bit for Tegra
		if cfg.platform == "TegraAndroid" then
			local files = vc2010.getfilegroup(prj, "AndroidBuild")
			_p(2,'<AntBuild>')
			if #files > 0 then
				_p(3,'<AndroidManifestLocation>%s</AndroidManifestLocation>',path.translate(files[1].name))
			end
			local isdebugbuild = premake.config.isdebugbuild(cfg)
			_p(3,'<AntBuildType>%s</AntBuildType>',iif(isdebugbuild, 'Debug','Release'))
			_p(3,'<Debuggable>%s</Debuggable>',tostring(cfg.flags.AntBuildDebuggable ~= nil))
			if #cfg.antbuildjavasourcedirs > 0 then
				local dirs = table.concat(cfg.antbuildjavasourcedirs,";")
				_p(3,'<JavaSourceDir>%s</JavaSourceDir>',dirs)
			end
			if #cfg.antbuildjardirs > 0 then
				local dirs = table.concat(cfg.antbuildjardirs,";")
				_p(3,'<JarDirectories>%s</JarDirectories>',dirs)
			end
			if #cfg.antbuildjardependencies > 0 then
				local dirs = table.concat(cfg.antbuildjardependencies,";")
				_p(3,'<JarDependencies>%s</JarDependencies>',dirs)
			end
			if #cfg.antbuildnativelibdirs > 0 then
				local dirs = table.concat(cfg.antbuildnativelibdirs,";")
				_p(3,'<NativeLibDirectories>%s</NativeLibDirectories>',dirs)
			end
			if #cfg.antbuildnativelibdependencies > 0 then
				local dirs = table.concat(cfg.antbuildnativelibdependencies,";")
				_p(3,'<NativeLibDependencies>%s</NativeLibDependencies>',dirs)
			end
			if #cfg.antbuildassetsdirs > 0 then
				local dirs = table.concat(cfg.antbuildassetsdirs,";")
				_p(3,'<AssetsDirectories>%s</AssetsDirectories>',dirs)
			end
			_p(2,'</AntBuild>')
		end
	end


	local function item_definitions(prj)
		for _, cfginfo in ipairs(prj.solution.vstudio_configs) do
			local cfg = premake.getconfig(prj, cfginfo.src_buildcfg, cfginfo.src_platform)
			_p(1,'<ItemDefinitionGroup ' ..if_config_and_platform() ..'>'
					,premake.esc(cfginfo.name))
				vs10_clcompile(cfg)
				resource_compile(cfg)
				item_def_lib(prj, cfg)
				vc2010.link(cfg)
				ant_build(prj, cfg)
				event_hooks(cfg)
				vs10_masm(prj, cfg)
				additional_manifest(cfg)
			_p(1,'</ItemDefinitionGroup>')
		end
	end


--
-- Retrieve a list of files for a particular build group, like
-- "ClInclude", "ClCompile", "ResourceCompile", "MASM", "None", etc.
--

	function vc2010.getfilegroup(prj, group)
		local sortedfiles = prj.vc2010sortedfiles
		if not sortedfiles then
			sortedfiles = {
				ClCompile = {},
				ClInclude = {},
				MASM = {},
				Object = {},
				None = {},
				ResourceCompile = {},
				AppxManifest = {},
				AndroidBuild = {},
				Natvis = {},
				Image = {},
				DeploymentContent = {}
			}

			local foundAppxManifest = false
			for file in premake.project.eachfile(prj, true) do
				if path.issourcefilevs(file.name) then
					table.insert(sortedfiles.ClCompile, file)
				elseif path.iscppheader(file.name) then
					if not table.icontains(prj.removefiles, file) then
						table.insert(sortedfiles.ClInclude, file)
					end
				elseif path.isobjectfile(file.name) then
					table.insert(sortedfiles.Object, file)
				elseif path.isresourcefile(file.name) then
					table.insert(sortedfiles.ResourceCompile, file)
				elseif path.isimagefile(file.name) then
					table.insert(sortedfiles.Image, file)
				elseif path.isappxmanifest(file.name) then
					foundAppxManifest = true
					table.insert(sortedfiles.AppxManifest, file)
				elseif path.isandroidbuildfile(file.name) then
					table.insert(sortedfiles.AndroidBuild, file)
				elseif path.isnatvis(file.name) then
					table.insert(sortedfiles.Natvis, file)
				elseif path.isasmfile(file.name) then
					table.insert(sortedfiles.MASM, file)
				elseif file.flags and table.icontains(file.flags, "DeploymentContent") then
					table.insert(sortedfiles.DeploymentContent, file)
				else
					table.insert(sortedfiles.None, file)
				end
			end

			-- WinRT projects get an auto-generated appxmanifest file if none is specified
			if vstudio.iswinrt() and prj.kind == "WindowedApp" and not foundAppxManifest then
				vstudio.needAppxManifest = true

				local fcfg = {}
				fcfg.name = prj.name .. "/Package.appxmanifest"
				fcfg.vpath = premake.project.getvpath(prj, fcfg.name)
				table.insert(sortedfiles.AppxManifest, fcfg)

				-- We also need a link to the splash screen because WinRT is retarded
				local logo = {}
				logo.name  = prj.name .. "/Logo.png"
				logo.vpath = logo.name
				table.insert(sortedfiles.Image, logo)

				local smallLogo = {}
				smallLogo.name  = prj.name .. "/SmallLogo.png"
				smallLogo.vpath = smallLogo.name
				table.insert(sortedfiles.Image, smallLogo)

				local storeLogo = {}
				storeLogo.name  = prj.name .. "/StoreLogo.png"
				storeLogo.vpath = storeLogo.name
				table.insert(sortedfiles.Image, storeLogo)

				local splashScreen = {}
				splashScreen.name  = prj.name .. "/SplashScreen.png"
				splashScreen.vpath = splashScreen.name
				table.insert(sortedfiles.Image, splashScreen)
			end

			-- Cache the sorted files; they are used several places
			prj.vc2010sortedfiles = sortedfiles
		end

		return sortedfiles[group]
	end


--
-- Write the files section of the project file.
--

	function vc2010.files(prj)
		vc2010.simplefilesgroup(prj, "ClInclude")
		vc2010.compilerfilesgroup(prj)
		vc2010.simplefilesgroup(prj, "Object")
		vc2010.simplefilesgroup(prj, "None")
		vc2010.customtaskgroup(prj)
		vc2010.simplefilesgroup(prj, "ResourceCompile")
		vc2010.simplefilesgroup(prj, "AppxManifest")
		vc2010.simplefilesgroup(prj, "AndroidBuild")
		vc2010.simplefilesgroup(prj, "Natvis")
		vc2010.deploymentcontentgroup(prj, "Image")
		vc2010.deploymentcontentgroup(prj, "DeploymentContent", "None")
	end

	function vc2010.customtaskgroup(prj)
		local files = { }
		for _, custombuildtask in ipairs(prj.custombuildtask or {}) do
			for _, buildtask in ipairs(custombuildtask or {}) do
				local fcfg = { }
				fcfg.name = path.getrelative(prj.location,buildtask[1])
				fcfg.vpath = path.trimdots(fcfg.name)
				table.insert(files, fcfg)
			end
		end
		if #files > 0  then
			_p(1,'<ItemGroup>')
			local groupedBuildTasks = {}
			local buildTaskNames = {}

			for _, custombuildtask in ipairs(prj.custombuildtask or {}) do
				for _, buildtask in ipairs(custombuildtask or {}) do
					if (groupedBuildTasks[buildtask[1]] == nil) then
						groupedBuildTasks[buildtask[1]] = {}
						table.insert(buildTaskNames, buildtask[1])
					end
					table.insert(groupedBuildTasks[buildtask[1]], buildtask)
				end
			end

			for _, name in ipairs(buildTaskNames) do
				custombuildtask = groupedBuildTasks[name]
				_p(2,'<CustomBuild Include=\"%s\">', path.translate(path.getrelative(prj.location,name), "\\"))
				_p(3,'<FileType>Text</FileType>')
				local cmd = ""
				local outputs = ""
				for _, buildtask in ipairs(custombuildtask or {}) do
					for _, cmdline in ipairs(buildtask[4] or {}) do
						cmd = cmd .. cmdline
						local num = 1
						for _, depdata in ipairs(buildtask[3] or {}) do
							cmd = string.gsub(cmd,"%$%(" .. num .."%)", string.format("%s ",path.getrelative(prj.location,depdata)))
							num = num + 1
						end
						cmd = string.gsub(cmd, "%$%(<%)", string.format("%s ",path.getrelative(prj.location,buildtask[1])))
						cmd = string.gsub(cmd, "%$%(@%)", string.format("%s ",path.getrelative(prj.location,buildtask[2])))
						cmd = cmd .. "\r\n"
					end
					outputs = outputs .. path.getrelative(prj.location,buildtask[2]) .. ";"
				end
				_p(3,'<Command>%s</Command>',cmd)
				_p(3,'<Outputs>%s%%(Outputs)</Outputs>',outputs)
				_p(3,'<SubType>Designer</SubType>')
				_p(3,'<Message></Message>')
				_p(2,'</CustomBuild>')
			end
			_p(1,'</ItemGroup>')
		end
	end

	function vc2010.simplefilesgroup(prj, section, subtype)
		local configs = prj.solution.vstudio_configs
		local files = vc2010.getfilegroup(prj, section)

		if #files > 0  then
			local config_mappings = {}

			for _, cfginfo in ipairs(configs) do
				local cfg = premake.getconfig(prj, cfginfo.src_buildcfg, cfginfo.src_platform)
				if cfg.pchheader and cfg.pchsource and not cfg.flags.NoPCH then
					config_mappings[cfginfo] = path.translate(cfg.pchsource, "\\")
				end
			end

			_p(1,'<ItemGroup>')

			for _, file in ipairs(files) do
				local prjexcluded = table.icontains(prj.excludes, file.name)
				local excludedcfgs = {}

				if not prjexcluded then
					for _, vsconfig in ipairs(configs) do
						local cfg = premake.getconfig(prj, vsconfig.src_buildcfg, vsconfig.src_platform)
						local fileincfg = table.icontains(cfg.files, file.name)
						local cfgexcluded = table.icontains(cfg.excludes, file.name)

						if not fileincfg or cfgexcluded then
							table.insert(excludedcfgs, vsconfig.name)
						end
					end
				end

				if subtype or prjexcluded or #excludedcfgs > 0 then
					_p(2, '<%s Include=\"%s\">', section, path.translate(file.name, "\\"))

					if prjexcluded then
						_p(3, '<ExcludedFromBuild>true</ExcludedFromBuild>')
					else
						for _, cfgname in ipairs(excludedcfgs) do
							_p(3, '<ExcludedFromBuild '
								.. if_config_and_platform()
								.. '>true</ExcludedFromBuild>'
								, premake.esc(cfgname)
								)
						end
					end

					if subtype then
						_p(3, '<SubType>%s</SubType>', subtype)
					end

					_p(2,'</%s>', section)
				else
					_p(2, '<%s Include=\"%s\" />', section, path.translate(file.name, "\\"))
				end
			end

			_p(1,'</ItemGroup>')
		end
	end

	function vc2010.deploymentcontentgroup(prj, section, filetype)
		if filetype == nil then
			filetype = section
		end

		local files = vc2010.getfilegroup(prj, section)
		if #files > 0  then
			_p(1,'<ItemGroup>')
			for _, file in ipairs(files) do
				_p(2,'<%s Include=\"%s\">', filetype, path.translate(file.name, "\\"))

				_p(3,'<DeploymentContent>true</DeploymentContent>')
				_p(3,'<Link>%s</Link>', path.translate(file.vpath, "\\"))
				_p(2,'</%s>', filetype)
			end
			_p(1,'</ItemGroup>')
		end
	end

	function vc2010.compilerfilesgroup(prj)
		local configs = prj.solution.vstudio_configs
		local files = vc2010.getfilegroup(prj, "ClCompile")
		if #files > 0  then
			local config_mappings = {}
			for _, cfginfo in ipairs(configs) do
				local cfg = premake.getconfig(prj, cfginfo.src_buildcfg, cfginfo.src_platform)
				if cfg.pchheader and cfg.pchsource and not cfg.flags.NoPCH then
					config_mappings[cfginfo] = path.translate(cfg.pchsource, "\\")
				end
			end

			_p(1,'<ItemGroup>')
			local existingBasenames = {};
			for _, file in ipairs(files) do
				-- Having unique ObjectFileName for each file subverts MSBuilds ability to parallelize compilation with the /MP flag.
				-- Instead we detect duplicates and partition them in subfolders only if needed.
				local filename = string.lower(path.getbasename(file.name))
				local disambiguation = existingBasenames[filename] or 0;
				existingBasenames[filename] = disambiguation + 1

				local translatedpath = path.translate(file.name, "\\")
				_p(2, '<ClCompile Include=\"%s\">', translatedpath)

				for _, vsconfig in ipairs(configs) do
					-- Android and NX need a full path to an object file, not a dir.
					local cfg = premake.getconfig(prj, vsconfig.src_buildcfg, vsconfig.src_platform)
					local namestyle = premake.getnamestyle(cfg)
					if namestyle == "TegraAndroid" or namestyle == "NX" then
						_p(3, '<ObjectFileName '.. if_config_and_platform() .. '>$(IntDir)%s.o</ObjectFileName>', premake.esc(vsconfig.name), premake.esc(path.translate(path.trimdots(path.removeext(file.name)))) )
					else
						if disambiguation > 0 then
							_p(3, '<ObjectFileName '.. if_config_and_platform() .. '>$(IntDir)%s\\</ObjectFileName>', premake.esc(vsconfig.name), tostring(disambiguation))
						end
					end
				end

				if path.iscxfile(file.name) then
					_p(3, '<CompileAsWinRT>true</CompileAsWinRT>')
					_p(3, '<RuntimeTypeInfo>true</RuntimeTypeInfo>')
					_p(3, '<PrecompiledHeader>NotUsing</PrecompiledHeader>')
				end

				--For Windows Store Builds, if the file is .c we have to exclude it from /ZW compilation
				if vstudio.iswinrt() and string.len(file.name) > 2 and string.sub(file.name, -2) == ".c" then
					_p(3,'<CompileAsWinRT>FALSE</CompileAsWinRT>')
				end

				for _, cfginfo in ipairs(configs) do
					if config_mappings[cfginfo] and translatedpath == config_mappings[cfginfo] then
						_p(3,'<PrecompiledHeader '.. if_config_and_platform() .. '>Create</PrecompiledHeader>', premake.esc(cfginfo.name))
						config_mappings[cfginfo] = nil  --only one source file per pch
					end
				end

				local nopch = table.icontains(prj.nopch, file.name)
				for _, vsconfig in ipairs(configs) do
					local cfg = premake.getconfig(prj, vsconfig.src_buildcfg, vsconfig.src_platform)
					if nopch or table.icontains(cfg.nopch, file.name) then
						_p(3,'<PrecompiledHeader '.. if_config_and_platform() .. '>NotUsing</PrecompiledHeader>', premake.esc(vsconfig.name))
					end
				end

				local excluded = table.icontains(prj.excludes, file.name)
				for _, vsconfig in ipairs(configs) do
					local cfg = premake.getconfig(prj, vsconfig.src_buildcfg, vsconfig.src_platform)
					local fileincfg = table.icontains(cfg.files, file.name)
					local cfgexcluded = table.icontains(cfg.excludes, file.name)

					if excluded or not fileincfg or cfgexcluded then
						_p(3, '<ExcludedFromBuild '
							.. if_config_and_platform()
							.. '>true</ExcludedFromBuild>'
							, premake.esc(vsconfig.name)
							)
					end
				end

				if prj.flags and prj.flags.Managed then
					local prjforcenative = table.icontains(prj.forcenative, file.name)
					for _,vsconfig in ipairs(configs) do
						local cfg = premake.getconfig(prj, vsconfig.src_buildcfg, vsconfig.src_platform)
						if prjforcenative or table.icontains(cfg.forcenative, file.name) then
							_p(3, '<CompileAsManaged ' .. if_config_and_platform() .. '>false</CompileAsManaged>', premake.esc(vsconfig.name))
						end
					end
				end

				_p(2,'</ClCompile>')
			end
			_p(1,'</ItemGroup>')
		end
	end

	function vc2010.masmfiles(prj)
		local configs = prj.solution.vstudio_configs
		local files = vc2010.getfilegroup(prj, "MASM")
		if #files > 0 then
			_p(1, '<ItemGroup>')
			for _, file in ipairs(files) do
				local translatedpath = path.translate(file.name, "\\")
				_p(2, '<MASM Include="%s">', translatedpath)

				local excluded = table.icontains(prj.excludes, file.name)
				for _, vsconfig in ipairs(configs) do
					local cfg = premake.getconfig(prj, vsconfig.src_buildcfg, vsconfig.src_platform)
					local fileincfg = table.icontains(cfg.files, file.name)
					local cfgexcluded = table.icontains(cfg.excludes, file.name)

					if excluded or not fileincfg or cfgexcluded then
						_p(3, '<ExcludedFromBuild '
							.. if_config_and_platform()
							.. '>true</ExcludedFromBuild>'
							, premake.esc(vsconfig.name)
							)
					end
				end

				_p(2, '</MASM>')
			end
			_p(1, '</ItemGroup>')
		end
	end


--
-- Output the VC2010 project file header
--

	function vc2010.header(targets)
		io.eol = "\r\n"
		_p('<?xml version="1.0" encoding="utf-8"?>')

		local t = ""
		if targets then
			t = ' DefaultTargets="' .. targets .. '"'
		end

		_p('<Project%s ToolsVersion="%s" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">', t, action.vstudio.toolsVersion)
	end


--
-- Output the VC2010 C/C++ project file
--

	function premake.vs2010_vcxproj(prj)
		local usemasm = hasmasmfiles(prj)

		io.indent = "  "
		vc2010.header("Build")

			vs2010_config(prj)
			vs2010_globals(prj)

			_p(1,'<Import Project="$(VCTargetsPath)\\Microsoft.Cpp.Default.props" />')

			for _, cfginfo in ipairs(prj.solution.vstudio_configs) do
				local cfg = premake.getconfig(prj, cfginfo.src_buildcfg, cfginfo.src_platform)
				vc2010.configurationPropertyGroup(cfg, cfginfo)
			end

			_p(1,'<Import Project="$(VCTargetsPath)\\Microsoft.Cpp.props" />')

			_p(1,'<ImportGroup Label="ExtensionSettings">')
			if usemasm then
				_p(2, '<Import Project="$(VCTargetsPath)\\BuildCustomizations\\masm.props" />')
			end
			_p(1,'</ImportGroup>')

			import_props(prj)

			--what type of macros are these?
			_p(1,'<PropertyGroup Label="UserMacros" />')

			vc2010.outputProperties(prj)

			item_definitions(prj)

			vc2010.files(prj)
			vc2010.clrReferences(prj)
			vc2010.projectReferences(prj)
			vc2010.sdkReferences(prj)
			vc2010.masmfiles(prj)

			_p(1,'<Import Project="$(VCTargetsPath)\\Microsoft.Cpp.targets" />')
			_p(1,'<ImportGroup Label="ExtensionTargets">')
			if usemasm then
				_p(2, '<Import Project="$(VCTargetsPath)\\BuildCustomizations\\masm.targets" />')
			end
			_p(1,'</ImportGroup>')

		_p('</Project>')
	end

--
-- Generate the list of CLR references
--
	function vc2010.clrReferences(prj)
		if #prj.clrreferences == 0 then
			return
		end

		_p(1,'<ItemGroup>')

		for _, ref in ipairs(prj.clrreferences) do
			if os.isfile(ref) then
				local assembly = path.getbasename(ref)
				_p(2,'<Reference Include="%s">', assembly)
				_p(3,'<HintPath>%s</HintPath>', path.getrelative(prj.location, ref))
				_p(2,'</Reference>')
			else
				_p(2,'<Reference Include="%s" />', ref)
			end
		end

		_p(1,'</ItemGroup>')
	end

--
-- Generate the list of project dependencies.
--

	function vc2010.projectReferences(prj)
		local deps = premake.getdependencies(prj)

		if #deps == 0 and #prj.vsimportreferences == 0 then
			return
		end

		-- Sort dependencies by uuid to keep the project files from changing
		-- unnecessarily.
		local function compareuuid(a, b) return a.uuid < b.uuid end
		table.sort(deps, compareuuid)
		table.sort(table.join(prj.vsimportreferences), compareuuid)

		_p(1,'<ItemGroup>')

		for _, dep in ipairs(deps) do
			local deppath = path.getrelative(prj.location, vstudio.projectfile(dep))
			_p(2,'<ProjectReference Include=\"%s\">', path.translate(deppath, "\\"))
			_p(3,'<Project>{%s}</Project>', dep.uuid)
			if vstudio.iswinrt() then
				_p(3,'<ReferenceOutputAssembly>false</ReferenceOutputAssembly>')
			end
			_p(2,'</ProjectReference>')
		end

		for _, ref in ipairs(prj.vsimportreferences) do
			-- Convert the path from being relative to the project to being
			-- relative to the solution, for lookup.
			local slnrelpath = path.rebase(ref, prj.location, sln.location)
			local iprj = premake.vstudio.getimportprj(slnrelpath, prj.solution)
			_p(2,'<ProjectReference Include=\"%s\">', ref)
			_p(3,'<Project>{%s}</Project>', iprj.uuid)
			_p(2,'</ProjectReference>')
		end

		_p(1,'</ItemGroup>')
	end

--
-- Generate the list of SDK references
--

	function vc2010.sdkReferences(prj)
		local refs = prj.sdkreferences
		if #refs > 0 then
			_p(1,'<ItemGroup>')
			for _, ref in ipairs(refs) do
				_p(2,'<SDKReference Include=\"%s\" />', ref)
			end
			_p(1,'</ItemGroup>')
		end
	end

--
-- Generate the .vcxproj.user file
--

	function vc2010.debugdir(cfg)
		local isnx = (cfg.platform == "NX32" or cfg.platform == "NX64")
		local debuggerFlavor =
			  iif(isnx,                           'OasisNXDebugger'
			, iif(cfg.platform == "Orbis",        'ORBISDebugger'
			, iif(cfg.platform == "Durango",      'XboxOneVCppDebugger'
			, iif(cfg.platform == "TegraAndroid", 'AndroidDebugger'
			, iif(vstudio.iswinrt(),              'AppHostLocalDebugger'
			,                                     'WindowsLocalDebugger'
			)))))
		_p(2, '<DebuggerFlavor>%s</DebuggerFlavor>', debuggerFlavor)

		if cfg.debugdir and not vstudio.iswinrt() then
			_p(2, '<LocalDebuggerWorkingDirectory>%s</LocalDebuggerWorkingDirectory>'
				, path.translate(cfg.debugdir, '\\')
				)
		end

		if cfg.debugcmd then
			_p(2, '<LocalDebuggerCommand>%s</LocalDebuggerCommand>', cfg.debugcmd)
		end

		if cfg.debugargs then
			_p(2, '<LocalDebuggerCommandArguments>%s</LocalDebuggerCommandArguments>'
				, table.concat(cfg.debugargs, " ")
				)
		end

		if cfg.debugenvs and #cfg.debugenvs > 0 then
			_p(2, '<LocalDebuggerEnvironment>%s%s</LocalDebuggerEnvironment>'
				, table.concat(cfg.debugenvs, "\n")
				, iif(cfg.flags.DebugEnvsInherit,'\n$(LocalDebuggerEnvironment)', '')
				)
			if cfg.flags.DebugEnvsDontMerge then
				_p(2, '<LocalDebuggerMergeEnvironment>false</LocalDebuggerMergeEnvironment>')
			end
		end

		if cfg.deploymode then
			_p(2, '<DeployMode>%s</DeployMode>', cfg.deploymode)
		end

		if cfg.platform == "TegraAndroid" then
			if cfg.androiddebugintentparams then
				_p(2, '<IntentParams>%s</IntentParams>'
					, table.concat(cfg.androiddebugintentparams, " ")
					)
			end
		end
	end

	function premake.vs2010_vcxproj_user(prj)
		io.indent = "  "
		vc2010.header()
		for _, cfginfo in ipairs(prj.solution.vstudio_configs) do
			local cfg = premake.getconfig(prj, cfginfo.src_buildcfg, cfginfo.src_platform)
			_p('  <PropertyGroup '.. if_config_and_platform() ..'>', premake.esc(cfginfo.name))
			vc2010.debugdir(cfg)
			_p('  </PropertyGroup>')
		end
		_p('</Project>')
	end

	local png1x1data = {
		0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a, 0x00, 0x00, 0x00, 0x0d, 0x49, 0x48, 0x44, 0x52, -- .PNG........IHDR
		0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, 0x01, 0x03, 0x00, 0x00, 0x00, 0x25, 0xdb, 0x56, -- .............%.V
		0xca, 0x00, 0x00, 0x00, 0x03, 0x50, 0x4c, 0x54, 0x45, 0x00, 0x00, 0x00, 0xa7, 0x7a, 0x3d, 0xda, -- .....PLTE....z=.
		0x00, 0x00, 0x00, 0x01, 0x74, 0x52, 0x4e, 0x53, 0x00, 0x40, 0xe6, 0xd8, 0x66, 0x00, 0x00, 0x00, -- ....tRNS.@..f...
		0x0a, 0x49, 0x44, 0x41, 0x54, 0x08, 0xd7, 0x63, 0x60, 0x00, 0x00, 0x00, 0x02, 0x00, 0x01, 0xe2, -- .IDAT..c`.......
		0x21, 0xbc, 0x33, 0x00, 0x00, 0x00, 0x00, 0x49, 0x45, 0x4e, 0x44, 0xae, 0x42, 0x60, 0x82,       -- !.3....IEND.B`.
	}

	function png1x1(obj, filename)
		filename = premake.project.getfilename(obj, filename)

		local f, err = io.open(filename, "wb")
		if f then
			for _, byte in ipairs(png1x1data) do
				f:write(string.char(byte))
			end
			f:close()
		end
	end

	function premake.vs2010_appxmanifest(prj)
		io.indent = "  "
		io.eol = "\r\n"
		_p('<?xml version="1.0" encoding="utf-8"?>')
		if vstudio.storeapp == "10.0" then
			_p('<Package')
			_p(1, 'xmlns="http://schemas.microsoft.com/appx/manifest/foundation/windows10"')
			_p(1, 'xmlns:mp="http://schemas.microsoft.com/appx/2014/phone/manifest"')
			_p(1, 'xmlns:uap="http://schemas.microsoft.com/appx/manifest/uap/windows10"')
			_p(1, 'IgnorableNamespaces="uap mp">')
		elseif vstudio.storeapp == "durango" then
			_p('<Package xmlns="http://schemas.microsoft.com/appx/2010/manifest" xmlns:mx="http://schemas.microsoft.com/appx/2013/xbox/manifest" IgnorableNamespaces="mx">')
		end

		_p(1, '<Identity')
		_p(2, 'Name="' .. prj.uuid .. '"')
		_p(2, 'Publisher="CN=Publisher"')
		_p(2, 'Version="1.0.0.0" />')

		if vstudio.storeapp == "10.0" then
			_p(1, '<mp:PhoneIdentity')
			_p(2, 'PhoneProductId="' .. prj.uuid .. '"')
			_p(2, 'PhonePublisherId="00000000-0000-0000-0000-000000000000"/>')
		end

		_p(1, '<Properties>')
		_p(2, '<DisplayName>' .. prj.name .. '</DisplayName>')
		_p(2, '<PublisherDisplayName>PublisherDisplayName</PublisherDisplayName>')
		_p(2, '<Logo>' .. prj.name .. '\\StoreLogo.png</Logo>')
		png1x1(prj, "%%/StoreLogo.png")
		_p(2, '<Description>' .. prj.name .. '</Description>')

		_p(1,'</Properties>')

		if vstudio.storeapp == "10.0" then
			_p(1, '<Dependencies>')
			_p(2, '<TargetDeviceFamily Name="Windows.Universal" MinVersion="10.0.10069.0" MaxVersionTested="10.0.10069.0" />')
			_p(1, '</Dependencies>')
		elseif vstudio.storeapp == "durango" then
			_p(1, '<Prerequisites>')
			_p(2, '<OSMinVersion>6.2</OSMinVersion>')
			_p(2, '<OSMaxVersionTested>6.2</OSMaxVersionTested>')
			_p(1, '</Prerequisites>')
		end

		_p(1, '<Resources>')
		_p(2, '<Resource Language="en-us"/>')
		_p(1, '</Resources>')

		_p(1, '<Applications>')
		_p(2, '<Application Id="App"')
		_p(3, 'Executable="$targetnametoken$.exe"')
		_p(3, 'EntryPoint="' .. prj.name .. '.App">')
		if vstudio.storeapp == "10.0" then
			_p(3, '<uap:VisualElements')
			_p(4, 'DisplayName="' .. prj.name .. '"')
			_p(4, 'Square150x150Logo="' .. prj.name .. '\\Logo.png"')
			png1x1(prj, "%%/Logo.png")
			if vstudio.storeapp == "10.0" then
				_p(4, 'Square44x44Logo="' .. prj.name .. '\\SmallLogo.png"')
				png1x1(prj, "%%/SmallLogo.png")
			else
				_p(4, 'Square30x30Logo="' .. prj.name .. '\\SmallLogo.png"')
				png1x1(prj, "%%/SmallLogo.png")
			end
			_p(4, 'Description="' .. prj.name .. '"')
			_p(4, 'BackgroundColor="transparent">')
			_p(4, '<uap:SplashScreen Image="' .. prj.name .. '\\SplashScreen.png" />')
			png1x1(prj, "%%/SplashScreen.png")
			_p(3, '</uap:VisualElements>')
		elseif vstudio.storeapp == "durango" then
			_p(3, '<VisualElements')
			_p(4, 'DisplayName="' .. prj.name .. '"')
			_p(4, 'Logo="' .. prj.name .. '\\Logo.png"')
			png1x1(prj, "%%/Logo.png")
			_p(4, 'SmallLogo="' .. prj.name .. '\\SmallLogo.png"')
			png1x1(prj, "%%/SmallLogo.png")
			_p(4, 'Description="' .. prj.name .. '"')
			_p(4, 'ForegroundText="light"')
			_p(4, 'BackgroundColor="transparent">')
			_p(5, '<SplashScreen Image="' .. prj.name .. '\\SplashScreen.png" />')
			png1x1(prj, "%%/SplashScreen.png")
			_p(3, '</VisualElements>')
			_p(3, '<Extensions>')
			_p(4, '<mx:Extension Category="xbox.system.resources">')
			_p(4, '<mx:XboxSystemResources />')
			_p(4, '</mx:Extension>')
			_p(3, '</Extensions>')
		end
		_p(2, '</Application>')
		_p(1, '</Applications>')

		_p('</Package>')
	end