@@ -142,6 +142,7 @@ public static bool FrameworkHasAValueTuple(string tfm) =>
142142 tfm . StartsWith ( MSBuildFacts . NetstandardPrelude , StringComparison . OrdinalIgnoreCase )
143143 || tfm . StartsWith ( MSBuildFacts . NetcoreappPrelude , StringComparison . OrdinalIgnoreCase )
144144 || tfm . StartsWith ( MSBuildFacts . Net5 , StringComparison . OrdinalIgnoreCase )
145+ || tfm . StartsWith ( MSBuildFacts . Net6 , StringComparison . OrdinalIgnoreCase )
145146 || tfm . StartsWith ( MSBuildFacts . LowestFrameworkVersionWithSystemValueTuple , StringComparison . OrdinalIgnoreCase ) ;
146147
147148 /// <summary>
@@ -150,6 +151,12 @@ public static bool FrameworkHasAValueTuple(string tfm) =>
150151 private static IEnumerable < ProjectItemElement > GetReferences ( ProjectItemGroupElement itemGroup ) =>
151152 itemGroup . Items . Where ( item => item . ElementName . Equals ( MSBuildFacts . MSBuildReferenceName , StringComparison . OrdinalIgnoreCase ) ) ;
152153
154+ /// <summary>
155+ /// Gets all PackageReference items from a given item group.
156+ /// </summary>
157+ private static IEnumerable < ProjectItemElement > GetPackageReferences ( ProjectItemGroupElement itemGroup ) =>
158+ itemGroup . Items . Where ( item => item . ElementName . Equals ( MSBuildFacts . MSBuildPackageReferenceName , StringComparison . OrdinalIgnoreCase ) ) ;
159+
153160 /// <summary>
154161 /// Checks if a root has a project type guids node.
155162 /// </summary>
@@ -211,6 +218,26 @@ public static bool IsDesktop(IProjectRootElement projectRoot)
211218 }
212219 }
213220
221+ /// <summary>
222+ /// Determines if a given project is UWP
223+ /// </summary>
224+ public static bool IsUwp ( IProjectRootElement projectRoot )
225+ {
226+ if ( projectRoot . PropertyGroups . Any ( g => g . Properties . Any ( p => p . Name == "TargetPlatformIdentifier" && p . Value == "UAP" ) ) )
227+ {
228+ return true ;
229+ }
230+ var packageReferences = projectRoot . ItemGroups . SelectMany ( GetPackageReferences ) ? . Select ( elem => elem . Include . Split ( ',' ) . First ( ) ) ;
231+ if ( packageReferences is null )
232+ {
233+ return false ;
234+ }
235+ else
236+ {
237+ return DesktopFacts . KnownUwpReferences . Any ( reference => packageReferences . Contains ( reference , StringComparer . OrdinalIgnoreCase ) ) ;
238+ }
239+ }
240+
214241 /// <summary>
215242 /// Determines if a given project references ASP.NET assemblies.
216243 /// </summary>
@@ -240,7 +267,7 @@ public static bool IsWebApp(IProjectRootElement projectRoot) =>
240267 /// </summary>
241268 public static bool IsAspNetCore ( IProjectRootElement projectRoot , string tfm ) =>
242269 IsWebApp ( projectRoot ) || projectRoot . Sdk . Equals ( WebFacts . WebSDKAttribute )
243- || ( IsWeb ( projectRoot ) && new [ ] { MSBuildFacts . Net5 , MSBuildFacts . NetcoreappPrelude } . Any ( s => tfm . StartsWith ( s , StringComparison . OrdinalIgnoreCase ) ) ) ;
270+ || ( IsWeb ( projectRoot ) && new [ ] { MSBuildFacts . Net6 , MSBuildFacts . Net5 , MSBuildFacts . NetcoreappPrelude } . Any ( s => tfm . StartsWith ( s , StringComparison . OrdinalIgnoreCase ) ) ) ;
244271
245272 /// <summary>
246273 /// Determines if a project is a .NET Framework MSTest project by looking at its references.
@@ -273,6 +300,12 @@ public static bool IsNotNetFramework(string tfm) =>
273300 ! tfm . ContainsIgnoreCase ( MSBuildFacts . NetcoreappPrelude )
274301 && ! tfm . ContainsIgnoreCase ( MSBuildFacts . NetstandardPrelude ) ;
275302
303+ /// <summary>
304+ /// Checks if a given TFM include -windows
305+ /// </summary>
306+ public static bool IsWindows ( string tfm ) =>
307+ tfm . ContainsIgnoreCase ( MSBuildFacts . WindowsSuffix ) ;
308+
276309 /// <summary>
277310 /// Finds the item group where a packages.config is included. Assumes only one.
278311 /// </summary>
@@ -295,6 +328,11 @@ public static ProjectItemElement GetPackagesConfigItem(ProjectItemGroupElement p
295328 /// </summary>
296329 public static void AddUseWPF ( ProjectPropertyGroupElement propGroup ) => propGroup . AddProperty ( DesktopFacts . UseWPFPropertyName , "true" ) ;
297330
331+ /// <summary>
332+ /// Adds the UseWinUI=true property to the top-level project property group.
333+ /// </summary>
334+ public static void AddUseWinUI ( ProjectPropertyGroupElement propGroup ) => propGroup . AddProperty ( DesktopFacts . UseWinUIPropertyName , "true" ) ;
335+
298336 /// <summary>
299337 /// Adds the ImportWindowsDesktopTargets=true property to ensure builds targeting .NET Framework will succeed.
300338 /// </summary>
@@ -368,7 +406,7 @@ public static bool ArePropertyGroupElementsIdentical(ProjectPropertyGroupElement
368406 /// <returns>true if string is successfuly unquoted</returns>
369407 private static bool UnquoteString ( ref string s )
370408 {
371- if ( s . Length < 2 || s [ 0 ] != '\' ' || s [ ^ 1 ] != '\' ' )
409+ if ( s . Length < 2 || s [ 0 ] != '\' ' || s [ ^ 1 ] != '\' ' || s [ 1 .. ^ 1 ] . Contains ( ' \' ' ) )
372410 {
373411 return false ;
374412 }
0 commit comments