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

PackageManagementFormat only updates settings when it has a value #6016

Merged
merged 2 commits into from
Sep 10, 2024

Conversation

donnie-msft
Copy link
Contributor

@donnie-msft donnie-msft commented Sep 7, 2024

Bug

Fixes: NuGet/Home#13773

Description

While testing VS Settings, I found that if I do not invoke getters on properties in this class, then call ApplyChanges two issues can occur:

  • Enabled property: an exception was thrown due to a nullable property being unset
  • SelectedPackageManagementFormat property: a "-1" was written to the nuget.config. This is never a valid value and should never be written to a nuget.config‼️

Check properties for valid values prior to updating settings.
Tests ensure that if no values are set, nothing is updated in settings, even though the call to Save still occurs. I didn't want to change any other workflow that may depend on this call to save to disk.

PR Checklist

  • Meaningful title, helpful description and a linked NuGet/Home issue
  • Added tests
  • Link to an issue or pull request to update docs if this PR changes settings, environment variables, new feature, etc.

@donnie-msft donnie-msft marked this pull request as ready for review September 7, 2024 03:51
@donnie-msft donnie-msft requested a review from a team as a code owner September 7, 2024 03:51
Copy link
Contributor

@jebriede jebriede left a comment

Choose a reason for hiding this comment

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

Good update! Approving with suggestion.

new AddItem(ConfigurationConstants.DefaultPackageManagementFormatKey, _selectedPackageFormat.ToString(CultureInfo.InvariantCulture)));
_settings.AddOrUpdate(ConfigurationConstants.PackageManagementSection,
new AddItem(ConfigurationConstants.DoNotShowPackageManagementSelectionKey, _showDialogValue.Value.ToString(CultureInfo.InvariantCulture)));
if (_selectedPackageFormat != -1)
Copy link
Contributor

Choose a reason for hiding this comment

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

To guard against any future code changes that could use another sentinel value (like -2, etc), you could make this:

Suggested change
if (_selectedPackageFormat != -1)
if (_selectedPackageFormat > -1)

@donnie-msft donnie-msft merged commit 785d8bb into dev Sep 10, 2024
28 checks passed
@donnie-msft donnie-msft deleted the dev-donnie-msft-packageManagementFormat branch September 10, 2024 13:18
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.

Saving PackageManagementFormat throws Nullable object must have a value.
3 participants