Repository navigation
Expand file tree
/
Copy pathCpsProjectSystem.cs
More file actions
117 lines (104 loc) · 4.19 KB
/
Copy pathCpsProjectSystem.cs
File metadata and controls
117 lines (104 loc) · 4.19 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
using System;
using System.Runtime.CompilerServices;
using EnvDTE;
#if VS10 || VS11 || VS12
using NuGetVS = NuGet.VisualStudio12;
#endif
#if VS14
using NuGetVS = NuGet.VisualStudio14;
#endif
namespace NuGet.VisualStudio
{
public abstract class CpsProjectSystem : VsProjectSystem
{
protected CpsProjectSystem(Project project, IFileSystemProvider fileSystemProvider) :
base(project, fileSystemProvider)
{
}
public override bool IsBindingRedirectSupported
{
get
{
return false;
}
}
protected override void AddGacReference(string name)
{
// Native & JS projects don't know about GAC
}
public override void AddImport(string targetPath, ProjectImportLocation location)
{
if (VsVersionHelper.IsVisualStudio2010)
{
base.AddImport(targetPath, location);
}
else
{
// For VS 2012 or above, the operation has to be done inside the Writer lock
if (String.IsNullOrEmpty(targetPath))
{
throw new ArgumentNullException(CommonResources.Argument_Cannot_Be_Null_Or_Empty, "targetPath");
}
string relativeTargetPath = PathUtility.GetRelativePath(PathUtility.EnsureTrailingSlash(Root), targetPath);
if (VsVersionHelper.IsVisualStudio2012)
{
Project.DoWorkInWriterLock(buildProject => NuGet.MSBuildProjectUtility.AddImportStatement(buildProject, relativeTargetPath, location));
Project.Save(this);
}
else
{
AddImportStatementForVS2013(location, relativeTargetPath);
}
}
}
// IMPORTANT: The NoInlining is required to prevent CLR from loading VisualStudio12.dll assembly while running
// in VS2010 and VS2012
[MethodImpl(MethodImplOptions.NoInlining)]
private void AddImportStatementForVS2013(ProjectImportLocation location, string relativeTargetPath)
{
NuGetVS.ProjectHelper.DoWorkInWriterLock(
Project,
Project.ToVsHierarchy(),
buildProject => NuGet.MSBuildProjectUtility.AddImportStatement(buildProject, relativeTargetPath, location));
// notify the project system of the change
UpdateImportStamp(Project);
}
public override void RemoveImport(string targetPath)
{
if (VsVersionHelper.IsVisualStudio2010)
{
base.RemoveImport(targetPath);
}
else
{
if (String.IsNullOrEmpty(targetPath))
{
throw new ArgumentNullException(CommonResources.Argument_Cannot_Be_Null_Or_Empty, "targetPath");
}
// For VS 2012 or above, the operation has to be done inside the Writer lock
string relativeTargetPath = PathUtility.GetRelativePath(PathUtility.EnsureTrailingSlash(Root), targetPath);
if (VsVersionHelper.IsVisualStudio2012)
{
Project.DoWorkInWriterLock(buildProject => NuGet.MSBuildProjectUtility.RemoveImportStatement(buildProject, relativeTargetPath));
Project.Save(this);
}
else
{
RemoveImportStatementForVS2013(relativeTargetPath);
}
}
}
// IMPORTANT: The NoInlining is required to prevent CLR from loading VisualStudio12.dll assembly while running
// in VS2010 and VS2012
[MethodImpl(MethodImplOptions.NoInlining)]
private void RemoveImportStatementForVS2013(string relativeTargetPath)
{
NuGetVS.ProjectHelper.DoWorkInWriterLock(
Project,
Project.ToVsHierarchy(),
buildProject => NuGet.MSBuildProjectUtility.RemoveImportStatement(buildProject, relativeTargetPath));
// notify the project system of the change
UpdateImportStamp(Project);
}
}
}