KEMBAR78
Add support for easier CentralPackageManagement options · Issue #6187 · dotnet/templating · GitHub
Skip to content

Add support for easier CentralPackageManagement options #6187

@dansiegel

Description

@dansiegel

Is 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

Metadata

Metadata

Assignees

Labels

area:package-managementgathering-feedbackThe issue requires feedback in order to be planned, please comment if the feature is useful for youhelp-wantedgood opportunity for contribution to the repotriagedThe issue was evaluated by the triage team, placed on correct area, next action defined.

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions