Skip to content

Commit

Permalink
Added WorkingDirectory property for #7471 (#7472)
Browse files Browse the repository at this point in the history
* Added WorkingDirectory property

* Updated PublicAPI.Unshipped.txt

* API list and Docs updated

* Unshipped API list updated
  • Loading branch information
egvijayanand committed May 31, 2024
1 parent d5ce8d1 commit d33e349
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 1 deletion.
6 changes: 5 additions & 1 deletion docs/Binding-and-project-context-evaluation.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:<param name>`, example: `host:HostIdentifier`.
- host parameters - parameters defined at certain host. For .NET SDK the following parameters are defined: `HostIdentifier: dotnetcli`, `GlobalJsonExists: true/false`, `WorkingDirectory: <dotnet_new_context_directory>`. Binding syntax is `host:<param name>`, example: `host:HostIdentifier`.
- environment variables - allows to bind environment variables. Binding syntax is `env:<environment variable name>`, example: `env:MYENVVAR`.

It is also possible to bind the parameter without the prefix as a fallback behavior: `HostIdentifier`, `MYENVVAR`.
Expand Down Expand Up @@ -37,6 +37,10 @@ The higher value indicates higher priority.
"HostIdentifier": {
"type": "bind",
"binding": "host:HostIdentifier"
},
"WorkingDirectory": {
"type": "bind",
"binding": "host:WorkingDirectory"
}
}
```
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<string> FallbackHostTemplateConfigNames { get; }

public string Version { get; }
Expand All @@ -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);
Expand Down
1 change: 1 addition & 0 deletions src/Microsoft.TemplateEngine.Edge/PublicAPI.Shipped.txt
Original file line number Diff line number Diff line change
Expand Up @@ -267,3 +267,4 @@ static Microsoft.TemplateEngine.Edge.Template.InputDataStateUtil.GetInputDataSta
static Microsoft.TemplateEngine.Edge.Template.TemplateEqualityComparer.Default.get -> System.Collections.Generic.IEqualityComparer<Microsoft.TemplateEngine.Abstractions.ITemplateInfo!>!
static Microsoft.TemplateEngine.Edge.Template.TemplateMatchInfoEqualityComparer.Default.get -> System.Collections.Generic.IEqualityComparer<Microsoft.TemplateEngine.Edge.Template.ITemplateMatchInfo!>!
~Microsoft.TemplateEngine.Edge.FilterableTemplateInfo.ParameterDefinitions.get -> Microsoft.TemplateEngine.Abstractions.Parameters.IParameterDefinitionSet
Microsoft.TemplateEngine.Edge.DefaultTemplateEngineHost.WorkingDirectory.get -> string!

0 comments on commit d33e349

Please sign in to comment.