File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -246,12 +246,12 @@ private void Parse(string file)
246246 break ;
247247 case "project" :
248248 var sdk = reader . GetAttribute ( "Sdk" ) ;
249- isSdkProjectStructureUsed |= sdk != null ;
249+ isSdkProjectStructureUsed |= sdk is not null ;
250250 useAspNetCoreDlls |= string . Equals ( sdk , "Microsoft.NET.Sdk.Web" , StringComparison . OrdinalIgnoreCase ) ;
251251 break ;
252252 case "frameworkreference" :
253253 var framework = reader . GetAttribute ( "Include" ) ;
254- isSdkProjectStructureUsed |= framework != null ;
254+ isSdkProjectStructureUsed |= framework is not null ;
255255 useAspNetCoreDlls |= string . Equals ( framework , "Microsoft.AspNetCore.App" , StringComparison . OrdinalIgnoreCase ) ;
256256 break ;
257257 case "implicitusings" :
@@ -271,8 +271,11 @@ private void Parse(string file)
271271 }
272272 break ;
273273 case "import" :
274- isLegacyProjectStructureUsed = isLegacyProjectStructureUsed || reader . GetAttribute ( "Project" ) ? . EndsWith ( "Microsoft.CSharp.targets" , StringComparison . OrdinalIgnoreCase ) == true ;
274+ var project = reader . GetAttribute ( "Project" ) ;
275+ isSdkProjectStructureUsed |= project is not null && reader . GetAttribute ( "Sdk" ) is not null ;
276+ isLegacyProjectStructureUsed = isLegacyProjectStructureUsed || project ? . EndsWith ( "Microsoft.CSharp.targets" , StringComparison . OrdinalIgnoreCase ) == true ;
275277 break ;
278+ // TODO: we could also check `<Sdk Name="Microsoft.NET.Sdk" />`
276279 }
277280 } ) ;
278281 }
Original file line number Diff line number Diff line change @@ -229,6 +229,24 @@ public void TestFileContent_SdkProjectStructure()
229229 Assert . False ( isLegacy ) ;
230230 }
231231
232+ /// <summary>
233+ /// Verifies that an SDK attribute on an import indicates SDK project structure.
234+ /// </summary>
235+ [ Fact ]
236+ public void TestFileContent_SdkProjectImport ( )
237+ {
238+ // Setup
239+ var fileContent = new TestFileContent ( "<Project><Import Project='Sdk.props' Sdk='Microsoft.NET.Sdk' /></Project>" ) ;
240+
241+ // Execute
242+ var isLegacy = fileContent . IsLegacyProjectStructureUsed ;
243+ var isSdk = fileContent . IsSdkProjectStructureUsed ;
244+
245+ // Verify
246+ Assert . True ( isSdk ) ;
247+ Assert . False ( isLegacy ) ;
248+ }
249+
232250 /// <summary>
233251 /// Verifies that `FileContent` correctly handles XML syntax with namespaces and various elements.
234252 /// </summary>
You can’t perform that action at this time.
0 commit comments