Skip to content

Commit

Permalink
[skip ci] Use boolean to see if package version is passed in as CLI a…
Browse files Browse the repository at this point in the history
…rg or not
  • Loading branch information
Pragnya Pandrate committed Jul 7, 2022
1 parent e3c1b34 commit 9030707
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 12 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
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 Down

0 comments on commit 9030707

Please sign in to comment.