-
Notifications
You must be signed in to change notification settings - Fork 399
Constraints
| Constraint | type |
|---|---|
| Operating system | os |
| Running template engine host | host |
| Installed workloads | workload |
| Current SDK version | sdk-version |
| Project capabilities | project-capability |
The feature is available since .NET SDK 7.0.100. The template may define constraints, all of which must be met in order for the template to be usable. In case constraints are not met, the template will be installed, however will not be visible nor used by default.
The constraints are defined under constraints top-level property in template.json. constraints contains objects (constraint definition). Each constraint should have a unique name, and the following properties:
-
type: (string) - constraint type (mandatory) -
args: (string, array, object) - constraint arguments - depend on actual constraint implementation. May be optional.
Example template.json:
}
// other template elements
"constraints": {
"windows-only": { // Custom name - not validated
"type": "os", // Type of the constraint - used to match to proper Constraint component to evaluate the constraint
"args": "Windows" // Arguments passed to the evaluating constraint component
}
}
}Restrict the template instantiation to certain operating system.
Configuration:
-
type:os -
args: (string, array) - list of supported operating systems. Possible values are:Windows,Linux,OSX.
Supported in:
- all hosts (by default). 3rd party host may explicitly disable the constraint.
"constraints": {
"linux-only": {
"type": "os",
"args": "Linux"
},
}"constraints": {
"linux-and-osx": {
"type": "os",
"args": [ "Linux", "OSX" ]
},
}Restrict template to be run only in certain application and its version. The following host identifiers are available:
-
dotnetcli- .NET SDK -
vs- Visual Studio -
vs-mac- Visual Studio for Mac -
ide- may refer to both Visual Studio and Visual Studio for Mac -
dotnetcli-preview-dotnet new3command (used for debugging testing)
3rd party applications may define other host identifiers.
Configuration:
-
type:host -
args(array). Mandatory. Array elements can have following properties:-
hostname: (string) - the host identifier (see above) -
version: (string, optional) - supported version, or version range. If not specified, all the versions are supported.
-
Supported in:
- all hosts (by default). 3rd party host may explicitly disable the constraint.
The version and version range syntax is explained here.
The parsing is done in following order:
- exact version syntax (
1.0.0) - floating version syntax (
1.*) - version range syntax (
(1.0,))
Supported on .NET SDK 6.
"constraints": {
"sdk-only": {
"type": "host",
"args": [
{
"hostname": "dotnetcli",
"version": "6.0.*"
}
]
},
}Supported from .NET SDK 6.
"constraints": {
"sdk-only": {
"type": "host",
"args": [
{
"hostname": "dotnetcli",
"version": "[6.0,)"
}
]
},
}Supported in .NET SDK and Visual Studio
"constraints": {
"sdk-only": {
"type": "host",
"args": [
{
"hostname": "dotnetcli"
},
{
"hostname": "vs"
},
]
},
}