You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/msbuild/property-functions.md
+24-24Lines changed: 24 additions & 24 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -16,13 +16,13 @@ Property functions are calls to .NET methods that appear in MSBuild property def
16
16
17
17
Unlike tasks, property functions can be used outside of targets. Property functions are evaluated whenever the properties or items get expanded. So, for properties and items outside of any targets, property functions are evaluated before any target runs. For property groups and item groups inside targets, property functions are evaluated when the target is executed.
18
18
19
-
Without using MSBuild tasks, you can read the system time, compare strings, match regular expressions, and perform other actions in your build script. MSBuild will try to convert string to number and number to string, and make other conversions as required.
19
+
Without using MSBuild tasks, you can read the system time, compare strings, match regular expressions, and perform other actions in your build script. MSBuild tries to convert string to number and number to string, and make other conversions as required.
20
20
21
21
String values returned from property functions have [special characters](msbuild-special-characters.md) escaped. If you want the value to be treated as though it was put directly in the project file, use `$([MSBuild]::Unescape())` to unescape the special characters.
22
22
23
23
## Property function syntax
24
24
25
-
These are three kinds of property functions; each function has a different syntax:
25
+
There are three kinds of property functions; each kind has a different syntax:
26
26
27
27
- String (instance) property functions
28
28
- Static property functions
@@ -62,7 +62,7 @@ For example, to set a build property to a new GUID, you can use this script:
62
62
<NewGuid>$([System.Guid]::NewGuid())</NewGuid>
63
63
```
64
64
65
-
In static property functions, you can use any public static method or property that's defined in .NET Standard 2.0 for these system classes:
65
+
In static property functions, you can use any public static method or property defined in .NET Standard 2.0 for these system classes:
> Methods and properties that aren't defined in .NET Standard 2.0 might be available when you use MSBuild in an environment that supports them, but can't be guaranteed to be available in all situations. For compatibility reasons, they are best avoided.
97
+
> Methods and properties that aren't defined in .NET Standard 2.0 might be available when you use MSBuild in an environment that supports them, but can't be guaranteed to be available in all situations. For compatibility reasons, they're best avoided.
98
98
99
99
In addition, you can use the following static methods and properties:
100
100
@@ -137,11 +137,11 @@ In addition, you can use the following static methods and properties:
137
137
:::moniker range=">=vs-2022"
138
138
#### System.OperatingSystem property functions
139
139
140
-
The `System.OperatingSystem` property functions return information about the operating system on which MSBuild is running. For example, if your project targets Linux and you build it on macOS, the property functions will return information about macOS.
140
+
The `System.OperatingSystem` property functions return information about the operating system on which MSBuild is running. For example, if your project targets Linux and you build it on macOS, the property functions return information about macOS.
141
141
142
-
In MSBuild running on .NET (`dotnet build`), all static methods of the `System.OperatingSystem` class will be callable as static property functions.
142
+
In MSBuild running on .NET (`dotnet build`), all static methods of the `System.OperatingSystem` class are callable as static property functions.
143
143
144
-
In MSBuild running on .NET Framework (`MSBuild.exe`), only the following methods of `System.OperatingSystem`will be callable as static property functions. MSBuild implements them internally, because `System.OperatingSystem` does not define them on .NET Framework. Methods for operating systems for which there is no .NET SDK, such as `System.OperatingSystem::IsTvOS`, are not callable.
144
+
In MSBuild running on .NET Framework (`MSBuild.exe`), only the following methods of `System.OperatingSystem`are callable as static property functions. MSBuild implements them internally, because `System.OperatingSystem` does not define them on .NET Framework. Methods for operating systems for which there's no .NET SDK, such as `System.OperatingSystem::IsTvOS`, are not callable.
@@ -191,7 +191,7 @@ For example, to add together two properties that have numeric values, use the fo
191
191
$([MSBuild]::Add($(NumberOne), $(NumberTwo)))
192
192
```
193
193
194
-
Here is a list of MSBuild property functions:
194
+
Here's a list of MSBuild property functions:
195
195
196
196
:::moniker range=">=vs-2022"
197
197
|Function signature|Description|
@@ -231,7 +231,7 @@ Here is a list of MSBuild property functions:
231
231
|`bool IsOSUnixLike()`|True if current OS is a Unix system.|
232
232
|`bool IsTargetFrameworkCompatible(string targetFrameworkTarget, string targetFrameworkCandidate)`|Return 'True' if the candidate target framework (second argument) is compatible with the target framework indicated by the first argument, and false otherwise. See [MSBuild TargetFramework and TargetPlatform functions](#msbuild-targetframework-and-targetplatform-functions).|
233
233
|`int LeftShift(int operand, int count)`| Shift left by `count` bits. MSBuild 17.7 and later. |
234
-
|`string MakeRelative(string basePath, string path)`|Makes `path` relative to `basePath`. `basePath` must be an absolute directory. If `path`cannot be made relative, it is returned verbatim. Similar to `Uri.MakeRelativeUri`. See [MSBuild MakeRelative](#msbuild-makerelative).|
234
+
|`string MakeRelative(string basePath, string path)`|Makes `path` relative to `basePath`. `basePath` must be an absolute directory. If `path`can't be made relative, it is returned verbatim. Similar to `Uri.MakeRelativeUri`. See [MSBuild MakeRelative](#msbuild-makerelative).|
235
235
|`double Modulo(double a, double b)`|Modulo two doubles.|
236
236
|`long Modulo(long a, long b)`|Modulo two longs.|
237
237
|`double Multiply(double a, double b)`|Multiply two doubles.|
@@ -365,7 +365,7 @@ This example shows how to import the nearest *EnlistmentInfo.props* file in or a
where `file` is the name of the file to search for and `startingDirectory` is an optional directory to start the search in. By default, the search will start in the current file's own directory.
384
+
where `file` is the name of the file to search for and `startingDirectory` is an optional directory to start the search in. By default, the search starts in the current file's own directory.
385
385
386
386
This example shows how to import a file named *dir.props* in or above the current directory, only if a match is found:
gets the **SLRuntimeInstallPath** data of the **ReferenceAssemblies** key, looking first in the 64-bit registry view and then in the 32-bit registry view.
453
+
The preceding code gets the **SLRuntimeInstallPath** data of the **ReferenceAssemblies** key, looking first in the 64-bit registry view and then in the 32-bit registry view.
454
454
455
455
> [!WARNING]
456
456
> In the .NET SDK version of MSBuild (`dotnet build`), this function is not supported.
@@ -562,23 +562,23 @@ MSBuild 16.7 and higher define several functions for handling [TargetFramework a
562
562
563
563
|Function signature|Description|
564
564
|------------------------|-----------------|
565
-
|`FilterTargetFrameworks(string incoming, string filter)`|Return the list of the target frameworks that match the specified filter. An target framework from `incoming` is kept if it matches any of the desired target frameworks on `filter`.|
566
-
|`GetTargetFrameworkIdentifier(string targetFramework)`|Parse the TargetFrameworkIdentifier from the TargetFramework.|
567
-
|`GetTargetFrameworkVersion(string targetFramework, int versionPartCount)`|Parse the TargetFrameworkVersion from the TargetFramework.|
568
-
|`GetTargetPlatformIdentifier(string targetFramework)`|Parse the TargetPlatformIdentifier from the TargetFramework.|
569
-
|`GetTargetPlatformVersion(string targetFramework, int versionPartCount)`|Parse the TargetPlatformVersion from the TargetFramework.|
570
-
|`IsTargetFrameworkCompatible(string targetFrameworkTarget, string targetFrameworkCandidate)`|Return 'True' if the candidate target framework (second argument) is compatible with the target framework indicated by the first argument, and false otherwise.|
565
+
|`FilterTargetFrameworks(string incoming, string filter)`|Return the list of the target frameworks that match the specified filter. A target framework from `incoming` is kept if it matches any of the desired target frameworks on `filter`.|
566
+
|`GetTargetFrameworkIdentifier(string targetFramework)`|Parse the TargetFrameworkIdentifier from the TargetFramework.|
567
+
|`GetTargetFrameworkVersion(string targetFramework, int versionPartCount)`|Parse the TargetFrameworkVersion from the TargetFramework.|
568
+
|`GetTargetPlatformIdentifier(string targetFramework)`|Parse the TargetPlatformIdentifier from the TargetFramework.|
569
+
|`GetTargetPlatformVersion(string targetFramework, int versionPartCount)`|Parse the TargetPlatformVersion from the TargetFramework.|
570
+
|`IsTargetFrameworkCompatible(string targetFrameworkTarget, string targetFrameworkCandidate)`|Return true if the candidate target framework (second argument) is compatible with the target framework indicated by the first argument, and false otherwise.|
571
571
:::moniker-end
572
572
573
573
:::moniker range="<=vs-2019"
574
574
575
575
|Function signature|Description|
576
576
|------------------------|-----------------|
577
-
|`GetTargetFrameworkIdentifier(string targetFramework)`|Parse the TargetFrameworkIdentifier from the TargetFramework.|
578
-
|`GetTargetFrameworkVersion(string targetFramework, int versionPartCount)`|Parse the TargetFrameworkVersion from the TargetFramework.|
579
-
|`GetTargetPlatformIdentifier(string targetFramework)`|Parse the TargetPlatformIdentifier from the TargetFramework.|
580
-
|`GetTargetPlatformVersion(string targetFramework, int versionPartCount)`|Parse the TargetPlatformVersion from the TargetFramework.|
581
-
|`IsTargetFrameworkCompatible(string targetFrameworkTarget, string targetFrameworkCandidate)`|Return 'True' if the candidate target framework (second argument) is compatible with the target framework indicated by the first argument, and false otherwise.|
577
+
|`GetTargetFrameworkIdentifier(string targetFramework)`|Parse the TargetFrameworkIdentifier from the TargetFramework.|
578
+
|`GetTargetFrameworkVersion(string targetFramework, int versionPartCount)`|Parse the TargetFrameworkVersion from the TargetFramework.|
579
+
|`GetTargetPlatformIdentifier(string targetFramework)`|Parse the TargetPlatformIdentifier from the TargetFramework.|
580
+
|`GetTargetPlatformVersion(string targetFramework, int versionPartCount)`|Parse the TargetPlatformVersion from the TargetFramework.|
581
+
|`IsTargetFrameworkCompatible(string targetFrameworkTarget, string targetFrameworkCandidate)`|Return true if the candidate target framework (second argument) is compatible with the target framework indicated by the first argument, and false otherwise.|
582
582
:::moniker-end
583
583
584
584
The `versionPartCount` parameter of `GetTargetFrameworkVersion` and `GetTargetPlatformVersion` has a default value of 2.
@@ -665,7 +665,7 @@ In these methods, versions are parsed like <xref:System.Version?displayProperty=
665
665
666
666
## MSBuild condition functions
667
667
668
-
The functions `Exists` and `HasTrailingSlash` are not property functions. They are available for use with the `Condition` attribute. See [MSBuild conditions](msbuild-conditions.md).
668
+
The functions `Exists` and `HasTrailingSlash` are not property functions. They're available for use with the `Condition` attribute. See [MSBuild conditions](msbuild-conditions.md).
0 commit comments