@@ -46,9 +46,7 @@ private static string FindSpecFlow(string version)
4646 var userProfile = Environment . GetEnvironmentVariable ( "USERPROFILE" ) ;
4747
4848 if ( string . IsNullOrWhiteSpace ( userProfile ) )
49- {
5049 userProfile = Environment . GetFolderPath ( Environment . SpecialFolder . UserProfile ) ;
51- }
5250
5351 path = Path . Combine ( userProfile , ".nuget" , "packages" , relativePathToSpecFlow ) ;
5452
@@ -64,29 +62,37 @@ private static bool TryGetSpecFlowVersion(FileInfo csproj, out string version)
6462 doc . Load ( csproj . FullName ) ;
6563
6664 var root = doc . DocumentElement ;
67- var node = root . SelectSingleNode ( "//ItemGroup/PackageReference[translate(@Include, 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz')='specflow']" ) ; // case-insensitive for XPath version 1.0
65+
66+ // Case-insensitive for XPath version 1.0
67+ var node = root . SelectSingleNode ( "//ItemGroup/PackageReference[translate(@Include, 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz')='specflow']" ) ;
68+
6869 if ( node == null )
6970 {
70- if ( TryGetSpecflowVersionFromImports ( csproj , root , out version ) )
71+ if ( TryGetSpecFlowVersionFromImports ( csproj , root , out version ) )
7172 return true ;
7273
7374 version = default ( string ) ;
7475 return false ;
7576 }
77+
7678 version = node . Attributes [ "Version" ] . Value ;
7779 return true ;
7880 }
7981
80- private static bool TryGetSpecflowVersionFromImports ( FileInfo csproj , XmlElement root , out string version )
82+ private static bool TryGetSpecFlowVersionFromImports ( FileInfo csproj , XmlElement root , out string version )
8183 {
8284 var importNodes = root . SelectNodes ( "//Import" ) ;
85+
8386 foreach ( XmlNode import in importNodes )
8487 {
8588 var relativePath = import . Attributes [ "Project" ] . Value ;
8689 var fullPath = Path . Combine ( csproj . DirectoryName , relativePath ) ;
90+
8791 if ( ! File . Exists ( fullPath ) )
8892 continue ;
93+
8994 var importInfo = new FileInfo ( fullPath ) ;
95+
9096 if ( TryGetSpecFlowVersion ( importInfo , out version ) )
9197 return true ;
9298 }
@@ -107,9 +113,7 @@ public IEnumerable<FileInfo> GetFeatureFromLinks(FileInfo csproj)
107113 var include = node . Attributes [ "Include" ] . Value ;
108114
109115 if ( File . Exists ( include ) && Path . GetExtension ( include ) . Equals ( ".feature" , StringComparison . OrdinalIgnoreCase ) )
110- {
111116 yield return new FileInfo ( include ) ;
112- }
113117 }
114118 }
115119
@@ -128,6 +132,7 @@ public void Fix(DirectoryInfo directory)
128132 EnsureSpecFlow ( csproj ) ;
129133
130134 var fakeCsproj = SaveFakeCsProj ( directory , csproj ) ;
135+
131136 try
132137 {
133138 GenerateSpecFlowGlue ( directory , fakeCsproj , csproj ) ;
@@ -136,6 +141,7 @@ public void Fix(DirectoryInfo directory)
136141 {
137142 DeleteFakeCsProj ( fakeCsproj ) ;
138143 }
144+
139145 FixTests ( directory ) ;
140146
141147 if ( missingGeneratedFiles . Any ( ) )
@@ -150,19 +156,17 @@ private void EnsureSpecFlow(FileInfo csproj)
150156 if ( string . IsNullOrWhiteSpace ( _specFlowExe ) )
151157 {
152158 if ( ! TryGetSpecFlowVersion ( csproj , out _specFlowVersion ) )
153- {
154159 throw new XmlException ( "Could not get SpecFlow version from: " + csproj . FullName ) ;
155- }
156160
157161 _specFlowExe = FindSpecFlow ( _specFlowVersion ) ;
158162 WriteLine ( "Found: " + _specFlowExe ) ;
163+
159164 return ;
160165 }
161166
162167 if ( File . Exists ( _specFlowExe ) )
163- {
164168 return ;
165- }
169+
166170 throw new FileNotFoundException ( "Path to SpecFlow was supplied as an argument, but doesn't exist: " + _specFlowExe ) ;
167171 }
168172
@@ -209,6 +213,7 @@ private static string FixXunit(string content)
209213 {
210214 content = content . Replace ( " : Xunit.IUseFixture<" , " : Xunit.IClassFixture<" ) ;
211215 content = content . Replace ( "[Xunit.Extensions" , "[Xunit" ) ;
216+
212217 return content ;
213218 }
214219
@@ -223,10 +228,12 @@ private void RunSpecFlow(string csproj)
223228 {
224229 // Credit: http://www.marcusoft.net/2010/12/specflowexe-and-mstest.html
225230 var arguments = "generateall " ;
231+
226232 // Version 2.4.0 and higher require the -p parameter
227233 // Version 2.3.2 and below cannot work with the -p parameter so we can't add
228234 var projectParameterVersion = Version . Parse ( "2.4.0" ) ;
229235 var localSpecFlowVersion = Version . Parse ( _specFlowVersion ) ;
236+
230237 if ( localSpecFlowVersion >= projectParameterVersion )
231238 arguments += $@ "-p ""{ csproj } "" --force --verbose";
232239 else
0 commit comments