-
Notifications
You must be signed in to change notification settings - Fork 395
Open
Description
Issue with managing SDK templates for custom host - duplicates and updates
Hey folks! I'm working on a C# IDE plugin for neovim, therefore I am trying to integrate with Microsoft.TemplateEngine. I'm trying to define a custom host using Microsoft.TemplateEngine.IDE.Bootstrapper and running into some challenges around template management. Would love some guidance on the best approach here.
What I'm trying to do
I want to create my own custom host (makes sense since some templates have constraints like if!dotnet-cli), and I'd like to:
- Automatically install all the templates that show up when running
dotnet new --list - Avoid having duplicate versions of the same template package installed
- Update templates when newer versions are available
The problem
I'm finding packages from the SDK at C:\Program Files\dotnet\templates\{version}\*.nupkg and installing them, but I keep running into issues with duplicates. It seems like:
- When I install packages, they get copied to
C:\Users\{user}\.templateengine\packages\ - Some package identifiers include version numbers (like
Microsoft.DotNet.Common.ProjectTemplates.10.0vsMicrosoft.DotNet.Common.ProjectTemplates.9.0) - This makes it tricky to dedupe by
Identifiersince different major versions have different identifiers - I'm getting stuck in a loop where certain packages (like WinForms and WPF templates) keep getting installed and then uninstalled
What I'm currently doing
// Install missing packages
var installedFilenames = installedPackages.Select(p => Path.GetFileName(new Uri(p.MountPointUri).LocalPath));
var missing = nupkgs.Where(nupkg => !installedFilenames.Contains(Path.GetFileName(nupkg)));
await bootstrapper.InstallTemplatePackagesAsync(missing, InstallationScope.Global, cancellationToken);
// Try to dedupe by Identifier
var dupes = installedPackages.GroupBy(p => p.Identifier).Where(g => g.Count() > 1);
await bootstrapper.UninstallTemplatePackagesAsync(dupes.SelectMany(g => g.Skip(1)), cancellationToken);
// Check for updates
await bootstrapper.UpdateTemplatePackagesAsync(...);Questions
- What's the recommended way to sync SDK templates to a custom host without creating duplicates?
- Should I be comparing by
Identifier, filename, or something else? - How should I handle packages where the major version is part of the identifier (like
*.ProjectTemplates.9.0vs*.ProjectTemplates.10.0)? - Is there a simpler/better pattern I'm missing here?
Any pointers would be super helpful! Thanks!
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels