Skip to content
This repository was archived by the owner on Mar 31, 2026. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 32 additions & 3 deletions Commands/SolutionParserCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -129,20 +129,49 @@ private void ExecuteCore(string? solutionFilePath, string? solutionFolderPath)
Console.WriteLine(jsonStr);
}

static string? GetFirstFramework(MSProject proj, out bool hasMultipleFrameworks)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure has this API is exactly used in VSCode extension.
But for VisualStudio extension we prioritize plain "netx.0" target framework over platform specific, and macos/windows as a second choice (if on that platform).

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For example, if project has "net8.0-ios" as a first framework, previewer will still fail.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As for SolutionParserCommand, it would make sense to return multiple projects in this situation. So, the caller can decide which framework to use (in this case, VSCode extension).

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will the language server handle multiple entries for the same .csproj file? If so it would make sense to add a project entry for each framework listed.

{
hasMultipleFrameworks = false;
var targetfx = proj.GetPropertyValue("TargetFramework");
if (!string.IsNullOrEmpty(targetfx))
{
return targetfx;
}
var targetFrameworks = proj.GetPropertyValue("TargetFrameworks");
if (string.IsNullOrEmpty(targetFrameworks))
{
return null;
}
hasMultipleFrameworks = true;
return targetFrameworks.Split(";").FirstOrDefault();
}

Project? GetProjectDetails(string name, string projPath)
{
try
{
var loadSettings = ProjectLoadSettings.IgnoreMissingImports | ProjectLoadSettings.FailOnUnresolvedSdk;
var proj = MSProject.FromFile(projPath, new ProjectOptions
{
LoadSettings = ProjectLoadSettings.IgnoreMissingImports | ProjectLoadSettings.FailOnUnresolvedSdk
LoadSettings = loadSettings
});

var targetfx = GetFirstFramework(proj, out var hasMultipleFrameworks);

if (hasMultipleFrameworks && !string.IsNullOrEmpty(targetfx))
{
proj = MSProject.FromFile(projPath, new ProjectOptions {
LoadSettings = loadSettings,
GlobalProperties = new Dictionary<string, string> {
{"TargetFramework", targetfx}
}
});
}

var assembly = proj.GetPropertyValue("TargetPath");
var outputType = proj.GetPropertyValue("outputType");
var desingerHostPath = proj.GetPropertyValue("AvaloniaPreviewerNetCoreToolPath");

var targetfx = proj.GetPropertyValue("TargetFramework");
var projectDepsFilePath = proj.GetPropertyValue("ProjectDepsFilePath");
var projectRuntimeConfigFilePath = proj.GetPropertyValue("ProjectRuntimeConfigFilePath");

Expand All @@ -160,7 +189,7 @@ private void ExecuteCore(string? solutionFilePath, string? solutionFolderPath)
OutputType = outputType,
DesignerHostPath = desingerHostPath,

TargetFramework = targetfx,
TargetFramework = targetfx ?? "",
DepsFilePath = projectDepsFilePath,
RuntimeConfigFilePath = projectRuntimeConfigFilePath,

Expand Down
4 changes: 2 additions & 2 deletions SolutionParser.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net9.0</TargetFramework>
<TargetFramework>net10.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
Expand All @@ -14,4 +14,4 @@
<PackageReference Include="Microsoft.Build.Utilities.Core" Version="17.11.4" ExcludeAssets="runtime" />
<PackageReference Include="Microsoft.Build.Locator" Version="1.7.8" />
</ItemGroup>
</Project>
</Project>