-
-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: improves Directory.Packages.props evaluation
- Loading branch information
1 parent
9b9aa61
commit c5b244b
Showing
15 changed files
with
1,011 additions
and
87 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,15 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
<Import Project="$(PackageDefaultsPropsPath)"/> | ||
<Import Project="$(PackageDefaultsPropsPath)" /> | ||
|
||
<PropertyGroup> | ||
<RootNamespace>DotnetAffected.Core</RootNamespace> | ||
</PropertyGroup> | ||
<ItemGroup> | ||
<ProjectReference Include="$(SourcesPath)/DotnetAffected.Abstractions/DotnetAffected.Abstractions.csproj"/> | ||
<ProjectReference Include="$(SourcesPath)/DotnetAffected.Abstractions/DotnetAffected.Abstractions.csproj" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Microsoft.Build.Prediction"/> | ||
<PackageReference Include="LibGit2Sharp"/> | ||
<PackageReference Include="Microsoft.Build.Prediction" /> | ||
<PackageReference Include="LibGit2Sharp" /> | ||
</ItemGroup> | ||
</Project> |
58 changes: 58 additions & 0 deletions
58
src/DotnetAffected.Core/FileSystem/EagerCachingMsBuildGitFileSystem.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
using LibGit2Sharp; | ||
using Microsoft.Build.Evaluation; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
|
||
namespace DotnetAffected.Core.FileSystem | ||
{ | ||
/// <summary> | ||
/// A wrapper around the git filesystem that works around the MSBuild issue https://github.com/dotnet/msbuild/issues/7956 <br/> | ||
/// The build process does not use the file system to ge the content of a file when it needs to load a nested project. <br/> | ||
/// It will only use the file system to query if a file exists or not, if it exist it will just load the file using the file system <para/> | ||
/// | ||
/// To workaround it we simply listen to all FileExists requests and if the file exists and it's part of the <see cref="MsBuildGitFileSystem.UseFileSystem">commit</see> | ||
/// we will eager load it on the spot, before the build will try to load it, so by the time the build loads it, it's in the cache. <br/> | ||
/// | ||
/// We only listen before we process the root file and stop right after the root is loaded. | ||
/// </summary> | ||
internal class EagerCachingMsBuildGitFileSystem : MsBuildGitFileSystem, IDisposable | ||
{ | ||
private readonly Commit? _commit; | ||
private ProjectFactory? _projectFactory; | ||
private Action<string>? _onEagerCacheRequired; | ||
|
||
public EagerCachingMsBuildGitFileSystem(Repository repository, Commit? commit) : base(repository, commit) | ||
{ | ||
_commit = commit; | ||
} | ||
|
||
/// <summary> | ||
/// Use this for File.Exists(path) | ||
/// </summary> | ||
public override bool FileExists(string path) | ||
{ | ||
var result = base.FileExists(path); | ||
if (result && !UseFileSystem(path)) | ||
_onEagerCacheRequired?.Invoke(path); | ||
return result; | ||
} | ||
|
||
public Project CreateProjectAndEagerLoadChildren(string path) | ||
{ | ||
var projects = new List<Project>(); | ||
_projectFactory ??= new ProjectFactory(this, new ProjectCollection()); | ||
|
||
_onEagerCacheRequired = s => projects.Add(_projectFactory.CreateProject(s)); | ||
projects.Add(_projectFactory.CreateProject(path)); | ||
_onEagerCacheRequired = null; | ||
|
||
return projects.Last(); | ||
} | ||
|
||
public void Dispose() | ||
{ | ||
_projectFactory?.Dispose(); | ||
} | ||
} | ||
} |
Oops, something went wrong.