Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
53 commits
Select commit Hold shift + click to select a range
708f4e2
applied changes from pragnya17-dotnet-nuget-why
advay26 Mar 28, 2024
10245f8
cleaning up some old code
advay26 Mar 28, 2024
2098b79
wipping
advay26 Apr 3, 2024
3d428bc
fixed duplicate paths bug
advay26 Apr 3, 2024
db9a7ce
trees are beautiful
advay26 Apr 5, 2024
ef25ca2
rip my sleep schedule
advay26 Apr 5, 2024
9170c26
everything works now
advay26 Apr 5, 2024
b1b74f5
refactoring
advay26 Apr 6, 2024
067430a
cleaning up strings
advay26 Apr 6, 2024
08e95fc
fixed redundant traversal bug
advay26 Apr 7, 2024
ae50998
minor string stuff
advay26 Apr 8, 2024
3f153f9
remove (*) deduplication, fix project reference bug
advay26 Apr 10, 2024
8a750f1
wip: recursion -> stack
advay26 Apr 16, 2024
25804a8
recursion -> stack is working now
advay26 Apr 17, 2024
a44299b
wipping
advay26 Apr 18, 2024
073e9b5
removed TODOs to clean up
advay26 Apr 18, 2024
7ed373a
added basic test; failed to run basic test;
advay26 Apr 21, 2024
aaee328
test stubs - commented out
advay26 Apr 22, 2024
ebc4732
cleanup + removed debugging code
advay26 Apr 23, 2024
4a42f3e
Moved files to diff folder
advay26 Apr 23, 2024
d9a6482
experimenting with tests
advay26 Apr 24, 2024
904740e
started addressing feedback, but wow it's a lot of work
advay26 May 3, 2024
69bfb3b
adjusted tests to static class
advay26 May 3, 2024
cb0c043
wip
advay26 May 7, 2024
e55583a
nit
advay26 May 8, 2024
7891af4
temp: working on project refs
advay26 May 9, 2024
fa67ec9
still wipping....
advay26 May 9, 2024
961b7df
added tests, TODOs for targetAlias matching in GetResolvedVersions; r…
advay26 May 10, 2024
cf5771f
added new test files, will fill them out later
advay26 May 10, 2024
efaee79
fixed failing test
advay26 May 10, 2024
0bba3a1
addressin smore feedback
advay26 May 10, 2024
8ee8eba
added func tests + dotnet integration tests
advay26 May 13, 2024
31a6bf3
cleaning up for PR
advay26 May 13, 2024
5c3ad52
cleaning up
advay26 May 13, 2024
852edf0
register dotnet nuget/package * commands separately
advay26 May 15, 2024
923a1df
moved print methods out to new class
advay26 May 15, 2024
527d448
wip: addressing feedback, trialing new method for top level packages/…
advay26 May 15, 2024
506ee92
refactoring
advay26 May 16, 2024
1297105
reverted MSBuildAPIUtility changes
advay26 May 16, 2024
fec9de8
nit
advay26 May 16, 2024
b164b31
fixed tests (at least locally)
advay26 May 16, 2024
2a1c576
whitespace changes?
advay26 May 16, 2024
dccf34c
added unit tests, fixed func tests, + some small nits
advay26 May 16, 2024
50394da
removed unnecessary param
advay26 May 16, 2024
8f3db89
trying to fix 'fully qualified path' error on linux and mac tests
advay26 May 16, 2024
d9c8890
address feedback, try to fix unit tests path issue
advay26 May 29, 2024
6074b25
fixed whitespace issue
advay26 May 29, 2024
7aceac8
fixed unit test path issue for remaining file paths
advay26 May 29, 2024
8aff030
trying to fix integration tests
advay26 May 29, 2024
ee68859
removed WhyCommandUtility sub directory
advay26 May 29, 2024
118735d
oops
advay26 May 29, 2024
7b9a2e9
please work
advay26 May 30, 2024
4a60b13
skip non-sdk stype projects + some more null dereference handling
advay26 May 31, 2024
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
Prev Previous commit
skip non-sdk stype projects + some more null dereference handling
  • Loading branch information
advay26 committed May 31, 2024
commit 4a60b1374dd776605e678eea96fca99024f3dd3b
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,13 @@ internal static class DependencyGraphFinder
{
foreach (var (targetFrameworkAlias, topLevelReferences) in topLevelReferencesByFramework)
{
LockFileTarget target = assetsFile.GetTarget(targetFrameworkAlias, runtimeIdentifier: null);
LockFileTarget? target = assetsFile.GetTarget(targetFrameworkAlias, runtimeIdentifier: null);

// get all package libraries for the framework
IList<LockFileTargetLibrary> packageLibraries = target.Libraries;
IList<LockFileTargetLibrary>? packageLibraries = target?.Libraries;

// if the project has a dependency on the target package, get the dependency graph
if (packageLibraries.Any(l => l?.Name?.Equals(targetPackage, StringComparison.OrdinalIgnoreCase) == true))
if (packageLibraries?.Any(l => l?.Name?.Equals(targetPackage, StringComparison.OrdinalIgnoreCase) == true) == true)
{
doesProjectHaveDependencyOnPackage = true;
dependencyGraphPerFramework.Add(targetFrameworkAlias,
Expand Down Expand Up @@ -272,7 +272,7 @@ private static Dictionary<string, List<string>> GetTopLevelPackageAndProjectRefe
/// <param name="packageLibraries">All package libraries for a given framework.</param>
private static Dictionary<string, string> GetAllResolvedVersions(IList<LockFileTargetLibrary> packageLibraries)
{
var versions = new Dictionary<string, string>();
var versions = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase);

foreach (var package in packageLibraries)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,35 +39,48 @@ public static int ExecuteCommand(WhyCommandArgs whyCommandArgs)
foreach (var projectPath in projectPaths)
{
Project project = MSBuildAPIUtility.GetProject(projectPath);
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe we can enhance the MSBuildAPIUtility to just return the ProjectAndSolution type instead of selecting only the paths in GetProjectsFromSolution. That way, you wouldn't need convert the paths back to projects, here.

I'm not familiar with these types, so let's see if @jeffkl has opinions on this.

LockFile? assetsFile = GetProjectAssetsFile(project, whyCommandArgs.Logger);

if (assetsFile != null)
{
ValidateFrameworksOptions(assetsFile, whyCommandArgs.Frameworks, whyCommandArgs.Logger);
string usingNetSdk = project.GetPropertyValue("UsingMicrosoftNETSdk");

Dictionary<string, List<DependencyNode>?>? dependencyGraphPerFramework = DependencyGraphFinder.GetAllDependencyGraphsForTarget(
assetsFile,
whyCommandArgs.Package,
whyCommandArgs.Frameworks);
if (!string.IsNullOrEmpty(usingNetSdk))
{
LockFile? assetsFile = GetProjectAssetsFile(project, whyCommandArgs.Logger);

if (dependencyGraphPerFramework != null)
if (assetsFile != null)
{
whyCommandArgs.Logger.LogMinimal(
string.Format(
Strings.WhyCommand_Message_DependencyGraphsFoundInProject,
assetsFile.PackageSpec.Name,
targetPackage));

DependencyGraphPrinter.PrintAllDependencyGraphs(dependencyGraphPerFramework, targetPackage, whyCommandArgs.Logger);
ValidateFrameworksOptions(assetsFile, whyCommandArgs.Frameworks, whyCommandArgs.Logger);

Dictionary<string, List<DependencyNode>?>? dependencyGraphPerFramework = DependencyGraphFinder.GetAllDependencyGraphsForTarget(
assetsFile,
whyCommandArgs.Package,
whyCommandArgs.Frameworks);

if (dependencyGraphPerFramework != null)
{
whyCommandArgs.Logger.LogMinimal(
string.Format(
Strings.WhyCommand_Message_DependencyGraphsFoundInProject,
assetsFile.PackageSpec.Name,
targetPackage));

DependencyGraphPrinter.PrintAllDependencyGraphs(dependencyGraphPerFramework, targetPackage, whyCommandArgs.Logger);
}
else
{
whyCommandArgs.Logger.LogMinimal(
string.Format(
Strings.WhyCommand_Message_NoDependencyGraphsFoundInProject,
assetsFile.PackageSpec.Name,
targetPackage));
}
}
else
{
whyCommandArgs.Logger.LogMinimal(
}
else
{
whyCommandArgs.Logger.LogMinimal(
string.Format(
Strings.WhyCommand_Message_NoDependencyGraphsFoundInProject,
assetsFile.PackageSpec.Name,
targetPackage));
}
Strings.WhyCommand_Message_NonSDKStyleProjectsAreNotSupported,
project.GetPropertyValue("MSBuildProjectName")));
}

ProjectCollection.GlobalProjectCollection.UnloadProject(project);
Expand Down
9 changes: 9 additions & 0 deletions src/NuGet.Core/NuGet.CommandLine.XPlat/Strings.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions src/NuGet.Core/NuGet.CommandLine.XPlat/Strings.resx
Original file line number Diff line number Diff line change
Expand Up @@ -932,6 +932,9 @@ Non-HTTPS access will be removed in a future version. Consider migrating to 'HTT
<value>Unable to run 'dotnet nuget why'. Missing or invalid project/solution file '{0}'.</value>
<comment>{0} - Project/solution file path</comment>
</data>
<data name="WhyCommand_Message_NonSDKStyleProjectsAreNotSupported" xml:space="preserve">
<value>Unable to run 'dotnet nuget why' for project '{0}'. This command only works on SDK-style projects.</value>
</data>
<data name="WhyCommand_Error_InvalidAssetsFile" xml:space="preserve">
<value>The assets file {0} is invalid. Please run restore for project '{1}' before running this command.</value>
<comment>{0} - Assets file path, {1} - Project name</comment>
Expand Down