-
Notifications
You must be signed in to change notification settings - Fork 797
/
Copy pathProjectConfig.cs
1984 lines (1751 loc) · 74.5 KB
/
ProjectConfig.cs
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
// Copyright (c) Microsoft Open Technologies, Inc. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using Microsoft.VisualStudio.Shell.Interop;
using Microsoft.VisualStudio.OLE.Interop;
using Microsoft.VisualStudio.Shell;
using System;
using System.Diagnostics;
using System.Globalization;
using System.Runtime.InteropServices;
using System.Security;
using System.IO;
using System.Collections.Generic;
using MSBuild = Microsoft.Build.BuildEngine;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using Microsoft.VisualStudio.FSharp.LanguageService;
using Microsoft.Win32;
namespace Microsoft.VisualStudio.FSharp.ProjectSystem
{
internal struct ConfigCanonicalName
{
private static readonly StringComparer CMP = StringComparer.Ordinal;
private readonly string myConfigName;
private readonly string myPlatform;
public ConfigCanonicalName(string configName, string platform)
{
myConfigName = configName;
if (CMP.Equals(platform,ProjectConfig.AnyCPU))
myPlatform = ProjectConfig.Any_CPU;
else
myPlatform = platform;
}
public ConfigCanonicalName(string configCanonicalName)
{
string platform;
TrySplitConfigurationCanonicalName(configCanonicalName, out myConfigName, out platform);
if (CMP.Equals(platform, ProjectConfig.AnyCPU))
myPlatform = ProjectConfig.Any_CPU;
else
myPlatform = platform;
}
public string ConfigName { get { return myConfigName != null ? myConfigName : String.Empty; } }
public string Platform { get { return myPlatform != null ? myPlatform : String.Empty; } }
public bool MatchesPlatform(string platform)
{
return CMP.Equals(platform, myPlatform);
}
public bool MatchesConfigName(string configName)
{
return CMP.Equals(configName, myConfigName);
}
public string MSBuildPlatform
{
get
{
if (CMP.Equals(myPlatform,ProjectConfig.Any_CPU))
return ProjectConfig.AnyCPU;
else
return myPlatform != null ? myPlatform : String.Empty;
}
}
public string PlatformTarget
{
get { return MSBuildPlatform; }
}
public override string ToString()
{
if (String.IsNullOrEmpty(myPlatform)) return myConfigName;
return String.Format("{0}|{1}", myConfigName, myPlatform);
}
public string ToMSBuildCondition()
{
if (String.IsNullOrEmpty(myPlatform))
{
return String.Format(CultureInfo.InvariantCulture, " '$(Configuration)' == '{0}' ", myConfigName);
}
else
{
return String.Format(CultureInfo.InvariantCulture, " '$(Configuration)|$(Platform)' == '{0}|{1}' ", myConfigName, this.MSBuildPlatform);
}
}
public override int GetHashCode()
{
return CMP.GetHashCode(myConfigName) * 29 + CMP.GetHashCode(myPlatform);
}
public bool Equals(ConfigCanonicalName other)
{
return CMP.Equals(myConfigName, other.myConfigName) && CMP.Equals(myPlatform, other.myPlatform);
}
public override bool Equals(object obj)
{
if (!(obj is ConfigCanonicalName)) return false;
return Equals((ConfigCanonicalName)obj);
}
public static bool operator ==(ConfigCanonicalName left, ConfigCanonicalName right)
{
return left.Equals(right);
}
public static bool operator !=(ConfigCanonicalName left, ConfigCanonicalName right)
{
return !left.Equals(right);
}
/// <summary>
/// Splits the canonical configuration name into platform and configuration name.
/// </summary>
/// <param name="canonicalName">The canonicalName name.</param>
/// <param name="configName">The name of the configuration.</param>
/// <param name="platformName">The name of the platform.</param>
/// <returns>true if successfull.</returns>
/*internal, but public for FSharp.Project.dll*/
internal static bool TrySplitConfigurationCanonicalName(string canonicalName, out string configName, out string platformName)
{
// TODO rationalize this code with callers and ProjectNode.OnHandleConfigurationRelatedGlobalProperties, ProjectNode.TellMSBuildCurrentSolutionConfiguration, etc
configName = String.Empty;
platformName = String.Empty;
if (String.IsNullOrEmpty(canonicalName))
{
return false;
}
string[] splittedCanonicalName = canonicalName.Split(new char[] { '|' }, StringSplitOptions.RemoveEmptyEntries);
if (splittedCanonicalName == null || (splittedCanonicalName.Length != 1 && splittedCanonicalName.Length != 2))
{
return false;
}
configName = splittedCanonicalName[0];
if (splittedCanonicalName.Length == 2)
{
platformName = splittedCanonicalName[1];
}
return true;
}
public static ConfigCanonicalName OfCondition(string condition)
{
const string confOnly = "'$(Configuration)'";
const string confAndPlatform = "'$(Configuration)|$(Platform)'";
condition = condition.Trim();
if (condition.StartsWith(confOnly) || condition.StartsWith(confAndPlatform))
{
var eqeqIdx = condition.IndexOf("==");
if (eqeqIdx < 0) return new ConfigCanonicalName();
var condTarget = condition.Substring(eqeqIdx + 2).Trim(' ');
if (condTarget.StartsWith("'")) condTarget = condTarget.Substring(1);
if (condTarget.EndsWith("'")) condTarget = condTarget.Substring(0, condTarget.Length - 1);
// In confOnly case condTarget now contains "ConfName"
// In confInPlatformCase condTarget now contains "ConfName|Platform"
// ConfigCanonicalName constructor is ok with both
return new ConfigCanonicalName(condTarget.Trim());
}
return new ConfigCanonicalName();
}
}
[CLSCompliant(false), ComVisible(true)]
public class ProjectConfig :
IVsCfg,
IVsProjectCfg,
IVsProjectCfg2,
IVsProjectFlavorCfg,
IVsDebuggableProjectCfg,
IVsQueryDebuggableProjectCfg,
ISpecifyPropertyPages,
IVsSpecifyProjectDesignerPages,
IVsCfgBrowseObject
{
#region constants
/*internal, but public for FSharp.Project.dll*/ public const string Debug = "Debug";
/*internal, but public for FSharp.Project.dll*/ public const string Release = "Release";
/*internal, but public for FSharp.Project.dll*/ public const string AnyCPU = "AnyCPU";
/*internal, but public for FSharp.Project.dll*/ public const string AnyCPU32BitPreferred = "AnyCPU32BitPreferred";
public const string Any_CPU = "Any CPU";
#endregion
#region fields
private ProjectNode project;
private ConfigCanonicalName configCanonicalName;
private DateTime lastCache;
private string projectAssemblyNameCache; // null means invalid
private int fCanLaunchCache; // -1 means invalid
private string cachedOutputPath = "";
private Microsoft.Build.Evaluation.Project evaluatedProject = null;
private List<OutputGroup> outputGroups;
private IVsProjectFlavorCfg flavoredCfg = null;
private BuildableProjectConfig buildableCfg = null;
private readonly ProjectConfigProperties projectConfigurationProperties ;
#endregion
private string GetProjectAssemblyName()
{
if (this.lastCache < this.project.LastModifiedTime || this.projectAssemblyNameCache == null)
{
this.lastCache = this.project.LastModifiedTime;
this.projectAssemblyNameCache = this.project.GetAssemblyName(this.configCanonicalName);
}
return this.projectAssemblyNameCache;
}
#region properties
public ProjectNode ProjectMgr
{
get
{
return this.project;
}
}
public string ConfigName
{
get
{
return this.configCanonicalName.ConfigName;
}
set
{
this.configCanonicalName = new ConfigCanonicalName(value, this.configCanonicalName.Platform);
this.projectAssemblyNameCache = null;
}
}
internal ConfigCanonicalName ConfigCanonicalName
{
get { return this.configCanonicalName; }
}
// Debug property page properties
public string StartURL
{
get
{
return GetConfigurationProperty(ProjectFileConstants.StartURL, false);
}
set
{
SetConfigurationProperty(ProjectFileConstants.StartURL, value);
}
}
public string StartArguments
{
get
{
return GetConfigurationProperty(ProjectFileConstants.StartArguments, false);
}
set
{
SetConfigurationProperty(ProjectFileConstants.StartArguments, value);
}
}
public string StartWorkingDirectory
{
get
{
return GetConfigurationProperty(ProjectFileConstants.StartWorkingDirectory, false);
}
set
{
SetConfigurationProperty(ProjectFileConstants.StartWorkingDirectory, value);
}
}
public string StartProgram
{
get
{
return GetConfigurationProperty(ProjectFileConstants.StartProgram, false);
}
set
{
SetConfigurationProperty(ProjectFileConstants.StartProgram, value);
}
}
public int StartAction
{
get
{
string startAction = GetConfigurationProperty(ProjectFileConstants.StartAction, false);
if ("Program" == startAction)
return 1;
else if ("URL" == startAction)
return 2;
else // "Project"
return 0;
}
set
{
string startAction = "";
switch (value)
{
case 0:
startAction = "Project";
break;
case 1:
startAction = "Program";
break;
case 2:
startAction = "URL";
break;
default:
throw new ArgumentException("Invalid StartAction value");
}
SetConfigurationProperty(ProjectFileConstants.StartAction, startAction);
}
}
private bool getBool(string projectFileConstant)
{
return "true" == GetConfigurationProperty(projectFileConstant, false);
}
private void setBool(string projectFileConstant, bool p)
{
string boolString = p ? "true" : "false";
SetConfigurationProperty(projectFileConstant, boolString);
}
public bool EnableSQLServerDebugging
{
get
{
return getBool(ProjectFileConstants.EnableSQLServerDebugging);
}
set
{
setBool(ProjectFileConstants.EnableSQLServerDebugging, value);
}
}
public bool EnableUnmanagedDebugging
{
get
{
return getBool(ProjectFileConstants.EnableUnmanagedDebugging);
}
set
{
setBool(ProjectFileConstants.EnableUnmanagedDebugging, value);
}
}
public string RemoteDebugMachine
{
get
{
return GetConfigurationProperty(ProjectFileConstants.RemoteDebugMachine, false);
}
set
{
SetConfigurationProperty(ProjectFileConstants.RemoteDebugMachine, value);
}
}
public bool RemoteDebugEnabled
{
get
{
return getBool(ProjectFileConstants.RemoteDebugEnabled);
}
set
{
setBool(ProjectFileConstants.RemoteDebugEnabled, value);
}
}
public bool UseVSHostingProcess
{
get
{
return getBool(ProjectFileConstants.UseVSHostingProcess);
}
set
{
setBool(ProjectFileConstants.UseVSHostingProcess, value);
}
}
// Build Property Page properties
public bool Optimize
{
get
{
return getBool(ProjectFileConstants.Optimize);
}
set
{
setBool(ProjectFileConstants.Optimize, value);
}
}
public bool Tailcalls
{
get
{
return getBool(ProjectFileConstants.Tailcalls);
}
set
{
setBool(ProjectFileConstants.Tailcalls, value);
}
}
public bool Prefer32Bit
{
get
{
return getBool(ProjectFileConstants.Prefer32Bit);
}
set
{
setBool(ProjectFileConstants.Prefer32Bit, value);
}
}
public bool DebugSymbols
{
get
{
return getBool(ProjectFileConstants.DebugSymbols);
}
set
{
setBool(ProjectFileConstants.DebugSymbols, value);
}
}
public string DebugType
{
get
{
return GetConfigurationProperty(ProjectFileConstants.DebugType,false);
}
set
{
SetConfigurationProperty(ProjectFileConstants.DebugType, value);
}
}
public string OutputPath
{
get
{
if (this.cachedOutputPath == string.Empty)
this.cachedOutputPath = GetConfigurationProperty(ProjectFileConstants.OutputPath, false);
return this.cachedOutputPath;
}
set
{
// for an emtpy string, convert to the cwd
if (value == string.Empty)
value = @".\";
try
{
// first, throw an exception if the path contains any bad characters
if (value.IndexOfAny(System.IO.Path.GetInvalidPathChars()) >= 0)
throw new System.ArgumentException();
SetConfigurationProperty(ProjectFileConstants.OutputPath, value);
this.cachedOutputPath = value;
}
catch
{
// Exception can be raised when the given path's format is not valid, so restore it
RestoreConfigurationProperty(ProjectFileConstants.OutputPath, this.cachedOutputPath);
throw new System.ArgumentException(SR.GetString(SR.InvalidOutputPath, CultureInfo.CurrentUICulture));
}
}
}
public string DefineConstants
{
get
{
return GetConfigurationProperty(ProjectFileConstants.DefineConstants, true);
}
set
{
SetConfigurationProperty(ProjectFileConstants.DefineConstants, value);
}
}
public string NoWarn
{
get
{
return GetConfigurationProperty(ProjectFileConstants.NoWarn, false);
}
set
{
SetConfigurationProperty(ProjectFileConstants.NoWarn, value);
}
}
public bool TreatWarningsAsErrors
{
get
{
return getBool(ProjectFileConstants.TreatWarningsAsErrors);
}
set
{
setBool(ProjectFileConstants.TreatWarningsAsErrors, value);
}
}
public string TreatSpecificWarningsAsErrors
{
get
{
return GetConfigurationProperty(ProjectFileConstants.WarningsAsErrors, false);
}
set
{
SetConfigurationProperty(ProjectFileConstants.WarningsAsErrors, value);
}
}
public string DocumentationFile
{
get
{
return GetConfigurationProperty(ProjectFileConstants.DocumentationFile, false);
}
set
{
string oldValue = GetConfigurationProperty(ProjectFileConstants.DocumentationFile, false);
try {
SetConfigurationProperty(ProjectFileConstants.DocumentationFile, value);
}
catch (Microsoft.Build.Exceptions.InvalidProjectFileException)
{
// Exception can be raised when the given path's format is not valid, so restore it
RestoreConfigurationProperty(ProjectFileConstants.DocumentationFile, oldValue);
throw;
}
}
}
public int WarningLevel
{
get
{
switch (GetConfigurationProperty(ProjectFileConstants.WarningLevel, false))
{
case "0": return 0;
case "1": return 1;
case "2": return 2;
case "3": return 3;
case "4": return 4;
case "5": return 5;
default: throw new ArgumentException("Invalid WarningLevel value in Project file.");
}
}
set
{
SetConfigurationProperty(ProjectFileConstants.WarningLevel, value.ToString());
}
}
public string PlatformTarget
{
get
{
return GetConfigurationProperty(ProjectFileConstants.PlatformTarget, false);
}
set
{
SetConfigurationProperty(ProjectFileConstants.PlatformTarget, value);
}
}
public string OtherFlags
{
get
{
return GetConfigurationProperty(ProjectFileConstants.OtherFlags, false);
}
set
{
SetConfigurationProperty(ProjectFileConstants.OtherFlags, value);
}
}
public virtual object ConfigurationProperties
{
get
{
return this.projectConfigurationProperties;
}
}
public /*protected, but public for FSharp.Project.dll*/ IList<OutputGroup> OutputGroups
{
get
{
if (null == this.outputGroups)
{
// Initialize output groups
this.outputGroups = new List<OutputGroup>();
// Get the list of group names from the project.
// The main reason we get it from the project is to make it easier for someone to modify
// it by simply overriding that method and providing the correct MSBuild target(s).
IList<KeyValuePair<string, string>> groupNames = project.GetOutputGroupNames();
if (groupNames != null)
{
// Populate the output array
foreach (KeyValuePair<string, string> group in groupNames)
{
OutputGroup outputGroup = CreateOutputGroup(project, group);
this.outputGroups.Add(outputGroup);
}
}
}
return this.outputGroups;
}
}
#endregion
#region ctors
internal ProjectConfig(ProjectNode project, ConfigCanonicalName configName)
{
this.project = project;
this.configCanonicalName = configName;
this.fCanLaunchCache = -1;
this.lastCache = DateTime.MinValue;
this.projectConfigurationProperties = new ProjectConfigProperties(this);
ErrorHandler.ThrowOnFailure(ProjectMgr.InteropSafeIVsProjectFlavorCfgProvider.CreateProjectFlavorCfg(this, out flavoredCfg));
// if the flavored object support XML fragment, initialize it
IPersistXMLFragment persistXML = flavoredCfg as IPersistXMLFragment;
if (null != persistXML)
{
this.project.LoadXmlFragment(persistXML, this.DisplayName);
}
}
#endregion
#region methods
public /*protected, but public for FSharp.Project.dll*/ virtual OutputGroup CreateOutputGroup(ProjectNode project, KeyValuePair<string, string> group)
{
OutputGroup outputGroup = new OutputGroup(group.Key, group.Value, project, this);
return outputGroup;
}
public void PrepareBuild(bool clean)
{
project.PrepareBuild(this.configCanonicalName, clean);
}
public virtual string GetConfigurationProperty(string propertyName, bool resetCache)
{
Microsoft.Build.Evaluation.ProjectProperty property = GetMsBuildProperty(propertyName, resetCache);
if (property == null)
return null;
return property.EvaluatedValue;
}
public virtual void SetConfigurationProperty(string propertyName, string propertyValue)
{
if (!this.project.QueryEditProjectFile(false))
{
throw Marshal.GetExceptionForHR(VSConstants.OLE_E_PROMPTSAVECANCELLED);
}
string condition = this.configCanonicalName.ToMSBuildCondition();
SetPropertyUnderCondition(propertyName, propertyValue, condition);
// property cache will need to be updated
this.evaluatedProject = null;
UpdateOutputGroup();
}
// Signal the output groups that something is changed
private void UpdateOutputGroup() {
foreach (OutputGroup group in this.OutputGroups)
{
group.InvalidateGroup();
}
this.project.SetProjectFileDirty(true);
}
// This method is to restore the property value with old one when configuration goes wrong.
// Unlike SetConfigurationProperty(), this method won't reevaluate the project prior to add the value, which may raise exceptions.
private void RestoreConfigurationProperty(string propertyName, string propertyValue)
{
string condition = this.configCanonicalName.ToMSBuildCondition();
// Get properties for current configuration from project file and cache it
MSBuildProject.SetGlobalProperty(this.project.BuildProject, ProjectFileConstants.Configuration, configCanonicalName.ConfigName);
MSBuildProject.SetGlobalProperty(this.project.BuildProject, ProjectFileConstants.Platform, configCanonicalName.MSBuildPlatform);
this.evaluatedProject = this.project.BuildProject;
SetPropertyUnderConditionImpl(propertyName, propertyValue, condition);
this.evaluatedProject = null;
UpdateOutputGroup();
}
/// <summary>
/// Emulates the behavior of SetProperty(name, value, condition) on the old MSBuild object model.
/// This finds a property group with the specified condition (or creates one if necessary) then sets the property in there.
/// </summary>
private void SetPropertyUnderCondition(string propertyName, string propertyValue, string condition)
{
this.EnsureCache();
SetPropertyUnderConditionImpl(propertyName, propertyValue, condition);
}
private void SetPropertyUnderConditionImpl(string propertyName, string propertyValue, string condition)
{
string conditionTrimmed = (condition == null) ? String.Empty : condition.Trim();
if (conditionTrimmed.Length == 0)
{
evaluatedProject.SetProperty(propertyName, propertyValue);
return;
}
// New OM doesn't have a convenient equivalent for setting a property with a particular property group condition.
// So do it ourselves.
Microsoft.Build.Construction.ProjectPropertyGroupElement newGroup = null;
foreach (Microsoft.Build.Construction.ProjectPropertyGroupElement group in this.evaluatedProject.Xml.PropertyGroups)
{
if (String.Equals(group.Condition.Trim(), conditionTrimmed, StringComparison.OrdinalIgnoreCase))
{
newGroup = group;
break;
}
}
if (newGroup == null)
{
newGroup = this.evaluatedProject.Xml.AddPropertyGroup(); // Adds after last existing PG, else at start of project
newGroup.Condition = condition;
}
Microsoft.Build.Construction.ProjectPropertyElement last = null; // If there's dupes, pick the last one so we win
foreach (Microsoft.Build.Construction.ProjectPropertyElement property in newGroup.Properties)
{
if (String.Equals(property.Name, propertyName, StringComparison.OrdinalIgnoreCase) && property.Condition.Length == 0)
{
last = property;
}
}
if (last != null)
{
last.Value = propertyValue;
return;
}
newGroup.AddProperty(propertyName, propertyValue);
}
/// <summary>
/// If flavored, and if the flavor config can be dirty, ask it if it is dirty
/// </summary>
/// <param name="storageType">Project file or user file</param>
/// <returns>0 = not dirty</returns>
/*internal, but public for FSharp.Project.dll*/ public int IsFlavorDirty(_PersistStorageType storageType)
{
int isDirty = 0;
if (this.flavoredCfg != null && this.flavoredCfg is IPersistXMLFragment)
{
((IPersistXMLFragment)this.flavoredCfg).IsFragmentDirty((uint)storageType, out isDirty);
}
return isDirty;
}
/// <summary>
/// If flavored, ask the flavor if it wants to provide an XML fragment
/// </summary>
/// <param name="flavor">Guid of the flavor</param>
/// <param name="storageType">Project file or user file</param>
/// <param name="fragment">Fragment that the flavor wants to save</param>
/// <returns>HRESULT</returns>
/*internal, but public for FSharp.Project.dll*/ public int GetXmlFragment(Guid flavor, _PersistStorageType storageType, out string fragment)
{
fragment = null;
int hr = VSConstants.S_OK;
if (this.flavoredCfg != null && this.flavoredCfg is IPersistXMLFragment)
{
Guid flavorGuid = flavor;
hr = ((IPersistXMLFragment)this.flavoredCfg).Save(ref flavorGuid, (uint)storageType, out fragment, 1);
}
return hr;
}
#endregion
#region IVsSpecifyPropertyPages
public void GetPages(CAUUID[] pages)
{
// We do not check whether the supportsProjectDesigner is set to false on the ProjectNode.
// We rely that the caller knows what to call on us.
if (pages == null)
{
throw new ArgumentNullException("pages");
}
if (pages.Length == 0)
{
throw new ArgumentException(SR.GetString(SR.InvalidParameter, CultureInfo.CurrentUICulture), "pages");
}
// behave similar to C#\VB - return empty array
pages[0] = new CAUUID();
pages[0].cElems = 0;
}
#endregion
#region IVsSpecifyProjectDesignerPages
/// <summary>
/// Implementation of the IVsSpecifyProjectDesignerPages. It will retun the pages that are configuration dependent.
/// </summary>
/// <param name="pages">The pages to return.</param>
/// <returns>VSConstants.S_OK</returns>
public virtual int GetProjectDesignerPages(CAUUID[] pages)
{
this.GetCfgPropertyPages(pages);
return VSConstants.S_OK;
}
#endregion
#region IVsCfg methods
/// <summary>
/// The display name is a two part item
/// first part is the config name, 2nd part is the platform name
/// </summary>
public virtual int get_DisplayName(out string name)
{
name = DisplayName;
return VSConstants.S_OK;
}
private string DisplayName
{
get
{
return this.configCanonicalName.ToString();
}
}
public virtual int get_IsDebugOnly(out int fDebug)
{
fDebug = 0;
if (this.configCanonicalName.ConfigName == Debug)
{
fDebug = 1;
}
return VSConstants.S_OK;
}
public virtual int get_IsReleaseOnly(out int fRelease)
{
CCITracing.TraceCall();
fRelease = 0;
if (this.configCanonicalName.ConfigName == Release)
{
fRelease = 1;
}
return VSConstants.S_OK;
}
#endregion
#region IVsProjectCfg methods
public virtual int EnumOutputs(out IVsEnumOutputs eo)
{
CCITracing.TraceCall();
eo = null;
return VSConstants.E_NOTIMPL;
}
public virtual int get_BuildableProjectCfg(out IVsBuildableProjectCfg pb)
{
CCITracing.TraceCall();
if (buildableCfg == null)
buildableCfg = new BuildableProjectConfig(this);
pb = buildableCfg;
return VSConstants.S_OK;
}
public virtual int get_CanonicalName(out string name)
{
return ((IVsCfg)this).get_DisplayName(out name);
}
public virtual int get_IsPackaged(out int pkgd)
{
CCITracing.TraceCall();
pkgd = 0;
return VSConstants.S_OK;
}
public virtual int get_IsSpecifyingOutputSupported(out int f)
{
CCITracing.TraceCall();
f = 1;
return VSConstants.S_OK;
}
public virtual int get_Platform(out Guid platform)
{
CCITracing.TraceCall();
platform = Guid.Empty;
return VSConstants.E_NOTIMPL;
}
public virtual int get_ProjectCfgProvider(out IVsProjectCfgProvider p)
{
CCITracing.TraceCall();
p = null;
IVsCfgProvider cfgProvider = null;
this.project.GetCfgProvider(out cfgProvider);
if (cfgProvider != null)
{
p = cfgProvider as IVsProjectCfgProvider;
}
return (null == p) ? VSConstants.E_NOTIMPL : VSConstants.S_OK;
}
public virtual int get_RootURL(out string root)
{
CCITracing.TraceCall();
root = null;
return VSConstants.S_OK;
}
public virtual int get_TargetCodePage(out uint target)
{
CCITracing.TraceCall();
target = (uint)System.Text.Encoding.Default.CodePage;
return VSConstants.S_OK;
}
public virtual int get_UpdateSequenceNumber(ULARGE_INTEGER[] li)
{
CCITracing.TraceCall();
li[0] = new ULARGE_INTEGER();
li[0].QuadPart = 0;
return VSConstants.S_OK;
}
public virtual int OpenOutput(string name, out IVsOutput output)
{
CCITracing.TraceCall();
output = null;
return VSConstants.E_NOTIMPL;
}
#endregion
private VsDebugTargetInfo GetDebugTargetInfo(uint grfLaunch, bool forLaunch)
{
VsDebugTargetInfo info = new VsDebugTargetInfo();
info.cbSize = (uint)Marshal.SizeOf(info);
info.dlo = Microsoft.VisualStudio.Shell.Interop.DEBUG_LAUNCH_OPERATION.DLO_CreateProcess;
// On first call, reset the cache, following calls will use the cached values
string property = GetConfigurationProperty("StartAction", true);
// Set the debug target
if (0 == System.String.Compare("Program", property, StringComparison.OrdinalIgnoreCase))
{
string startProgram = StartProgram;
if (!string.IsNullOrEmpty(startProgram))
info.bstrExe = startProgram;
}
else
// property is either null or "Project"
// we're ignoring "URL" for now
{
string outputType = project.GetProjectProperty(ProjectFileConstants.OutputType, false);
if (forLaunch && 0 == string.Compare("library", outputType, StringComparison.OrdinalIgnoreCase))