Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes to add package command #1086

Merged
merged 5 commits into from
Jan 4, 2017
Merged

Fixes to add package command #1086

merged 5 commits into from
Jan 4, 2017

Conversation

mishra14
Copy link
Contributor

@mishra14 mishra14 commented Jan 4, 2017

Finishes work for : NuGet/Home#3751

Changes -

  1. Add logs to MsBuildAPIUtility.cs
  2. Fixed the way we read resolved version for a package from the restore result.
  3. Changed MsBuildAPIUtility to not add/update references in an imported file.

@emgarten @rrelyea

Copy link
Member

@emgarten emgarten left a comment

Choose a reason for hiding this comment

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

questions on error handling

@@ -24,6 +24,7 @@ namespace NuGet.XPlat.FuncTest
public class XPlatAddPkgTests
{
private static readonly string projectName = "test_project_addpkg";
private static MSBuildAPIUtility msBuild = new MSBuildAPIUtility(new TestCommandOutputLogger());
Copy link
Member

Choose a reason for hiding this comment

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

I would avoid sharing this between tests, you could make this a property that returns a new instance each time if needed though.

private const string UPDATE_OPERATION = "Update";
private const string REMOVE_OPERATION = "Remove";

public ILogger Logger { get; }
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 see a lot of state in this class beyond the logger. Maybe this should be a static class instead and the methods could take the logger as needed.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

discussed offline. Instantiable class allows mocking and easier unit testing.

.Select(f => NuGetFramework.Parse(f)));

restoreGraphs = restoreGraphs
.Where(r => userSpecifiedFrameworks.Contains(r.Framework));
Copy link
Member

Choose a reason for hiding this comment

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

What if the user accidentally specified a framework that doesn't exist in the project? a error message for that scenario might help, looks like it would just go on and possibly fail with an unrelated error message

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Addressed here

.Select(p => p)
.Where(p => p.Key.Name.Equals(packageReferenceArgs.PackageDependency.Id, StringComparison.OrdinalIgnoreCase));

if (matchingPackageEntries.Count() > 0)
Copy link
Member

Choose a reason for hiding this comment

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

nit: matchingPackageEntries.Any()

}
}

private NuGetVersion privateGetPackageVersionFromRestoreResult(RestoreResultPair restorePreviewResult,
Copy link
Member

Choose a reason for hiding this comment

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

private static NuGetVersion GetPackageVersionFromRestoreResult

it is a good practice to make methods static if possible, here there are no class fields or properties being used that I see

method names should be Camel cased per the C# style guidelines

// Get the package version from the graph
var resolvedVersion = privateGetPackageVersionFromRestoreResult(restorePreviewResult, packageReferenceArgs);

if (resolvedVersion != null)
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 see where null is being handled. If finding the highest version comes back as null it looks like this just keeps going

VersionRange.Parse(resolvedVersion.ToString()));
}
}
}
Copy link
Member

Choose a reason for hiding this comment

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

It might make the code more clear to just return the version here, it would be easier to handle errors as needed from a higher level.

@@ -398,4 +398,29 @@ For more information, visit http://docs.nuget.org/docs/reference/command-line-re
<data name="Error_NoDgSpec" xml:space="preserve">
<value>None or invalid DgSpec was passed to NuGet add package command.</value>
</data>
<data name="Error_AddPkgErrorStringForImportedEdit" xml:space="preserve">
<value>Item : {0} for {1} in Imported file : {2}</value>
Copy link
Member

Choose a reason for hiding this comment

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

Is this colon delimited format used anywhere else? I would expect this to feel very similar to the add project command if possible.

{
//Update the packagedependency with the new version
packageReferenceArgs.PackageDependency = new PackageDependency(packageReferenceArgs.PackageDependency.Id,
VersionRange.Parse(resolvedVersion.ToString()));
Copy link
Member

Choose a reason for hiding this comment

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

There's no need to parse this as a string. Just pass the resolvedVersion as the min version.

@mishra14 mishra14 merged commit 3a380d8 into dev Jan 4, 2017
@mishra14 mishra14 deleted the dev-anmishr-addrefpatch branch January 4, 2017 23:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants