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

Rename SdkPackageUpdater => PackageReferenceUpdater, for clarity #10788

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
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
Loading