You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This applies even when the parameter is used multiple times in the expression:
35
+
36
+
```csharp
37
+
// ✅ Correct
38
+
xml.Descendants("PackageVersion")
39
+
.FirstOrDefault(_=>
40
+
string.Equals(
41
+
_.Attribute("Include")?.Value,
42
+
packageName,
43
+
StringComparison.OrdinalIgnoreCase))
44
+
45
+
// ❌ Incorrect
46
+
xml.Descendants("PackageVersion")
47
+
.FirstOrDefault(e=>
48
+
string.Equals(
49
+
e.Attribute("Include")?.Value,
50
+
packageName,
51
+
StringComparison.OrdinalIgnoreCase))
52
+
```
53
+
54
+
**Exception:** Use descriptive parameter names when creating complex anonymous types or when the lambda body is long and clarity would benefit from a meaningful name:
55
+
56
+
```csharp
57
+
// Named parameter acceptable for complex Select projections
Copy file name to clipboardExpand all lines: readme.md
+193Lines changed: 193 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -317,6 +317,199 @@ The next time you run the updater, it will update to the latest version.
317
317
- Comments and formatting around pinned packages are preserved during updates
318
318
319
319
320
+
## Automatic Package Migration
321
+
322
+
323
+
### Overview
324
+
325
+
PackageUpdate automatically detects and migrates deprecated NuGet packages to their recommended alternatives. When a package is marked as deprecated on NuGet.org with an alternative package specified, the tool will automatically replace it during updates.
326
+
327
+
328
+
### How It Works
329
+
330
+
When updating packages, PackageUpdate:
331
+
332
+
1. Checks if the **current version** of each package is marked as deprecated
333
+
2. If an alternative package is specified in the deprecation metadata:
334
+
- Verifies the alternative package exists in configured NuGet sources
335
+
- Checks that the alternative doesn't already exist in `Directory.Packages.props`
336
+
- Replaces the package reference with the alternative
337
+
- Sets the version to the latest available version of the alternative
Package WindowsAzure.Storage is deprecated with alternative Azure.Storage.Common, but alternative already exists
409
+
```
410
+
411
+
Both packages remain in the file, and only `Azure.Storage.Common` gets updated to the latest version.
412
+
413
+
414
+
#### When No Alternative is Available
415
+
416
+
If a package is deprecated but has no alternative specified, the tool logs a warning and continues with normal version update:
417
+
418
+
```
419
+
Package SomeDeprecatedPackage is deprecated but has no alternative. Reasons: Legacy
420
+
```
421
+
422
+
423
+
#### Current Version Check
424
+
425
+
The tool only migrates if the **current** version you're using is deprecated. If you're on an older, non-deprecated version, and only newer versions are deprecated, no migration occurs. This prevents unnecessary migrations when you're deliberately staying on an older version.
426
+
427
+
428
+
#### Specific Package Flag
429
+
430
+
The migration feature works with the `--package` flag:
431
+
432
+
```bash
433
+
packageupdate --package WindowsAzure.Storage
434
+
```
435
+
436
+
If `WindowsAzure.Storage` is deprecated with an alternative, it will be migrated automatically.
437
+
438
+
439
+
### Common Scenarios
440
+
441
+
442
+
#### Scenario 1: Microsoft Azure SDK Packages
443
+
444
+
Many older Azure SDK packages have been deprecated in favor of the new Azure SDK:
445
+
446
+
-`WindowsAzure.Storage` → `Azure.Storage.Common` or `Azure.Storage.Blobs`
Package WindowsAzure.Storage is deprecated with alternative Azure.Storage.Common, but alternative already exists
488
+
```
489
+
490
+
491
+
#### Migration Skipped (No Alternative)
492
+
493
+
```
494
+
Package MyOldPackage is deprecated but has no alternative. Reasons: Legacy, Critical Bugs
495
+
```
496
+
497
+
498
+
#### Migration Skipped (Alternative Not Found)
499
+
500
+
```
501
+
Package OldPackage is deprecated with alternative NewPackage, but alternative not found in sources
502
+
```
503
+
504
+
505
+
### Technical Details
506
+
507
+
- Migration uses NuGet's official deprecation metadata API (`PackageDeprecationMetadata`)
508
+
- The `AlternatePackage` information comes directly from package authors via NuGet.org
509
+
- File formatting, comments, and XML structure are preserved during migration
510
+
- Migrations are logged distinctly from version updates for clarity
511
+
512
+
320
513
## Icon
321
514
322
515
[Update](https://thenounproject.com/search/?q=update&i=2060555) by [Andy Miranda](https://thenounproject.com/andylontuan88) from [The Noun Project](https://thenounproject.com/).
0 commit comments