forked from ajopjo/Entity-Framework-Model-Generator
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProjectExtensions.cs
More file actions
71 lines (64 loc) · 2.75 KB
/
ProjectExtensions.cs
File metadata and controls
71 lines (64 loc) · 2.75 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
using EnvDTE;
using Microsoft.VisualStudio.Shell;
using Microsoft.VisualStudio.Shell.Interop;
using System;
using System.Collections.Generic;
using System.Configuration;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
using System.Xml.Linq;
namespace EfModelGenerator
{
public static class ProjectExtensions
{
public static bool IsWebProject(this Project project)
{
return project.GetProjectTypes().Any<string>((Func<string, bool>)(g =>
{
if (!g.EqualsIgnoreCase("{349C5851-65DF-11DA-9384-00065B846F21}"))
return g.EqualsIgnoreCase("{E24C65DC-7377-472B-9ABA-BC803B73C61A}");
return true;
}));
}
public static string ProjectPath(this Project project)
{
return project.Properties.Item("FullPath").Value as string;
}
/// <summary>
/// Get the executing projects configuration
/// </summary>
/// <returns></returns>
public static System.Configuration.Configuration GetProjectConfiguration(this Project project)
{
XDocument document = XDocument.Load(Path.Combine(project.ProjectPath() as string, project.IsWebProject() ? "Web.config" : "App.config"));
string tempFileName = Path.GetTempFileName();
document.Save(tempFileName);
return System.Configuration.ConfigurationManager.OpenMappedExeConfiguration(new ExeConfigurationFileMap()
{
ExeConfigFilename = tempFileName
}, ConfigurationUserLevel.None);
}
private static IEnumerable<string> GetProjectTypes(this Project project)
{
IVsSolution service;
using (ServiceProvider serviceProvider = new ServiceProvider((Microsoft.VisualStudio.OLE.Interop.IServiceProvider)project.DTE))
service = (IVsSolution)serviceProvider.GetService(typeof(IVsSolution));
IVsHierarchy ppHierarchy;
int projectOfUniqueName = service.GetProjectOfUniqueName(project.UniqueName, out ppHierarchy);
if (projectOfUniqueName != 0)
Marshal.ThrowExceptionForHR(projectOfUniqueName);
string pbstrProjTypeGuids;
int projectTypeGuids = ((IVsAggregatableProject)ppHierarchy).GetAggregateProjectTypeGuids(out pbstrProjTypeGuids);
if (projectTypeGuids != 0)
Marshal.ThrowExceptionForHR(projectTypeGuids);
return (IEnumerable<string>)pbstrProjTypeGuids.Split(';');
}
public static bool EqualsIgnoreCase(this string s1, string s2)
{
return string.Equals(s1, s2, StringComparison.OrdinalIgnoreCase);
}
}
}