Skip to content

Commit 7299d08

Browse files
authored
Merge pull request #2502 from dibarbet/report_old_style_csproj
Report to the client if the project being loaded is sdk style
2 parents d6ef83d + 9cf0ffb commit 7299d08

3 files changed

Lines changed: 20 additions & 3 deletions

File tree

src/OmniSharp.Abstractions/Eventing/IEventEmitterExtensions.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,8 @@ public static void ProjectInformation(this IEventEmitter emitter,
5454
HashedString sdkVersion,
5555
IEnumerable<HashedString> references,
5656
IEnumerable<HashedString> fileExtensions,
57-
IEnumerable<int> fileCounts)
57+
IEnumerable<int> fileCounts,
58+
bool sdkStyleProject)
5859
{
5960
var projectConfiguration = new ProjectConfigurationMessage()
6061
{
@@ -66,7 +67,8 @@ public static void ProjectInformation(this IEventEmitter emitter,
6667
SessionId = sessionId.Value,
6768
References = references.Select(hashed => hashed.Value),
6869
FileExtensions = fileExtensions.Select(hashed => hashed.Value),
69-
FileCounts = fileCounts
70+
FileCounts = fileCounts,
71+
SdkStyleProject = sdkStyleProject
7072
};
7173

7274
emitter.Emit(

src/OmniSharp.Abstractions/Models/Events/ProjectConfigurationMessage.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,6 @@ public class ProjectConfigurationMessage
1414
public IEnumerable<string> References { get; set; }
1515
public IEnumerable<string> FileExtensions { get; set; }
1616
public IEnumerable<int> FileCounts { get; set; }
17+
public bool SdkStyleProject { get; set; }
1718
}
1819
}

src/OmniSharp.MSBuild/ProjectLoadListener.cs

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using System;
22
using System.Collections.Generic;
33
using System.Composition;
4+
using System.Diagnostics;
45
using System.IO;
56
using System.Linq;
67
using Microsoft.Build.Execution;
@@ -51,14 +52,27 @@ public void ProjectLoaded(ProjectLoadedEventArgs args)
5152
var hashedReferences = GetHashedReferences(args);
5253
var (hashedFileExtensions, fileCounts) = GetUniqueHashedFileExtensionsAndCounts(args);
5354

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);
5557
}
5658
catch (Exception ex)
5759
{
5860
_logger.LogError("Unexpected exception got thrown from project load listener: " + ex);
5961
}
6062
}
6163

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+
6276
private static (IEnumerable<HashedString> Extensions, IEnumerable<int> Counts) GetUniqueHashedFileExtensionsAndCounts(ProjectLoadedEventArgs args)
6377
{
6478
var contentFiles = args.ProjectInstance

0 commit comments

Comments
 (0)