Add support for easier CentralPackageManagement options
See original GitHub issueIs your feature request related to a problem? Please describe.
As CentralPacakgeManagement becomes more mainstream it is something we would like to offer as an option in our templates like:
dotnet new mytemplate -cpm
Currently we would need to have dependencies in our template like:
<ItemGroup>
<!--#if (useCentralPackageManagement)-->
<PackageReference Include="PackageA" />
<PackageReference Include="PackageB" />
<!--#else-->
<PackageReference Include="PackageA" Version="8.0.0" />
<PackageReference Include="PackageB" Version="8.0.0" />
<!--#endif-->
</ItemGroup>
Describe the solution you’d like.
Add a post action that can work from any host (VS/CLI/etc) which can remove versions on PackageReferences. This could be purpose build to strip out any PackageReference Version. Or to make this the most useful for a variety of situations perhaps a Regex Replace Post Action could be more useful.
"postActions": [{
"condition": "(useCentralPackageManagement)",
"description": "Removes the PackageReference Versions in the generated csproj.",
"args": {
"files": "**\\*.csproj",
"pattern": "(\\s?Version=\\\"\\d+\\.\\d+(.\\d+)?(.\\d+)?(-[A-Za-z\\.0-9]+)?\\\")",
"replace": ""
},
"manualInstructions": [{
"text": "Remove the PackageReference Versions'"
}],
"actionId": "Some Id",
"continueOnError": false
}]
Additional context
No response
Issue Analytics
- State:
- Created 7 months ago
- Comments:7 (7 by maintainers)
Top Results From Across the Web
Introducing Central Package Management - The NuGet Blog
Central Package Management. Dependency management is a core feature of NuGet. Managing dependencies for a single project can be easy.
Read more >Central Package Management
Manage your dependencies in a central location and how you can get started with central package management.
Read more >Centrally managing NuGet package versions
For a project that is opt-out from Central Package Version Management the install/unistall/update of package versions will work as currently.
Read more >Central Package Management for .NET Projects
It's a way of controlling versions of NuGet packages in a centralized location. This solution follows the modern pattern of using Directory.*.
Read more >How to centrally manage NuGet package versions within your ...
To get started, you need to create a file named Directory.Build.targets at the root of your solution that declares which packages and which ......
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@Evangelink , we are investigating the possibility of PostAction usage for resolving this issue. I will let you know once we know more.
Close due to the existing workaround described in https://github.com/dotnet/templating/issues/6187#issuecomment-1572223281.