Skip to content
Closed
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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Fixed

- Detect the dotnet packs folder on macOS and Linux

## [0.22.1] - 2026-08-23

### Fixed
Expand Down
36 changes: 36 additions & 0 deletions TypeContractor.Tests/Tool/ReflectionContextHelperTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
using TypeContractor.Tool;

namespace TypeContractor.Tests.Tool
{
public class ReflectionContextHelperTests
{
[Fact]
public void GetNetCorePack_Joins_Pack_Path_Without_Backslash()
{
var tempRoot = Path.Combine(Path.GetTempPath(), "typecontractor-" + Guid.NewGuid());
try
{
var expected = Path.Combine(tempRoot, "Microsoft.NETCore.App.Ref", "10.0.1", "ref", "net10.0");
Directory.CreateDirectory(expected);

var result = ReflectionContextHelper.GetNetCorePack(tempRoot, "Microsoft.NETCore.App.Ref", 10);

result.Should().Be(expected);
}
finally
{
if (Directory.Exists(tempRoot))
Directory.Delete(tempRoot, recursive: true);
}
}

[Fact]
public void GetDefaultPacksPath_Exists_And_Contains_NetCore_Ref_Pack()
{
var packsPath = ReflectionContextHelper.GetDefaultPacksPath();

Directory.Exists(packsPath).Should().BeTrue($"expected default packs path '{packsPath}' to exist");
Directory.Exists(Path.Combine(packsPath, "Microsoft.NETCore.App.Ref")).Should().BeTrue($"expected '{packsPath}' to contain 'Microsoft.NETCore.App.Ref'");
}
}
}
1 change: 1 addition & 0 deletions TypeContractor.Tests/TypeContractor.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@

<ItemGroup>
<ProjectReference Include="..\TypeContractor\TypeContractor.csproj" />
<ProjectReference Include="..\TypeContractor.Tool\TypeContractor.Tool.csproj" />
</ItemGroup>

</Project>
4 changes: 2 additions & 2 deletions TypeContractor.Tool/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,8 @@

var packsOptions = new Option<string>("--packs-path")
{
DefaultValueFactory = (arg) => config.GetStringWithFallback("packs-path", @"C:\Program Files\dotnet\packs\"),
Description = "Path where dotnet is installed and reference assemblies can be found.",
DefaultValueFactory = (arg) => config.GetStringWithFallback("packs-path", ReflectionContextHelper.GetDefaultPacksPath()),
Description = "Path where dotnet reference packs can be found. Defaults to the packs folder of the active .NET installation.",
};

var dotnetVersionOptions = new Option<int>("--dotnet-version")
Expand Down
7 changes: 6 additions & 1 deletion TypeContractor.Tool/ReflectionContextHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ internal static PathAssemblyResolver GetResolver(string packPath, int dotnetVers

internal static string? GetNetCorePack(string packPath, string packName, int dotnetVersion)
{
var packPrefix = @$"{packPath}\{packName}";
var packPrefix = Path.Combine(packPath, packName);
if (!Directory.Exists(packPrefix))
return null;

Expand All @@ -59,4 +59,9 @@ internal static PathAssemblyResolver GetResolver(string packPath, int dotnetVers

return packDirectory;
}

internal static string GetDefaultPacksPath() =>
Path.GetFullPath(Path.Combine(
RuntimeEnvironment.GetRuntimeDirectory(),
"..", "..", "..", "packs"));
}
4 changes: 4 additions & 0 deletions TypeContractor.Tool/TypeContractor.Tool.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@
<ProjectReference Include="..\TypeContractor\TypeContractor.csproj" />
</ItemGroup>

<ItemGroup>
<InternalsVisibleTo Include="TypeContractor.Tests" />
</ItemGroup>

<ItemGroup>
<None Include="..\LICENSE" Pack="true" PackagePath="\" />
<None Include="..\README.md" Pack="true" PackagePath="\" />
Expand Down