Skip to content

Commit

Permalink
Use Microsoft.Build.Locator to fix project evaluation
Browse files Browse the repository at this point in the history
  • Loading branch information
ReMinoer committed Oct 19, 2021
1 parent eb1ce72 commit 06cd350
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
10 changes: 10 additions & 0 deletions Sources/SubSolution.MsBuild/MsBuildProjectReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using System.Text;
using System.Threading.Tasks;
using Microsoft.Build.Evaluation;
using Microsoft.Build.Locator;
using Microsoft.Extensions.Logging;
using SubSolution.ProjectReaders;

Expand All @@ -17,6 +18,11 @@ public class MsBuildProjectReader : IProjectReader
private readonly ILogger? _logger;
public LogLevel LogLevel { get; set; } = LogLevel.Trace;

static MsBuildProjectReader()
{
MSBuildLocator.RegisterDefaults();
}

public MsBuildProjectReader(ILogger? logger = null)
{
_logger = logger;
Expand Down Expand Up @@ -195,6 +201,10 @@ static private void ReadConfigurationPlatformsConditions(Project project, Soluti
{
solutionProject.Configurations.AddRange(conditionedConfigurations!);
}
else
{
throw new ProjectReadException(project.FullPath, "No configuration found.");
}

if (hasPlatforms)
{
Expand Down
4 changes: 3 additions & 1 deletion Sources/SubSolution.MsBuild/SubSolution.MsBuild.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@
<Description>Library using MsBuild as dependency to implement SubSolution default project reader.</Description>
</PropertyGroup>

<!-- Use version 15.1.548 to support VS2017 and later. Exclude at runtime since the locator will find exisitng MSBuild. -->
<ItemGroup>
<PackageReference Include="Microsoft.Build" Version="16.11.0" />
<PackageReference Include="Microsoft.Build" Version="15.1.548" ExcludeAssets="runtime" />
<PackageReference Include="Microsoft.Build.Locator" Version="1.4.1" />
</ItemGroup>

<ItemGroup>
Expand Down

0 comments on commit 06cd350

Please sign in to comment.