Repository navigation
Expand file tree
/
Copy pathProjectHelper.cs
More file actions
77 lines (70 loc) · 2.88 KB
/
Copy pathProjectHelper.cs
File metadata and controls
77 lines (70 loc) · 2.88 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
using System;
using System.Threading.Tasks;
#if VS14
using Microsoft.VisualStudio;
using Microsoft.VisualStudio.ProjectSystem;
using Microsoft.VisualStudio.ProjectSystem.Designers;
#endif
using Microsoft.VisualStudio.Shell.Interop;
using MsBuildProject = Microsoft.Build.Evaluation.Project;
namespace NuGet.VisualStudio14
{
public static class ProjectHelper
{
#if VS14
public static async void DoWorkInWriterLock(EnvDTE.Project project, IVsHierarchy hierarchy, Action<MsBuildProject> action)
{
await DoWorkInWriterLock((IVsProject)hierarchy, action);
project.Save();
}
private static async Task DoWorkInWriterLock(IVsProject project, Action<MsBuildProject> action)
{
UnconfiguredProject unconfiguredProject = GetUnconfiguredProject(project);
if (unconfiguredProject != null)
{
var service = unconfiguredProject.ProjectService.Services.ProjectLockService;
if (service != null)
{
using (ProjectWriteLockReleaser x = await service.WriteLockAsync())
{
await x.CheckoutAsync(unconfiguredProject.FullPath);
ConfiguredProject configuredProject = await unconfiguredProject.GetSuggestedConfiguredProjectAsync();
MsBuildProject buildProject = await x.GetProjectAsync(configuredProject);
if (buildProject != null)
{
action(buildProject);
}
await x.ReleaseAsync();
}
await unconfiguredProject.ProjectService.Services.ThreadingPolicy.SwitchToUIThread();
}
}
}
private static UnconfiguredProject GetUnconfiguredProject(IVsProject project)
{
IVsBrowseObjectContext context = project as IVsBrowseObjectContext;
if (context == null)
{
IVsHierarchy hierarchy = project as IVsHierarchy;
if (hierarchy != null)
{
object extObject;
if (ErrorHandler.Succeeded(hierarchy.GetProperty((uint)VSConstants.VSITEMID.Root, (int)__VSHPROPID.VSHPROPID_ExtObject, out extObject)))
{
EnvDTE.Project dteProject = extObject as EnvDTE.Project;
if (dteProject != null)
{
context = dteProject.Object as IVsBrowseObjectContext;
}
}
}
}
return context != null ? context.UnconfiguredProject : null;
}
#else
public static void DoWorkInWriterLock(EnvDTE.Project project, IVsHierarchy hierarchy, Action<MsBuildProject> action)
{
}
#endif
}
}