Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
Make the toolsResolverCache path overridable using an environment var…
…iable. Fixes #11432.

Fixes #11432.
  • Loading branch information
rolfbjarne committed Sep 19, 2024
commit c540e6f69e03e35af5d6ea46ee13c1f63f2d1608
3 changes: 3 additions & 0 deletions documentation/manpages/sdk/dotnet-environment-variables.7
Original file line number Diff line number Diff line change
Expand Up @@ -452,6 +452,9 @@ Configures the default programming language for the \f[V]dotnet new\f[R] command
The default value is \f[V]C#\f[R].
Valid values are \f[V]C#\f[R], \f[V]F#\f[R], or \f[V]VB\f[R].
For more information, see dotnet new.
.SS \f[V]DOTNET_TOOLS_RESOLVER_CACHE_FOLDER\f[R]
.PP
Overrides the default location ($HOME/.dotnet/toolResolverCache) for the shim files for locally installed tools.
Comment on lines +555 to +557
Copy link

Copilot AI Dec 10, 2025

Choose a reason for hiding this comment

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

According to repository guidelines, files under documentation/manpages/sdk are generated and should not be manually modified. These changes should be made to the source documentation files instead, and the manpages should be regenerated from those sources.

Copilot generated this review using guidance from repository custom instructions.
.SH \f[V]dotnet watch\f[R] ENVIRONMENT VARIABLES
.PP
For information about \f[V]dotnet watch\f[R] settings that are available as environment variables, see dotnet watch environment variables.
Expand Down
2 changes: 1 addition & 1 deletion documentation/manpages/sdk/dotnet-tool-install.1
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ They\[cq]re stored in the same way as global tools: an executable binary with th
.SS Local tools
.PP
Local tools are stored in the NuGet global directory, whatever you\[cq]ve set that to be.
There are shim files in \f[V]$HOME/.dotnet/toolResolverCache\f[R] for each local tool that point to where the tools are within that location.
There are shim files in \f[V]$HOME/.dotnet/toolResolverCache\f[R] for each local tool that point to where the tools are within that location (this path can be overridden with the \f[V]DOTNET_TOOLS_RESOLVER_CACHE_FOLDER\f[R] environment variable).
Copy link

Copilot AI Dec 10, 2025

Choose a reason for hiding this comment

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

According to repository guidelines, files under documentation/manpages/sdk are generated and should not be manually modified. These changes should be made to the source documentation files instead, and the manpages should be regenerated from those sources.

Copilot generated this review using guidance from repository custom instructions.
.PP
References to local tools are added to a \f[I]dotnet-tools.json\f[R] file in a \f[I].config\f[R] directory under the current directory.
If a manifest file doesn\[cq]t exist yet, create it by using the \f[V]--create-manifest-if-needed\f[R] option or by running the following command:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,9 @@ public static string WindowsNonExpandedToolsShimPath
public static string DotnetUserProfileFolderPath =>
Path.Combine(DotnetHomePath, DotnetProfileDirectoryName);

public static string ToolsResolverCachePath => Path.Combine(DotnetUserProfileFolderPath, ToolsResolverCacheFolderName);
public static string ToolsResolverCachePath =>
Environment.GetEnvironmentVariable("DOTNET_TOOLS_RESOLVER_CACHE_FOLDER") ??
Path.Combine(DotnetUserProfileFolderPath, ToolsResolverCacheFolderName);
Copy link

Copilot AI Dec 10, 2025

Choose a reason for hiding this comment

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

Inconsistent indentation: This line has an extra space. It should align with line 18 (12 spaces of indentation), but appears to have 13 spaces. Please adjust the indentation to match the pattern used in lines 17-18.

Suggested change
Path.Combine(DotnetUserProfileFolderPath, ToolsResolverCacheFolderName);
Path.Combine(DotnetUserProfileFolderPath, ToolsResolverCacheFolderName);

Copilot uses AI. Check for mistakes.

public static string PlatformHomeVariableName => CliFolderPathCalculatorCore.PlatformHomeVariableName;

Expand Down
49 changes: 49 additions & 0 deletions test/dotnet.Tests/CommandTests/ToolRestoreCommandTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -437,6 +437,55 @@ public void ItRestoresCorrectToolVersion()
rows[0].Version.Should().Be("8.0.0-rc.1.23419.6");
}

[Fact]
public void ItRestoresCorrectToolVersionWithOverriddenResolverCachePath()
{
var testDir = _testAssetsManager.CreateTestDirectory().Path;

string configContents = """
{
"version": 1,
"isRoot": true,
"tools": {
"dotnet-ef": {
"version": "8.0.0-rc.1.23419.6",
"commands": [
"dotnet-ef"
]
}
}
}
""";

File.WriteAllText(Path.Combine(testDir, "dotnet-tools.json"), configContents);

string CliHome = Path.Combine(testDir, ".home");
Directory.CreateDirectory(CliHome);

var toolsResolverCacheFolder = Path.Combine(testDir, "toolsResolverCache");
var toolRestoreCommand = new DotnetCommand(Log, "tool", "restore")
.WithEnvironmentVariable("DOTNET_CLI_HOME", CliHome)
.WithEnvironmentVariable("DOTNET_SKIP_WORKLOAD_INTEGRITY_CHECK", "true")
.WithEnvironmentVariable("DOTNET_TOOLS_RESOLVER_CACHE_FOLDER", toolsResolverCacheFolder)
.WithWorkingDirectory(testDir);

toolRestoreCommand
.Execute()
.Should()
.Pass();

var cacheFilePath = Path.Combine(toolsResolverCacheFolder, "1", "dotnet-ef");

string json = File.ReadAllText(cacheFilePath);

var rows = JsonSerializer.Deserialize<List<CacheRow>>(json);

rows.Count.Should().Be(1);

rows[0].Name.Should().Be("dotnet-ef");
rows[0].Version.Should().Be("8.0.0-rc.1.23419.6");
}

[Fact]
public void WhenCannotFindManifestFileItPrintsWarning()
{
Expand Down