Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added WorkingDirectory property for #7471 #7472

Merged
merged 6 commits into from
May 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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!