-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSolutionExtensions.cs
More file actions
74 lines (66 loc) · 2.32 KB
/
Copy pathSolutionExtensions.cs
File metadata and controls
74 lines (66 loc) · 2.32 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
using System;
using EnvDTE;
using EnvDTE80;
using Microsoft.VisualStudio;
namespace CnSharp.VisualStudio.Extensions
{
public static class SolutionExtensions
{
public static ProjectItem FindSolutionItemByName(this Solution sln, string name, bool recursive)
{
ProjectItem projectItem = null;
foreach (Project project in sln.Projects)
{
projectItem = project.FindProjectItem(name, recursive);
if (projectItem != null)
{
break;
}
}
return projectItem;
}
public const string SolutionItemsFolderName = "Solution Items";
public static Project GetOrAddSolutionItemsFolder(this Solution2 sln)
{
foreach (Project project in sln.Projects)
{
if(project.Name == SolutionItemsFolderName)
{
return project;
}
}
return sln.AddSolutionFolder(SolutionItemsFolderName);
}
public static ProjectItem AddSolutionItem(this Solution2 sln,string file)
{
var folder = sln.GetOrAddSolutionItemsFolder();
foreach (ProjectItem projectItem in folder.ProjectItems)
{
var projItemGuid = new Guid(projectItem.Kind);
var fileName = projItemGuid == VSConstants.GUID_ItemType_PhysicalFile
? projectItem.FileNames[0]
: projectItem.FileNames[1];
if (fileName == file) return projectItem;
}
return folder.ProjectItems.AddFromFile(file);
}
public static bool Build(this Solution2 sln, string configName = null)
{
var solutionBuild = (SolutionBuild2)sln.SolutionBuild;
if (!string.IsNullOrWhiteSpace(configName))
{
solutionBuild.SolutionConfigurations.Item(configName).Activate();
}
solutionBuild.Build(true);
return solutionBuild.LastBuildInfo == 0;
}
public static bool BuildRelease(this Solution2 sln)
{
return Build(sln, "Release");
}
public static bool BuildDebug(this Solution2 sln)
{
return Build(sln, "Debug");
}
}
}