|
1 | 1 | using System; |
2 | 2 | using System.Collections.Generic; |
3 | 3 | using System.Composition; |
| 4 | +using System.Diagnostics; |
4 | 5 | using System.IO; |
5 | 6 | using System.Linq; |
6 | 7 | using Microsoft.Build.Execution; |
@@ -51,14 +52,27 @@ public void ProjectLoaded(ProjectLoadedEventArgs args) |
51 | 52 | var hashedReferences = GetHashedReferences(args); |
52 | 53 | var (hashedFileExtensions, fileCounts) = GetUniqueHashedFileExtensionsAndCounts(args); |
53 | 54 |
|
54 | | - _eventEmitter.ProjectInformation(projectId, sessionId, (int)outputKind, projectCapabilities, targetFrameworks, sdkVersion, hashedReferences, hashedFileExtensions, fileCounts); |
| 55 | + var sdkStyleProject = IsSdkStyleProject(args); |
| 56 | + _eventEmitter.ProjectInformation(projectId, sessionId, (int)outputKind, projectCapabilities, targetFrameworks, sdkVersion, hashedReferences, hashedFileExtensions, fileCounts, sdkStyleProject); |
55 | 57 | } |
56 | 58 | catch (Exception ex) |
57 | 59 | { |
58 | 60 | _logger.LogError("Unexpected exception got thrown from project load listener: " + ex); |
59 | 61 | } |
60 | 62 | } |
61 | 63 |
|
| 64 | + private static bool IsSdkStyleProject(ProjectLoadedEventArgs args) |
| 65 | + { |
| 66 | + // To see if a project is an SDK style project we check for either of two things |
| 67 | + // 1. If it has a TargetFramework / TargetFrameworks property. This isn't fully complete |
| 68 | + // as this property could come from a different props file |
| 69 | + // 2. If it imports an SDK. This can be defined multiple ways in the project file, but |
| 70 | + // we can look at the resolved imports after evaluation to see if any are SDK based. |
| 71 | + bool hasTargetFrameworkProperty = args.Project.Properties.Any(property => property.Name is "TargetFramework" or "TargetFrameworks"); |
| 72 | + bool importsSdk = args.Project.Imports.Any(import => import.SdkResult != null); |
| 73 | + return hasTargetFrameworkProperty || importsSdk; |
| 74 | + } |
| 75 | + |
62 | 76 | private static (IEnumerable<HashedString> Extensions, IEnumerable<int> Counts) GetUniqueHashedFileExtensionsAndCounts(ProjectLoadedEventArgs args) |
63 | 77 | { |
64 | 78 | var contentFiles = args.ProjectInstance |
|
0 commit comments