Skip to content

Commit

Permalink
Merge pull request #10788 from rhyskoedijk/feature/tidy-packageconfig…
Browse files Browse the repository at this point in the history
…-packagereference-separation

Rename  SdkPackageUpdater => PackageReferenceUpdater, for clarity
  • Loading branch information
randhircs authored Oct 18, 2024
2 parents bf3e061 + 2e2c8bd commit 1c4db24
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace NuGetUpdater.Core.Test.Update;

public partial class UpdateWorkerTests
{
public class Sdk : UpdateWorkerTestBase
public class PackageReference : UpdateWorkerTestBase
{
[Theory]
[InlineData("net472")]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,16 @@ internal static class BindingRedirectManager
private static readonly XName DependentAssemblyName = AssemblyBinding.GetQualifiedName("dependentAssembly");
private static readonly XName BindingRedirectName = AssemblyBinding.GetQualifiedName("bindingRedirect");

/// <summary>
/// Updates assembly binding redirects for a project build file.
/// </summary>
/// <remarks>
/// Assembly binding redirects are only applicable to projects targeting .NET Framework.
/// .NET Framework targets can appear in SDK-style OR non-SDK-style project files, using either packages.config OR `<PackageReference>` MSBuild items.
/// See: https://learn.microsoft.com/en-us/dotnet/framework/configure-apps/redirect-assembly-versions
/// https://learn.microsoft.com/en-us/nuget/resources/check-project-format
/// </remarks>
/// <param name="projectBuildFile">The project build file (*.xproj) to be updated</param>
public static async ValueTask UpdateBindingRedirectsAsync(ProjectBuildFile projectBuildFile)
{
var configFile = await TryGetRuntimeConfigurationFile(projectBuildFile);
Expand All @@ -33,7 +43,7 @@ public static async ValueTask UpdateBindingRedirectsAsync(ProjectBuildFile proje
var bindings = BindingRedirectResolver.GetBindingRedirects(projectBuildFile.Path, references.Select(static x => x.Include));
if (!bindings.Any())
{
// no bindings to update
// no bindings found in the project file, nothing to update
return;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,18 @@

namespace NuGetUpdater.Core;

internal static class SdkPackageUpdater
/// <summary>
/// Handles package updates for projects containing `<PackageReference>` MSBuild items.
/// </summary>
/// <remarks>
/// PackageReference items can appear in both SDK-style AND non-SDK-style project files.
/// By default, PackageReference is used by [SDK-style] projects targeting .NET Core, .NET Standard, and UWP.
/// By default, packages.config is used by [non-SDK-style] projects targeting .NET Framework; However, they can be migrated to PackageReference too.
/// See: https://learn.microsoft.com/en-us/nuget/consume-packages/package-references-in-project-files#project-type-support
/// https://learn.microsoft.com/en-us/nuget/consume-packages/migrate-packages-config-to-package-reference
/// https://learn.microsoft.com/en-us/nuget/resources/check-project-format
/// </remarks>
internal static class PackageReferenceUpdater
{
public static async Task UpdateDependencyAsync(
string repoRootPath,
Expand All @@ -17,8 +28,8 @@ public static async Task UpdateDependencyAsync(
bool isTransitive,
ILogger logger)
{
// SDK-style project, modify the XML directly
logger.Log(" Running for SDK-style project");
// PackageReference project; modify the XML directly
logger.Log(" Running 'PackageReference' project direct XML update");

(ImmutableArray<ProjectBuildFile> buildFiles, string[] tfms) = await MSBuildHelper.LoadBuildFilesAndTargetFrameworksAsync(repoRootPath, projectPath);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,14 @@

namespace NuGetUpdater.Core;

/// <summary>
/// Handles package updates for projects that use packages.config.
/// </summary>
/// <remarks>
/// packages.config can appear in non-SDK-style projects, but not in SDK-style projects.
/// See: https://learn.microsoft.com/en-us/nuget/reference/packages-config
/// https://learn.microsoft.com/en-us/nuget/resources/check-project-format
/// <remarks>
internal static class PackagesConfigUpdater
{
public static async Task UpdateDependencyAsync(
Expand All @@ -25,9 +33,8 @@ public static async Task UpdateDependencyAsync(
ILogger logger
)
{
logger.Log($" Found {NuGetHelper.PackagesConfigFileName}; running with NuGet.exe");

// use NuGet.exe to perform update
// packages.config project; use NuGet.exe to perform update
logger.Log($" Found '{NuGetHelper.PackagesConfigFileName}' project; running NuGet.exe update");

// ensure local packages directory exists
var projectBuildFile = ProjectBuildFile.Open(repoRootPath, projectPath);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ private async Task RunUpdaterAsync(
}

// Some repos use a mix of packages.config and PackageReference
await SdkPackageUpdater.UpdateDependencyAsync(repoRootPath, projectPath, dependencyName, previousDependencyVersion, newDependencyVersion, isTransitive, _logger);
await PackageReferenceUpdater.UpdateDependencyAsync(repoRootPath, projectPath, dependencyName, previousDependencyVersion, newDependencyVersion, isTransitive, _logger);

// Update lock file if exists
if (File.Exists(Path.Combine(Path.GetDirectoryName(projectPath), "packages.lock.json")))
Expand Down

0 comments on commit 1c4db24

Please sign in to comment.