Skip to content

Commit a426f3e

Browse files
authored
make containers net472 target resilient to incorrectly-determined DOTNET_HOST_PATH values (#49736)
1 parent bf31345 commit a426f3e

File tree

1 file changed

+21
-1
lines changed

1 file changed

+21
-1
lines changed

src/Containers/Microsoft.NET.Build.Containers/Tasks/CreateNewImageToolTask.cs

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,17 +22,37 @@ private string DotNetPath
2222
{
2323
get
2424
{
25+
// DOTNET_HOST_PATH, if set, is the full path to the dotnet host executable.
26+
// However, not all environments/scenarios set it correctly - some set it to just the directory.
27+
28+
// this is the expected correct case - DOTNET_HOST_PATH is set to the full path of the dotnet host executable
2529
string path = Environment.GetEnvironmentVariable("DOTNET_HOST_PATH") ?? "";
30+
if (Path.IsPathRooted(path) && File.Exists(path))
31+
{
32+
return path;
33+
}
34+
// some environments set it to just the directory, so we need to check that too
35+
if (Path.IsPathRooted(path) && Directory.Exists(path))
36+
{
37+
path = Path.Combine(path, ToolExe);
38+
if (File.Exists(path))
39+
{
40+
return path;
41+
}
42+
}
43+
// last-chance fallback - use the ToolPath and ToolExe properties to try to synthesize the path
2644
if (string.IsNullOrEmpty(path))
2745
{
46+
// no
2847
path = string.IsNullOrEmpty(ToolPath) ? "" : ToolPath;
48+
path = Path.Combine(path, ToolExe);
2949
}
3050

3151
return path;
3252
}
3353
}
3454

35-
protected override string GenerateFullPathToTool() => Path.Combine(DotNetPath, ToolExe);
55+
protected override string GenerateFullPathToTool() => DotNetPath;
3656

3757
/// <summary>
3858
/// Workaround to avoid storing user/pass into the EnvironmentVariables property, which gets logged by the task.

0 commit comments

Comments
 (0)