Skip to content

Commit

Permalink
remove unnecessary parameter, use boolean version of parameter
Browse files Browse the repository at this point in the history
  • Loading branch information
pragnya17 committed Jul 1, 2022
1 parent 7b81348 commit 6236de4
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public async Task<int> ExecuteCommand(PackageReferenceArgs packageReferenceArgs,
typeConstraint: LibraryDependencyTarget.Package)
};

msBuild.AddPackageReference(packageReferenceArgs.ProjectPath, libraryDependency, packageReferenceArgs.PackageVersion);
msBuild.AddPackageReference(packageReferenceArgs.ProjectPath, libraryDependency, packageReferenceArgs.NoVersion);
return 0;
}

Expand Down Expand Up @@ -219,7 +219,7 @@ public async Task<int> ExecuteCommand(PackageReferenceArgs packageReferenceArgs,
// generate a library dependency with all the metadata like Include, Exlude and SuppressParent
var libraryDependency = GenerateLibraryDependency(updatedPackageSpec, packageReferenceArgs, restorePreviewResult, userSpecifiedFrameworks, packageDependency);

msBuild.AddPackageReference(packageReferenceArgs.ProjectPath, libraryDependency, packageReferenceArgs.PackageVersion);
msBuild.AddPackageReference(packageReferenceArgs.ProjectPath, libraryDependency, packageReferenceArgs.NoVersion);
}
else
{
Expand All @@ -240,7 +240,7 @@ public async Task<int> ExecuteCommand(PackageReferenceArgs packageReferenceArgs,
msBuild.AddPackageReferencePerTFM(packageReferenceArgs.ProjectPath,
libraryDependency,
compatibleOriginalFrameworks,
packageReferenceArgs.PackageVersion);
packageReferenceArgs.NoVersion);
}

// 6. Commit restore result
Expand Down
24 changes: 12 additions & 12 deletions src/NuGet.Core/NuGet.CommandLine.XPlat/Utility/MSBuildAPIUtility.cs
Original file line number Diff line number Diff line change
Expand Up @@ -125,16 +125,16 @@ public int RemovePackageReference(string projectPath, LibraryDependency libraryD
/// </summary>
/// <param name="projectPath">Path to the csproj file of the project.</param>
/// <param name="libraryDependency">Package Dependency of the package to be added.</param>
/// <param name="packageVersion">The version that is passed in as a CLI argument. Null if no version is passed in the command.</param>
public void AddPackageReference(string projectPath, LibraryDependency libraryDependency, string packageVersion)
/// <param name="noVersion">If a version is passed in as a CLI argument.</param>
public void AddPackageReference(string projectPath, LibraryDependency libraryDependency, bool noVersion)
{
var project = GetProject(projectPath);

// Here we get package references for any framework.
// If the project has a conditional reference, then an unconditional reference is not added.

var existingPackageReferences = GetPackageReferencesForAllFrameworks(project, libraryDependency);
AddPackageReference(project, libraryDependency, existingPackageReferences, packageVersion);
AddPackageReference(project, libraryDependency, existingPackageReferences, noVersion);
ProjectCollection.GlobalProjectCollection.UnloadProject(project);
}

Expand All @@ -144,17 +144,17 @@ public void AddPackageReference(string projectPath, LibraryDependency libraryDep
/// <param name="projectPath">Path to the csproj file of the project.</param>
/// <param name="libraryDependency">Package Dependency of the package to be added.</param>
/// <param name="frameworks">Target Frameworks for which the package reference should be added.</param>
/// <param name="packageVersion">The version that is passed in as a CLI argument. Null if no version is passed in the command.</param>
/// <param name="noVersion">If a version is passed in as a CLI argument.</param>
public void AddPackageReferencePerTFM(string projectPath, LibraryDependency libraryDependency,
IEnumerable<string> frameworks, string packageVersion)
IEnumerable<string> frameworks, bool noVersion)
{
foreach (var framework in frameworks)
{
var globalProperties = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase)
{ { "TargetFramework", framework } };
var project = GetProject(projectPath, globalProperties);
var existingPackageReferences = GetPackageReferences(project, libraryDependency);
AddPackageReference(project, libraryDependency, existingPackageReferences, packageVersion, framework);
AddPackageReference(project, libraryDependency, existingPackageReferences, noVersion, framework);
ProjectCollection.GlobalProjectCollection.UnloadProject(project);
}
}
Expand All @@ -165,12 +165,12 @@ public void AddPackageReferencePerTFM(string projectPath, LibraryDependency libr
/// <param name="project">Project that needs to be modified.</param>
/// <param name="libraryDependency">Package Dependency of the package to be added.</param>
/// <param name="existingPackageReferences">Package references that already exist in the project.</param>
/// <param name="packageVersion">The version that is passed in as a CLI argument. Null if no version is passed in the command.</param>
/// <param name="noVersion">If a version is passed in as a CLI argument.</param>
/// <param name="framework">Target Framework for which the package reference should be added.</param>
private void AddPackageReference(Project project,
LibraryDependency libraryDependency,
IEnumerable<ProjectItem> existingPackageReferences,
string packageVersion,
bool noVersion,
string framework = null)
{
// Getting all the item groups in a given project
Expand Down Expand Up @@ -212,8 +212,9 @@ private void AddPackageReference(Project project,
else
{
// Modify the Directory.Packages.props file with the version that is passed in.
if (packageVersion != null)
if (!noVersion)
{
string packageVersion = libraryDependency.LibraryRange.VersionRange.OriginalString;
UpdatePackageVersion(project, packageVersionInProps, packageVersion);
}
}
Expand All @@ -234,7 +235,7 @@ private void AddPackageVersionIntoItemGroupCPM(Project project, LibraryDependenc

// Get the ItemGroup to add a PackageVersion to or create a new one.
var propsItemGroup = GetItemGroup(directoryBuildPropsRootElement.ItemGroups, PACKAGE_VERSION_TYPE_TAG) ?? directoryBuildPropsRootElement.AddItemGroup();
AddPackageVersionIntoPropsItemGroup(project, propsItemGroup, libraryDependency);
AddPackageVersionIntoPropsItemGroup(propsItemGroup, libraryDependency);

// Save the updated props file.
directoryBuildPropsRootElement.Save();
Expand All @@ -256,10 +257,9 @@ private ProjectRootElement GetDirectoryBuildPropsRootElement(Project project)
/// <summary>
/// Add package name and version into the props file.
/// </summary>
/// <param name="project">Project that is being modified.</param>
/// <param name="itemGroup">Item group that needs to be modified in the props file.</param>
/// <param name="libraryDependency">Package Dependency of the package to be added.</param>
private void AddPackageVersionIntoPropsItemGroup(Project project, ProjectItemGroupElement itemGroup,
private void AddPackageVersionIntoPropsItemGroup(ProjectItemGroupElement itemGroup,
LibraryDependency libraryDependency)
{
// Add both package reference information and version metadata using the PACKAGE_VERSION_TYPE_TAG.
Expand Down

0 comments on commit 6236de4

Please sign in to comment.