Skip to content

Commit 881a0dd

Browse files
committed
Review and update
1 parent a833b57 commit 881a0dd

File tree

1 file changed

+18
-22
lines changed

1 file changed

+18
-22
lines changed

docs/msbuild/walkthrough-using-msbuild.md

Lines changed: 18 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
title: "MSBuild Tutorial: Install and create a project"
33
description: Explore the various parts of an MSBuild project file, including items, item metadata, properties, targets, and build tasks.
4-
ms.date: 10/17/2023
4+
ms.date: 10/3/2024
55
ms.topic: tutorial
66
helpviewer_keywords:
77
- MSBuild, tutorial
@@ -79,11 +79,6 @@ To install MSBuild on a system that doesn't have Visual Studio, go to Build Tool
7979

8080
Project files are XML-formatted files with the root node [Project](../msbuild/project-element-msbuild.md).
8181

82-
```xml
83-
<?xml version="1.0" encoding="utf-8"?>
84-
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
85-
```
86-
8782
Most .NET projects have an `Sdk` attribute. These projects are called SDK-style projects.
8883

8984
```xml
@@ -129,21 +124,22 @@ MSBuild keeps track of the targets of a build, and guarantees that each target i
129124

130125
```xml
131126
<Target Name="HelloWorld">
132-
<Message Text="Hello"></Message> <Message Text="World"></Message>
127+
<Message Text="Hello"></Message>
128+
<Message Text="World"></Message>
133129
</Target>
134130
```
135131

136132
3. Save the project file.
137133

138134
The `Message` task is one of the many tasks that ships with MSBuild. For a complete list of available tasks and usage information, see [Task reference](../msbuild/msbuild-task-reference.md).
139135

140-
The `Message` task takes the string value of the Text attribute as input and displays it on the output device (or writes it to one or more logs, if applicable). The HelloWorld target executes the Message task twice: first to display "Hello", and then to display "World."
136+
The `Message` task takes the string value of the `Text` attribute as input and displays it on the output device (or writes it to one or more logs, if applicable). The `HelloWorld` target executes the Message task twice: first to display "Hello", and then to display "World."
141137

142138
## Build the target
143139

144140
If you try to build this project from Visual Studio, it doesn't build the target you defined. That's because Visual Studio chooses the default target, which is still the one in the imported `.targets` file.
145141

146-
Run MSBuild from the **Developer Command Prompt** for Visual Studio to build the HelloWorld target defined previously. Use the -target or -t command-line switch to select the target.
142+
Run MSBuild from the **Developer Command Prompt** for Visual Studio to build the HelloWorld target defined previously. Use the `-target` or `-t` command-line switch to select the target.
147143

148144
> [!NOTE]
149145
> We will refer to the **Developer Command Prompt** as the **Command Window** in the following sections.
@@ -194,18 +190,18 @@ Run MSBuild from the **Developer Command Prompt** for Visual Studio to build the
194190
All properties are child elements of PropertyGroup elements. The name of the property is the name of the child element, and the value of the property is the text element of the child element. For example,
195191

196192
```xml
197-
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
193+
<TargetFrameworkVersion>net8.0</TargetFrameworkVersion>
198194
```
199195

200-
defines the property named TargetFrameworkVersion, giving it the string value "v4.5."
196+
defines the property named `TargetFrameworkVersion`, giving it the string value "net8.0"
201197

202198
Build properties can be redefined at any time. If
203199

204200
```xml
205-
<TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
201+
<TargetFrameworkVersion>net6.0</TargetFrameworkVersion>
206202
```
207203

208-
appears later in the project file, or in a file imported later in the project file, then TargetFrameworkVersion takes the new value "v3.5."
204+
appears later in the project file, or in a file imported later in the project file, then `TargetFrameworkVersion` takes the new value "net6.0"
209205

210206
## Examine a property value
211207

@@ -261,24 +257,24 @@ Use this syntax to examine some of the properties in the project file.
261257
Many properties like `Configuration` are defined conditionally, that is, the `Condition` attribute appears in the property element. Conditional properties are defined or redefined only if the condition evaluates to "true." Undefined properties are given the default value of an empty string. For example,
262258

263259
```xml
264-
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
260+
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
265261
```
266262

267263
means "If the Configuration property hasn't been defined yet, define it and give it the value 'Debug'."
268264

269-
Almost all MSBuild elements can have a Condition attribute. For more discussion about using the Condition attribute, see [Conditions](../msbuild/msbuild-conditions.md).
265+
Almost all MSBuild elements can have a `Condition` attribute. For more discussion about using the `Condition` attribute, see [Conditions](../msbuild/msbuild-conditions.md).
270266

271267
### Reserved properties
272268

273-
MSBuild reserves some property names to store information about the project file and the MSBuild binaries. MSBuildToolsPath is an example of a reserved property. Reserved properties are referenced with the $ notation like any other property. For more information, see [How to: Reference the name or location of the project file](../msbuild/how-to-reference-the-name-or-location-of-the-project-file.md) and [MSBuild reserved and well-known properties](../msbuild/msbuild-reserved-and-well-known-properties.md).
269+
MSBuild reserves some property names to store information about the project file and the MSBuild binaries. MSBuildToolsPath is an example of a reserved property. Reserved properties are referenced with the `$` notation like any other property. For more information, see [How to: Reference the name or location of the project file](../msbuild/how-to-reference-the-name-or-location-of-the-project-file.md) and [MSBuild reserved and well-known properties](../msbuild/msbuild-reserved-and-well-known-properties.md).
274270

275271
### Environment variables
276272

277-
You can reference environment variables in project files the same way as build properties. For example, to use the PATH environment variable in your project file, use $(Path). If the project contains a property definition that has the same name as an environment variable, the property in the project overrides the value of the environment variable. For more information, see [How to: Use environment variables in a build](../msbuild/how-to-use-environment-variables-in-a-build.md).
273+
You can reference environment variables in project files the same way as build properties. For example, to use the `PATH` environment variable in your project file, use `$(Path`). If the project contains a property definition that has the same name as an environment variable, the property in the project overrides the value of the environment variable. For more information, see [How to: Use environment variables in a build](../msbuild/how-to-use-environment-variables-in-a-build.md).
278274

279275
## Set properties from the command line
280276

281-
Properties can be defined on the command line using the -property or -p command line switch. Property values received from the command line override property values set in the project file and environment variables.
277+
Properties can be defined on the command line using the `-property` or `-p` command line switch. Property values received from the command line override property values set in the project file and environment variables.
282278

283279
**To set a property value from the command line:**
284280

@@ -298,7 +294,7 @@ MSBuild creates the Configuration property and gives it the value "Release."
298294
299295
## Special characters
300296
301-
Certain characters have special meaning in MSBuild project files. Examples of these characters include semicolons (;) and asterisks (*). In order to use these special characters as literals in a project file, they must be specified by using the syntax %\<xx>, where \<xx> represents the ASCII hexadecimal value of the character.
297+
Certain characters have special meaning in MSBuild project files. Examples of these characters include semicolons (`;`) and asterisks (`*`). In order to use these special characters as literals in a project file, they must be specified by using the syntax `%<xx>`, where `<xx>` represents the ASCII hexadecimal value of the character.
302298
303299
Change the Message task to show the value of the Configuration property with special characters to make it more readable.
304300
@@ -396,7 +392,7 @@ To change the separator of an item type, use the following syntax, where ItemTyp
396392
@(ItemType, Separator)
397393
```
398394

399-
Change the Message task to use carriage returns and line feeds (%0A%0D) to display Compile items one per line.
395+
Change the `Message` task to use carriage returns and line feeds (%0A%0D) to display Compile items one per line.
400396

401397
**To display item type values one per line**
402398

@@ -550,7 +546,7 @@ Notice how the phrase "Compile.DependentUpon" appears several times. The use of
550546

551547
### Well-known metadata
552548

553-
Whenever an item is added to an item list, that item is assigned some well-known metadata. For example, %(Filename) returns the file name of any item. For a complete list of well-known metadata, see [Well-known item metadata](../msbuild/msbuild-well-known-item-metadata.md).
549+
Whenever an item is added to an item list, that item is assigned some well-known metadata. For example, `%(Filename)` returns the file name of any item. For a complete list of well-known metadata, see [Well-known item metadata](../msbuild/msbuild-well-known-item-metadata.md).
554550

555551
**To examine well-known metadata:**
556552

@@ -583,7 +579,7 @@ By comparing the preceding two examples, you can see that while not every item i
583579

584580
### Metadata transformations
585581

586-
Item lists can be transformed into new item lists. To transform an item list, use the following syntax, where \<ItemType> is the name of the item type and \<MetadataName> is the name of the metadata:
582+
Item lists can be transformed into new item lists. To transform an item list, use the following syntax, where `<ItemType>` is the name of the item type and `<MetadataName>` is the name of the metadata:
587583

588584
```xml
589585
@(ItemType -> '%(MetadataName)')

0 commit comments

Comments
 (0)