Replace JsonCli tool with direct nupkg parsing and native dotnet new#4947
Replace JsonCli tool with direct nupkg parsing and native dotnet new#4947
dotnet new#4947Conversation
There was a problem hiding this comment.
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
.nupkgparsing to list templates by reading.template.config/template.json. - Replace JsonCli-based template creation with native
dotnet newflow (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; |
There was a problem hiding this comment.
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.
| shortName: string; | |
| shortName: string | string[]; |
| // 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; | ||
|
|
There was a problem hiding this comment.
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.
| export async function executeDotnetTemplateCreate( | ||
| context: IActionContext, | ||
| version: FuncVersion, | ||
| projTemplateKey: string, | ||
| workingDirectory: string | undefined, | ||
| identity: string, | ||
| templateArgs: Record<string, string>, | ||
| ): Promise<void> { |
There was a problem hiding this comment.
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.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Summary
Removes the
Microsoft.TemplateEngine.JsonCli.NET tool and replaces it with:.template.config/template.jsonfiles from nupkg archives (ZIP extraction viaextract-zip). No .NET CLI required for listing.dotnet new install+dotnet new <shortName>with an isolatedDOTNET_CLI_HOMEto avoid polluting the user's global template state.Changes
src/templates/dotnet/parseNupkgTemplates.ts— Extracts and parses template metadata from nupkg files, producing the same output shape consumed byparseDotnetTemplates.ts(zero changes needed there).src/templates/dotnet/executeDotnetTemplateCommand.ts— List path reads nupkgs directly; create path usesdotnet new. AddedDotnetTemplateOperationenum anditemNupkgFileName/projectNupkgFileNameconstants.DotnetFunctionCreateStep.ts,DotnetProjectCreateStep.ts— UseexecuteDotnetTemplateCreate()with structuredRecord<string, string>args instead of JSON Cli-style--arg:flags.resources/dotnetJsonCli/(13 shipped DLLs),tools/JsonCli/(C# source, CI pipelines, build configs)..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
-getPropertycapability. 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.