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/msbuild.md
+11-3Lines changed: 11 additions & 3 deletions
Original file line number
Diff line number
Diff line change
@@ -2,7 +2,7 @@
2
2
title: MSBuild | Microsoft Docs
3
3
description: Learn about how the Microsoft Build Engine (MSBuild) platform provides a project file with an XML schema to control builds.
4
4
ms.custom: SEO-VS-2020
5
-
ms.date: 08/11/2021
5
+
ms.date: 10/07/2022
6
6
ms.topic: conceptual
7
7
helpviewer_keywords:
8
8
- MSBuild, about MSBuild
@@ -17,7 +17,7 @@ ms.workload:
17
17
---
18
18
# MSBuild
19
19
20
-
The Microsoft Build Engine is a platform for building applications. This engine, which is also known as MSBuild, provides an XML schema for a project file that controls how the build platform processes and builds software. Visual Studio uses MSBuild, but MSBuild doesn't depend on Visual Studio. By invoking *msbuild.exe* on your project or solution file, you can orchestrate and build products in environments where Visual Studio isn't installed.
20
+
The Microsoft Build Engine is a platform for building applications. This engine, which is also known as MSBuild, provides an XML schema for a project file that controls how the build platform processes and builds software. Visual Studio uses MSBuild, but MSBuild doesn't depend on Visual Studio. By invoking *msbuild.exe*or *dotnet build*on your project or solution file, you can orchestrate and build products in environments where Visual Studio isn't installed.
21
21
22
22
Visual Studio uses MSBuild to load and build managed projects. The project files in Visual Studio (*.csproj*, *.vbproj*, *.vcxproj*, and others) contain MSBuild XML code that executes when you build a project by using the IDE. Visual Studio projects import all the necessary settings and build processes to do typical development work, but you can extend or modify them from within Visual Studio or by using an XML editor.
> Before you download a project, determine the trustworthiness of the code.
67
67
68
+
For .NET Core and .NET 5 or later, you typically use `dotnet build` to invoke MSBuild. See [dotnet build](/dotnet/core/tools/dotnet-build).
69
+
68
70
## Project file
69
71
70
72
MSBuild uses an XML-based project file format that's straightforward and extensible. The MSBuild project file format lets developers describe the items that are to be built, and also how they are to be built for different operating systems and configurations. In addition, the project file format lets developers author reusable build rules that can be factored into separate files so that builds can be performed consistently across different projects in the product.
71
73
72
-
The Visual Studio build system stores project-specific logic in the your project file itself, and uses imported MSBuild XML files with extensions like *.props* and *.targets* to define the standard build logic. The *.props* files define MSBuild properties, and *.targets* files define MSBuild targets. These imports are sometimes visible in the Visual Studio project file, but in newer projects such as .NET Core, .NET 5 and .NET 6 projects, you don't see the imports in the project file; instead, you see an SDK reference. These are called SDK-style projects. When you reference an SDK such as the .NET SDK, the imports of .props and .target files are implicitly specified by the SDK.
74
+
The Visual Studio build system stores project-specific logic in the your project file itself, and uses imported MSBuild XML files with extensions like `.props` and `.targets` to define the standard build logic. The `.props` files define MSBuild properties, and `.targets` files define MSBuild targets. These imports are sometimes visible in the Visual Studio project file, but in newer projects such as .NET Core, .NET 5 and .NET 6 projects, you don't see the imports in the project file; instead, you see an SDK reference, which looks like this:
75
+
76
+
```xml
77
+
<ProjectSdk="Microsoft.Net.Sdk">
78
+
```
79
+
80
+
These are called SDK-style projects. When you reference an SDK such as the .NET SDK, the imports of `.props` and `.target` files are implicitly specified by the SDK.
73
81
74
82
The following sections describe some of the basic elements of the MSBuild project file format. For a tutorial about how to create a basic project file, see [Walkthrough: Creating an MSBuild project file from scratch](../msbuild/walkthrough-creating-an-msbuild-project-file-from-scratch.md).
Newer .NET Core (SDK-style) projects have a `Sdk` attribute.
91
+
Most .NET projects have a `Sdk` attribute. These are called SDK-style projects.
92
92
93
93
```xml
94
94
<ProjectSdk="Microsoft.NET.Sdk">
95
95
```
96
96
97
-
If the project is not an SDK-style project, you must specify the xmlns namespace in the Project element. If `ToolsVersion` is present in a new project, it must match the MSBuild version. If you don't know the MSBuild version, you can get it from the first two numbers from the output of the following command line (for example, 16.0):
98
-
99
-
```console
100
-
MSBuild -ver
101
-
```
97
+
There are many variations of .NET SDKs for special purposes; they are described at [.NET Project SDKs](/dotnet/core/project-sdk/overview).
102
98
103
99
The work of building an application is done with [Target](../msbuild/target-element-msbuild.md) and [Task](../msbuild/task-element-msbuild.md) elements.
104
100
@@ -144,9 +140,9 @@ MSBuild keeps track of the targets of a build, and guarantees that each target i
144
140
145
141
3. Save the project file.
146
142
147
-
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).
143
+
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).
148
144
149
-
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".
145
+
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".
150
146
151
147
## Build the target
152
148
@@ -161,7 +157,7 @@ Run MSBuild from the **Developer Command Prompt** for Visual Studio to build the
161
157
162
158
1. Open the **Command Window**.
163
159
164
-
(Windows 10) In the search box on the taskbar, start typing the name of the tool, such as `dev` or `developer command prompt`. This brings up a list of installed apps that match your search pattern.
160
+
In the search box on the taskbar, start typing the name of the tool, such as `dev` or `developer command prompt`. This brings up a list of installed apps that match your search pattern.
165
161
166
162
If you need to find it manually, the file is *LaunchDevCmd.bat* in the *<visualstudio installation folder\>\Common7\Tools* folder.
167
163
@@ -350,7 +346,7 @@ All items are child elements of ItemGroup elements. The item name is the name of
350
346
351
347
defines an item group containing two items. The item type Compile has two values: *Program.cs* and *Properties\AssemblyInfo.cs*.
352
348
353
-
The following code creates the same item type by declaring both files in one Include attribute, separated by a semicolon.
349
+
The following code creates the same item type by declaring both files in one `Include` attribute, separated by a semicolon.
354
350
355
351
```xml
356
352
<ItemGroup>
@@ -365,13 +361,13 @@ For more information, see [Items](../msbuild/msbuild-items.md).
365
361
366
362
## Examine item type values
367
363
368
-
To get the values of an item type, use the following syntax, where ItemType is the name of the item type:
364
+
To get the values of an item type, use the following syntax, where `ItemType` is the name of the item type:
369
365
370
366
```xml
371
367
@(ItemType)
372
368
```
373
369
374
-
Use this syntax to examine the Compile item type in the project file.
370
+
Use this syntax to examine the `Compile` item type in the project file.
375
371
376
372
**To examine item type values:**
377
373
@@ -393,7 +389,7 @@ Use this syntax to examine the Compile item type in the project file.
393
389
394
390
1. Examine the output. You should see this long line:
395
391
396
-
```
392
+
```output
397
393
Compile item type contains Form1.cs;Form1.Designer.cs;Program.cs;Properties\AssemblyInfo.cs;Properties\Resources.Designer.cs;Properties\Settings.Designer.cs
398
394
```
399
395
@@ -425,7 +421,7 @@ Change the Message task to use carriage returns and line feeds (%0A%0D) to displ
425
421
426
422
4. Examine the output. You should see these lines:
427
423
428
-
```
424
+
```output
429
425
Compile item type contains Form1.cs
430
426
Form1.Designer.cs
431
427
Program.cs
@@ -506,7 +502,7 @@ would not exclude the file *Form1.cs*, which was added in the preceding item ele
506
502
507
503
5. Examine the output. You should see this line:
508
504
509
-
```
505
+
```output
510
506
XFiles item type contains Form1.cs;Program.cs;Properties/Resources.resx
511
507
```
512
508
@@ -524,7 +520,7 @@ would not exclude the file *Form1.cs*, which was added in the preceding item ele
524
520
</ItemGroup>
525
521
```
526
522
527
-
To get the metadata value of an item type, use the following syntax, where ItemType is the name of the item type and MetaDataName is the name of the metadata:
523
+
To get the metadata value of an item type, use the following syntax, where `ItemType` is the name of the item type and MetaDataName is the name of the metadata:
528
524
529
525
```xml
530
526
%(ItemType.MetaDataName)
@@ -626,7 +622,9 @@ Notice that metadata expressed in this syntax does not cause batching.
626
622
627
623
## Next steps
628
624
629
-
To learn how to create a simple project file one step at a time, try out the [Walkthrough: Creating an MSBuild project file from scratch](../msbuild/walkthrough-creating-an-msbuild-project-file-from-scratch.md).
625
+
To learn how to create a simple project file one step at a time, on Windows, try out the [Walkthrough: Creating an MSBuild project file from scratch](../msbuild/walkthrough-creating-an-msbuild-project-file-from-scratch.md).
626
+
627
+
If you're primarily using the .NET SDK, you may wish to continue reading at [MSBuild Reference for .NET SDK Projects](/dotnet/core/project-sdk/msbuild-props).
0 commit comments