Skip to content

Replace JsonCli tool with direct nupkg parsing and native dotnet new#4947

Merged
nturinski merged 5 commits intomainfrom
nat/purgeJsonCliTool
Mar 31, 2026
Merged

Replace JsonCli tool with direct nupkg parsing and native dotnet new#4947
nturinski merged 5 commits intomainfrom
nat/purgeJsonCliTool

Conversation

@nturinski
Copy link
Copy Markdown
Member

Summary

Removes the Microsoft.TemplateEngine.JsonCli .NET tool and replaces it with:

  • Template listing: Direct parsing of .template.config/template.json files from nupkg archives (ZIP extraction via extract-zip). No .NET CLI required for listing.
  • Template creation: Native dotnet new install + dotnet new <shortName> with an isolated DOTNET_CLI_HOME to avoid polluting the user's global template state.

Changes

  • New: src/templates/dotnet/parseNupkgTemplates.ts — Extracts and parses template metadata from nupkg files, producing the same output shape consumed by parseDotnetTemplates.ts (zero changes needed there).
  • Rewritten: src/templates/dotnet/executeDotnetTemplateCommand.ts — List path reads nupkgs directly; create path uses dotnet new. Added DotnetTemplateOperation enum and itemNupkgFileName/projectNupkgFileName constants.
  • Updated: DotnetFunctionCreateStep.ts, DotnetProjectCreateStep.ts — Use executeDotnetTemplateCreate() with structured Record<string, string> args instead of JSON Cli-style --arg: flags.
  • Deleted: resources/dotnetJsonCli/ (13 shipped DLLs), tools/JsonCli/ (C# source, CI pipelines, build configs).
  • Cleaned up: .vscode/settings.json, .azure-pipelines/1esmain.yml, src/templates/README.md.

Motivation

Inspired by microsoft/vscode-containers#335 which replaced custom MSBuild targets with .NET's native -getProperty capability. Similarly, this removes a custom C# tool with its own build pipeline, code signing, and NuGet feed in favor of capabilities already built into the .NET SDK.

Copilot AI review requested due to automatic review settings March 30, 2026 23:50
@nturinski nturinski marked this pull request as ready for review March 30, 2026 23:52
@nturinski nturinski requested a review from a team as a code owner March 30, 2026 23:52
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR removes the shipped Microsoft.TemplateEngine.JsonCli toolchain and switches .NET template handling to (1) directly parse template metadata from item.nupkg/project.nupkg and (2) instantiate templates via native dotnet new install + dotnet new <shortName> using an isolated DOTNET_CLI_HOME.

Changes:

  • Add direct .nupkg parsing to list templates by reading .template.config/template.json.
  • Replace JsonCli-based template creation with native dotnet new flow (install + instantiate) using structured args.
  • Delete the JsonCli tool source/resources and remove related pipeline/editor configuration.

Reviewed changes

Copilot reviewed 26 out of 38 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
src/templates/dotnet/parseNupkgTemplates.ts New parser to extract template metadata from nupkg archives.
src/templates/dotnet/executeDotnetTemplateCommand.ts Reworked listing (parse nupkgs) and creation (native dotnet new with isolated CLI home).
src/templates/dotnet/DotnetTemplateProvider.ts Updates template listing call to use DotnetTemplateOperation.List.
src/commands/createFunction/dotnetSteps/DotnetFunctionCreateStep.ts Switches create flow to executeDotnetTemplateCreate with Record<string,string> args.
src/commands/createNewProject/ProjectCreateStep/DotnetProjectCreateStep.ts Switches project creation to executeDotnetTemplateCreate with structured args.
src/templates/README.md Updates documentation to reflect new nupkg parsing + dotnet new approach.
.vscode/settings.json Removes exclusion for the deleted JsonCli source tree.
.azure-pipelines/1esmain.yml Removes obsolete note about JsonCli pipeline handling C#.
tools/JsonCli/src/src.sln Deleted (JsonCli tool removal).
tools/JsonCli/src/Microsoft.TemplateEngine.JsonCli.csproj Deleted (JsonCli tool removal).
tools/JsonCli/src/Program.cs Deleted (JsonCli tool removal).
tools/JsonCli/src/Installer.cs Deleted (JsonCli tool removal).
tools/JsonCli/src/CommandLineParser.cs Deleted (JsonCli tool removal).
tools/JsonCli/src/Signing.csproj Deleted (JsonCli tool removal).
tools/JsonCli/src/nuget.config Deleted (JsonCli tool removal).
tools/JsonCli/src/Models/Models.cs Deleted (JsonCli tool removal).
tools/JsonCli/src/Package.cs Deleted (JsonCli tool removal).
tools/JsonCli/README.md Deleted (JsonCli tool removal).
tools/JsonCli/.vscode/* Deleted (JsonCli tool removal).
tools/JsonCli/.azure-pipelines/* Deleted (JsonCli tool removal).
resources/dotnetJsonCli/* Removed JsonCli shipped binaries/configs.

interface TemplateJson {
identity: string;
name: string;
shortName: string;
Copy link

Copilot AI Mar 30, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

template.json files can define shortName as an array (multiple short names). The current TemplateJson.shortName: string and ShortName: templateJson.shortName assumption can cause findShortNameByIdentity to return a non-string and break dotnet new <shortName> invocation. Consider supporting string | string[] and normalizing to a single short name (e.g., first entry) or throwing a clearer error if none are available.

Suggested change
shortName: string;
shortName: string | string[];

Copilot uses AI. Check for mistakes.
Comment on lines +99 to +106
// Use an isolated DOTNET_CLI_HOME so template installation doesn't affect the user's global state
// This is how the JSON CLI tool operateed
const tempCliHome = path.join(os.tmpdir(), `azfunc-dotnet-home-${Date.now()}-${Math.random().toString(36).substring(2)}`);
const prevDotnetCliHome = process.env.DOTNET_CLI_HOME;

try {
process.env.DOTNET_CLI_HOME = tempCliHome;

Copy link

Copilot AI Mar 30, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

executeDotnetTemplateCreate mutates process.env.DOTNET_CLI_HOME globally. If multiple template operations (or other .NET operations in the extension) run concurrently, this can lead to race conditions and cross-contamination of state. Prefer passing an env override per spawned process (and/or extending cpUtils.executeCommand to accept env) rather than mutating the global environment.

Copilot uses AI. Check for mistakes.
Comment thread src/templates/dotnet/executeDotnetTemplateCommand.ts Outdated
Comment on lines +73 to +80
export async function executeDotnetTemplateCreate(
context: IActionContext,
version: FuncVersion,
projTemplateKey: string,
workingDirectory: string | undefined,
identity: string,
templateArgs: Record<string, string>,
): Promise<void> {
Copy link

Copilot AI Mar 30, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

New behavior (nupkg template parsing + dotnet new install/dotnet new) is not directly covered by tests. Consider adding unit/integration tests that validate: (1) parsing of .template.config/template.json from the shipped backup nupkgs, including choice/boolean symbols and multi-shortName cases; and (2) executeDotnetTemplateCreate runs with an isolated template home and succeeds in generating output in a temp directory.

Copilot uses AI. Check for mistakes.
Nathan Turinski and others added 2 commits March 30, 2026 16:58
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Comment thread src/templates/dotnet/executeDotnetTemplateCommand.ts Outdated
Comment thread src/templates/dotnet/parseNupkgTemplates.ts Outdated
@nturinski nturinski enabled auto-merge (squash) March 31, 2026 16:52
@nturinski nturinski merged commit 039bd5e into main Mar 31, 2026
2 checks passed
@nturinski nturinski deleted the nat/purgeJsonCliTool branch March 31, 2026 16:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants