Repository navigation
Expand file tree
/
Copy pathNativeProjectSystem.cs
More file actions
160 lines (140 loc) · 5.62 KB
/
Copy pathNativeProjectSystem.cs
File metadata and controls
160 lines (140 loc) · 5.62 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
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
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text.RegularExpressions;
using EnvDTE;
using Microsoft.VisualStudio.Shell;
using NuGet.VisualStudio.Resources;
namespace NuGet.VisualStudio
{
public class NativeProjectSystem : CpsProjectSystem
{
public NativeProjectSystem(Project project, IFileSystemProvider fileSystemProvider)
: base(project, fileSystemProvider)
{
}
public override bool ReferenceExists(string name)
{
// We disable assembly reference for native projects
return true;
}
public override void AddReference(string referencePath)
{
// We disable assembly reference for native projects
}
public override void RemoveReference(string name)
{
// We disable assembly reference for native projects
}
public override IEnumerable<string> GetFiles(string path, string filter, bool recursive)
{
var allFiles = ThreadHelper.Generic.Invoke<IEnumerable<string>>(() =>
{
if (VsVersionHelper.IsVisualStudio2010)
{
return GetFilesFromProjectForVS2010(path);
}
else
{
return VCProjectHelper.GetFiles(Project.Object, path);
}
});
if (filter == null || filter.Equals("*.*", StringComparison.OrdinalIgnoreCase))
{
return allFiles;
}
Regex matcher = ProjectExtensions.GetFilterRegex(filter);
return allFiles.Where(f => matcher.IsMatch(f));
}
public override IEnumerable<string> GetDirectories(string path)
{
return ThreadHelper.Generic.Invoke<IEnumerable<string>>(() =>
{
if (VsVersionHelper.IsVisualStudio2010)
{
return GetFiltersFromProjectForVS2010(path);
}
else
{
return VCProjectHelper.GetFilters(Project.Object, path);
}
});
}
protected override void AddFileToProject(string path)
{
if (ExcludeFile(path))
{
return;
}
// Get the project items for the folder path
string folderPath = Path.GetDirectoryName(path);
string fullPath = GetFullPath(path);
ThreadHelper.Generic.Invoke(() =>
{
if (VsVersionHelper.IsVisualStudio2010)
{
AddFileToProjectForVS2010(folderPath, fullPath);
}
else
{
VCProjectHelper.AddFileToProject(Project.Object, fullPath, folderPath);
}
});
Logger.Log(MessageLevel.Debug, VsResources.Debug_AddedFileToProject, path, ProjectName);
}
public override void DeleteFile(string path)
{
string folderPath = Path.GetDirectoryName(path);
string fullPath = GetFullPath(path);
bool succeeded;
if (VsVersionHelper.IsVisualStudio2010)
{
succeeded = RemoveFileFromProjectForVS2010(folderPath, fullPath);
}
else
{
succeeded = VCProjectHelper.RemoveFileFromProject(Project.Object, fullPath, folderPath);
}
if (succeeded)
{
// The RemoveFileFromProject() method only removes file from project.
// We want to delete it from disk too.
BaseFileSystem.DeleteFileAndParentDirectoriesIfEmpty(path);
if (!String.IsNullOrEmpty(folderPath))
{
Logger.Log(MessageLevel.Debug, VsResources.Debug_RemovedFileFromFolder, Path.GetFileName(path), folderPath);
}
else
{
Logger.Log(MessageLevel.Debug, VsResources.Debug_RemovedFile, Path.GetFileName(path));
}
}
}
// Use NoInlining option to prevent the CLR from loading VisualStudio10.dll when running inside VS 2013
[MethodImpl(MethodImplOptions.NoInlining)]
private void AddFileToProjectForVS2010(string folderPath, string fullPath)
{
VisualStudio10.VCProjectHelper.AddFileToProject(Project.Object, fullPath, folderPath);
}
// Use NoInlining option to prevent the CLR from loading VisualStudio10.dll when running inside VS 2013
[MethodImpl(MethodImplOptions.NoInlining)]
private bool RemoveFileFromProjectForVS2010(string folderPath, string fullPath)
{
return VisualStudio10.VCProjectHelper.RemoveFileFromProject(Project.Object, fullPath, folderPath);
}
// Use NoInlining option to prevent the CLR from loading VisualStudio10.dll when running inside VS 2013
[MethodImpl(MethodImplOptions.NoInlining)]
private string[] GetFilesFromProjectForVS2010(string folderPath)
{
return VisualStudio10.VCProjectHelper.GetFiles(Project.Object, folderPath).ToArray();
}
// Use NoInlining option to prevent the CLR from loading VisualStudio10.dll when running inside VS 2013
[MethodImpl(MethodImplOptions.NoInlining)]
private string[] GetFiltersFromProjectForVS2010(string folderPath)
{
return VisualStudio10.VCProjectHelper.GetFilters(Project.Object, folderPath).ToArray();
}
}
}