@@ -20,8 +20,7 @@ class FolderContent
20
20
class SolutionGenerator
21
21
{
22
22
string Template =
23
- @"
24
- Microsoft Visual Studio Solution File, Format Version 12.00
23
+ @"Microsoft Visual Studio Solution File, Format Version 12.00
25
24
# Visual Studio 14
26
25
VisualStudioVersion = 14.0.25420.1
27
26
MinimumVisualStudioVersion = 10.0.40219.1
@@ -31,23 +30,23 @@ class SolutionGenerator
31
30
HideSolutionNode = FALSE
32
31
EndGlobalSection
33
32
GlobalSection(NestedProjects) = preSolution
34
- {1}
35
- EndGlobalSection
33
+ {1} EndGlobalSection
36
34
EndGlobal
37
35
" ;
38
36
39
37
40
- private readonly Arguments _args ;
38
+ private readonly Options _args ;
41
39
private HashSet < string > _excludedFolders ;
42
- public SolutionGenerator ( Arguments args )
40
+ public SolutionGenerator ( Options args )
43
41
{
44
42
_args = args ;
45
- _excludedFolders = new HashSet < string > ( ".git,bin,obj,packages,node_modules" . Split ( ',' ) ) ;
43
+ _excludedFolders = new HashSet < string > ( _args . ExcludedFolders . Split ( ',' ) ) ;
46
44
}
47
45
48
46
public void Render ( )
49
47
{
50
48
var content = GetContent ( _args . Folder ) ;
49
+ content . FolderId = string . Empty ; // Root folder is a special case
51
50
52
51
StringBuilder projectSection = new StringBuilder ( ) ;
53
52
StringBuilder folderSection = new StringBuilder ( ) ;
@@ -58,6 +57,9 @@ public void Render()
58
57
Path . Combine ( _args . Folder , _args . SolutionFileName ) ,
59
58
string . Format ( Template , projectSection . ToString ( ) , folderSection . ToString ( ) )
60
59
) ;
60
+
61
+ Console . WriteLine ( "Done." ) ;
62
+
61
63
}
62
64
63
65
private void WriteContent ( FolderContent content , StringBuilder projectSection , StringBuilder folderSection )
@@ -67,7 +69,10 @@ private void WriteContent(FolderContent content, StringBuilder projectSection, S
67
69
projectSection . AppendLine ( $ "Project(\" {{2150E333-8FDC-42A3-9474-1A3956D46DE8}}\" ) = \" { Path . GetFileName ( dir . Path ) } \" , \" { Path . GetFileName ( dir . Path ) } \" , \" {{{dir.FolderId}}}\" ") ;
68
70
projectSection . AppendLine ( "EndProject" ) ;
69
71
70
- folderSection . AppendLine ( $ " {{{dir.FolderId}}} = {{{content.FolderId}}}") ;
72
+ if ( ! string . IsNullOrEmpty ( content . FolderId ) )
73
+ {
74
+ folderSection . AppendLine ( $ " {{{dir.FolderId}}} = {{{content.FolderId}}}") ;
75
+ }
71
76
WriteContent ( dir , projectSection , folderSection ) ;
72
77
}
73
78
@@ -78,7 +83,8 @@ private void WriteContent(FolderContent content, StringBuilder projectSection, S
78
83
79
84
projectSection . AppendLine ( $ "Project(\" {{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}}\" ) = \" { Path . GetFileNameWithoutExtension ( project ) } \" , \" { MakeRelative ( project ) } \" , \" {{{projectId}}}\" ") ;
80
85
projectSection . AppendLine ( "EndProject" ) ;
81
- folderSection . AppendLine ( $ " {{{projectId}}} = {{{content.FolderId}}}") ;
86
+ if ( ! string . IsNullOrEmpty ( content . FolderId ) )
87
+ folderSection . AppendLine ( $ " {{{projectId}}} = {{{content.FolderId}}}") ;
82
88
}
83
89
}
84
90
@@ -89,7 +95,8 @@ private string MakeRelative(string path)
89
95
90
96
FolderContent GetContent ( string folder )
91
97
{
92
- Console . WriteLine ( folder ) ;
98
+ if ( _args . Verbose )
99
+ Console . WriteLine ( folder ) ;
93
100
var content = new FolderContent ( ) ;
94
101
content . Path = folder ;
95
102
try
@@ -102,15 +109,14 @@ FolderContent GetContent(string folder)
102
109
var subContent = GetContent ( subFolder ) ;
103
110
if ( subContent . IsEmpty ( ) )
104
111
continue ;
105
- else if ( subContent . SubDirectories . Count ( ) == 0 && subContent . Projects . Count ( ) == 1 )
106
- content . Projects . AddRange ( subContent . Projects ) ;
107
- // else if (subContent.Projects.Count == 1 && Path.GetFileNameWithoutExtension(subContent.Projects[0]) == folderName && subContent.SubDirectories.Count == 0)
108
- // content.Projects.Add(subContent.Projects[0]);
112
+ else if ( subContent . SubDirectories . Count ( ) == 0 && subContent . Projects . Count ( ) == 1 )
113
+ content . Projects . AddRange ( subContent . Projects ) ; // Flatten folders with only one project.
109
114
else
110
115
content . SubDirectories . Add ( subContent ) ;
111
116
}
112
117
}
113
- catch ( PathTooLongException ) { }
118
+ catch ( PathTooLongException )
119
+ { Console . Error . WriteLine ( $ "PathTooLongException: { folder } ") ; }
114
120
115
121
try
116
122
{
@@ -119,7 +125,8 @@ FolderContent GetContent(string folder)
119
125
content . Projects . Add ( subProj ) ;
120
126
}
121
127
}
122
- catch ( PathTooLongException ) { }
128
+ catch ( PathTooLongException )
129
+ { Console . Error . WriteLine ( $ "PathTooLongException: { folder } ") ; }
123
130
return content ;
124
131
}
125
132
}
0 commit comments