From d33e349fa5a3b5b502fc640160bd44beffdd88d3 Mon Sep 17 00:00:00 2001 From: Vijay Anand E G <81947404+egvijayanand@users.noreply.github.com> Date: Fri, 31 May 2024 23:12:37 +0530 Subject: [PATCH] Added WorkingDirectory property for #7471 (#7472) * Added WorkingDirectory property * Updated PublicAPI.Unshipped.txt * API list and Docs updated * Unshipped API list updated --- docs/Binding-and-project-context-evaluation.md | 6 +++++- .../DefaultTemplateEngineHost.cs | 7 +++++++ src/Microsoft.TemplateEngine.Edge/PublicAPI.Shipped.txt | 1 + 3 files changed, 13 insertions(+), 1 deletion(-) diff --git a/docs/Binding-and-project-context-evaluation.md b/docs/Binding-and-project-context-evaluation.md index f4ce729bfa..a951d7936b 100644 --- a/docs/Binding-and-project-context-evaluation.md +++ b/docs/Binding-and-project-context-evaluation.md @@ -9,7 +9,7 @@ The feature is available for both `dotnet new` and Visual Studio. The symbol binds value from external sources. By default, the following sources are available: -- host parameters - parameters defined at certain host. For .NET SDK the following parameters are defined: `HostIdentifier: dotnetcli`, `GlobalJsonExists: true/false`. Binding syntax is `host:`, example: `host:HostIdentifier`. +- host parameters - parameters defined at certain host. For .NET SDK the following parameters are defined: `HostIdentifier: dotnetcli`, `GlobalJsonExists: true/false`, `WorkingDirectory: `. Binding syntax is `host:`, example: `host:HostIdentifier`. - environment variables - allows to bind environment variables. Binding syntax is `env:`, example: `env:MYENVVAR`. It is also possible to bind the parameter without the prefix as a fallback behavior: `HostIdentifier`, `MYENVVAR`. @@ -37,6 +37,10 @@ The higher value indicates higher priority. "HostIdentifier": { "type": "bind", "binding": "host:HostIdentifier" + }, + "WorkingDirectory": { + "type": "bind", + "binding": "host:WorkingDirectory" } } ``` diff --git a/src/Microsoft.TemplateEngine.Edge/DefaultTemplateEngineHost.cs b/src/Microsoft.TemplateEngine.Edge/DefaultTemplateEngineHost.cs index 98b198a587..1c893a25be 100644 --- a/src/Microsoft.TemplateEngine.Edge/DefaultTemplateEngineHost.cs +++ b/src/Microsoft.TemplateEngine.Edge/DefaultTemplateEngineHost.cs @@ -37,12 +37,16 @@ public DefaultTemplateEngineHost( loggerFactory ??= NullLoggerFactory.Instance; _loggerFactory = loggerFactory; _logger = _loggerFactory.CreateLogger("Template Engine") ?? NullLogger.Instance; + + WorkingDirectory = Environment.CurrentDirectory; } public IPhysicalFileSystem FileSystem { get; private set; } public string HostIdentifier { get; } + public string WorkingDirectory { get; } + public IReadOnlyList FallbackHostTemplateConfigNames { get; } public string Version { get; } @@ -61,6 +65,9 @@ public virtual bool TryGetHostParamDefault(string paramName, out string? value) case "HostIdentifier": value = HostIdentifier; return true; + case "WorkingDirectory": + value = WorkingDirectory; + return true; } return _hostDefaults.TryGetValue(paramName, out value); diff --git a/src/Microsoft.TemplateEngine.Edge/PublicAPI.Shipped.txt b/src/Microsoft.TemplateEngine.Edge/PublicAPI.Shipped.txt index bb4433c540..276f69f40b 100644 --- a/src/Microsoft.TemplateEngine.Edge/PublicAPI.Shipped.txt +++ b/src/Microsoft.TemplateEngine.Edge/PublicAPI.Shipped.txt @@ -267,3 +267,4 @@ static Microsoft.TemplateEngine.Edge.Template.InputDataStateUtil.GetInputDataSta static Microsoft.TemplateEngine.Edge.Template.TemplateEqualityComparer.Default.get -> System.Collections.Generic.IEqualityComparer! static Microsoft.TemplateEngine.Edge.Template.TemplateMatchInfoEqualityComparer.Default.get -> System.Collections.Generic.IEqualityComparer! ~Microsoft.TemplateEngine.Edge.FilterableTemplateInfo.ParameterDefinitions.get -> Microsoft.TemplateEngine.Abstractions.Parameters.IParameterDefinitionSet +Microsoft.TemplateEngine.Edge.DefaultTemplateEngineHost.WorkingDirectory.get -> string! \ No newline at end of file