This article is a mirror article of machine translation, please click here to jump to the original article.

View: 3379|Reply: 2

[Communication] .NET Project Setup Central Package Management (CPM)

[Copy link]
Posted on 3/16/2024 6:27:01 PM | | | |
Requirements: Java developers can use dependencyManagement for package management in maven projects, and now .NET solutions also support package management. The same version is used when the project in the solution references the same package name.

Prerequisite, this feature is available for all NuGet integration tools, starting with the following versions.

  • Visual Studio 2022 17.2
  • .NET SDK 6.0.300
  • nuget.exe 6.2.0


Create a new solution

Create a new solution, a console application, and a class library, all of which reference the same versionNewtonsoft.Jsonpackage, as follows:



Enable central package management

To get started with Central Package Management, you must create a Directory.Packages.props file in the root directory of the repository and set the MSBuild property ManagePackageVersionsCentrally to true.

Then, in it, define each corresponding package version required for the project using the <PackageVersion/> element that defines the package ID and version.

Then, define a <PackageReference/> for each item, but omit the Version property, as the version will be obtained from the corresponding <PackageVersion/> item.

Now you can use the central package management and manage your releases in one centralized location! As shown below:



dotnet-tocpm tool

Dotnet global tool for converting solutions to Nuget CPM. When it comes to large solutions with multiple projects, switching to Nuget CPM can be a pain. dotnet-tocpm is designed to do this in one simple step.

First, install the tool globally with the following command:

First, run the simulate command for a trial run, as follows:



After checking that there are no errors, use the execute command to enable central package management, as follows:



Reference:The hyperlink login is visible.
The hyperlink login is visible.
The hyperlink login is visible.





Previous:Git Change Repository Address (Clone to New Repository)
Next:Windows 11 can't create a new notepad file (text document)
 Landlord| Posted on 3/16/2024 6:43:59 PM |
.NET 9 has a Directory.Packages.props template, which can be created through the template command, without manual creation, and can be viewed with the following command:


Create a central package command:

 Landlord| Posted on 6/1/2025 4:51:42 PM |
.NET/C# Solution Project Import References (Unified Version)
https://www.itsvse.com/thread-11015-1-1.html
Disclaimer:
All software, programming materials or articles published by Code Farmer Network are only for learning and research purposes; The above content shall not be used for commercial or illegal purposes, otherwise, users shall bear all consequences. The information on this site comes from the Internet, and copyright disputes have nothing to do with this site. You must completely delete the above content from your computer within 24 hours of downloading. If you like the program, please support genuine software, purchase registration, and get better genuine services. If there is any infringement, please contact us by email.

Mail To:help@itsvse.com