Repository navigation
Expand file tree
/
Copy pathFSharpProjectSystem.cs
More file actions
108 lines (96 loc) · 4.6 KB
/
Copy pathFSharpProjectSystem.cs
File metadata and controls
108 lines (96 loc) · 4.6 KB
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
using System;
using System.Diagnostics.CodeAnalysis;
using System.Globalization;
using EnvDTE;
using NuGet.VisualStudio.Resources;
using VSLangProj;
namespace NuGet.VisualStudio
{
public class FSharpProjectSystem : VsProjectSystem
{
public FSharpProjectSystem(Project project, IFileSystemProvider fileSystemProvider)
: base(project, fileSystemProvider)
{
}
[SuppressMessage("Microsoft.Design", "CA1031:DoNotCatchGeneralExceptionTypes", Justification = "We want to swallow this exception. Read the comment below")]
protected override void AddFileToProject(string path)
{
try
{
base.AddFileToProject(path);
}
catch
{
// HACK: The F# project system blows up with the following stack when calling AddFromFileCopy on a newly created folder:
// at Microsoft.VisualStudio.FSharp.ProjectSystem.MSBuildUtilities.MoveFileToBottom(String relativeFileName, ProjectNode projectNode)
// at Microsoft.VisualStudio.FSharp.ProjectSystem.FSharpProjectNode.MoveFileToBottomIfNoOtherPendingMove(String relativeFileName)
// at Microsoft.VisualStudio.FSharp.ProjectSystem.ProjectNode.AddItem(UInt32 itemIdLoc, VSADDITEMOPERATION op, String itemName, UInt32 filesToOpen, String[] files, IntPtr dlgOwner, VSADDRESULT[] result)
// But it still ends up working so we swallow the exception. We should follow up with F# people to find out what's going on.
}
}
protected override void AddGacReference(string name)
{
// The F# project system expects assemblies that start with * to be framework assemblies.
base.AddGacReference("*" + name);
}
public override bool FileExistsInProject(string path)
{
ProjectItem projectItem = Project.GetProjectItem(path);
return (projectItem != null);
}
/// <summary>
/// WORKAROUND:
/// This override is in place to handle the case-sensitive call to Project.Object.References.Item
/// There are certain assemblies where the AssemblyName and Assembly file name do not match in case
/// And, this causes a mismatch. For more information, Refer to the RemoveReference of the base class
/// </summary>
/// <param name="name"></param>
public override void RemoveReference(string name)
{
RemoveReferenceCore(name, Project.GetReferences());
}
internal void RemoveReferenceCore(string name, References references)
{
try
{
var referenceName = System.IO.Path.GetFileNameWithoutExtension(name);
Reference reference = references.Item(referenceName);
if (reference == null)
{
// No exact match found for referenceName. Trying case-insensitive search
Logger.Log(MessageLevel.Warning, VsResources.Warning_NoExactMatchForReference, referenceName);
foreach (Reference r in references)
{
if (String.Equals(referenceName, r.Name, StringComparison.OrdinalIgnoreCase))
{
if (reference == null)
{
reference = r;
}
else
{
var message = String.Format(CultureInfo.CurrentCulture, VsResources.FailedToRemoveReference, referenceName);
Logger.Log(MessageLevel.Error, message);
throw new InvalidOperationException(message);
}
}
}
}
// At this point, the necessary case-sensitive and case-insensitive search are performed
if (reference != null)
{
reference.Remove();
Logger.Log(MessageLevel.Debug, VsResources.Debug_RemoveReference, name, ProjectName);
}
else
{
Logger.Log(MessageLevel.Warning, VsResources.Warning_FailedToFindMatchForRemoveReference, referenceName);
}
}
catch (Exception e)
{
Logger.Log(MessageLevel.Warning, e.Message);
}
}
}
}