Skip to content
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public PackageCompilationAssemblyResolver()
}

public PackageCompilationAssemblyResolver(string nugetPackageDirectory)
: this(FileSystemWrapper.Default, new string[] { nugetPackageDirectory })
: this(FileSystemWrapper.Default, [nugetPackageDirectory])
{
}

Expand All @@ -46,32 +46,24 @@ internal static string[] GetDefaultProbeDirectories(IEnvironment environment)

if (!string.IsNullOrEmpty(listOfDirectories))
{
return listOfDirectories.Split(new char[] { Path.PathSeparator }, StringSplitOptions.RemoveEmptyEntries);
return listOfDirectories.Split([Path.PathSeparator], StringSplitOptions.RemoveEmptyEntries);
}

string? packageDirectory = environment.GetEnvironmentVariable("NUGET_PACKAGES");

if (!string.IsNullOrEmpty(packageDirectory))
{
return new string[] { packageDirectory };
return [packageDirectory];
}

string? basePath;
if (environment.IsWindows())
{
basePath = environment.GetEnvironmentVariable("USERPROFILE");
}
else
{
basePath = environment.GetEnvironmentVariable("HOME");
}
string basePath = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@ViktorHofer this is matching sdk and nuget streamlined behavior NuGet/NuGet.Client@310f5d4 dotnet/sdk@456aa42 using standard .net api to get profile directory cross platform instead of manually checking the environment variables.

Copy link
Member

Choose a reason for hiding this comment

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

I don't really have much context here but the changes LGTM


if (string.IsNullOrEmpty(basePath))
{
return new string[] { string.Empty };
return [string.Empty];
}

return new string[] { Path.Combine(basePath, ".nuget", "packages") };
return [Path.Combine(basePath, ".nuget", "packages")];
}

public bool TryResolveAssemblyPaths(CompilationLibrary library, List<string>? assemblies)
Expand Down Expand Up @@ -102,7 +94,7 @@ public bool TryResolveAssemblyPaths(CompilationLibrary library, List<string>? as

private static bool TryResolveFromPackagePath(IFileSystem fileSystem, CompilationLibrary library, string basePath, [MaybeNullWhen(false)] out IEnumerable<string> results)
{
var paths = new List<string>();
List<string> paths = [];

foreach (string assembly in library.Assemblies)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System;
using System.Collections.Generic;
using System.IO;
using FluentAssertions;
Expand Down Expand Up @@ -28,29 +29,14 @@ public void ShouldUseEnvironmentVariableToGetDefaultLocation()


[Fact]
public void ShouldUseNugetUnderUserProfileOnWindows()
public void ShouldUseNugetUnderUserProfile()
{
var environment = EnvironmentMockBuilder.Create()
.SetIsWindows(true)
.AddVariable("USERPROFILE", "User Profile")
.AddAppContextData("PROBING_DIRECTORIES", string.Empty)
.Build();

var result = PackageCompilationAssemblyResolver.GetDefaultProbeDirectories(environment);
result.Should().Contain(Path.Combine("User Profile", ".nuget", "packages"));
}

[Fact]
public void ShouldUseNugetUnderHomeOnNonWindows()
{
var environment = EnvironmentMockBuilder.Create()
.SetIsWindows(false)
.AddVariable("HOME", "User Home")
.AddAppContextData("PROBING_DIRECTORIES", string.Empty)
.Build();

var result = PackageCompilationAssemblyResolver.GetDefaultProbeDirectories(environment);
result.Should().Contain(Path.Combine("User Home", ".nuget", "packages"));
result.Should().Contain(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), ".nuget", "packages"));
}

[Fact]
Expand Down
Loading