Skip to content

Commit 57be1b0

Browse files
authored
Merge pull request #10401 from ghogen/msbuild-content-updates-sep22
MSBuild: update articles for Visual Studio 2022
2 parents 4ff164a + 2b811a2 commit 57be1b0

5 files changed

+53
-69
lines changed

docs/ide/how-to-view-save-and-configure-build-log-files.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
title: 'How to: View, save, and configure build log files | Microsoft Docs'
33
description: Learn how you can view, save, and configure build log files. These files provide useful information for tasks like troubleshooting a build failure.
44
ms.custom: SEO-VS-2020
5-
ms.date: 08/28/2019
5+
ms.date: 09/12/2022
66
ms.technology: vs-ide-compile
77
ms.topic: how-to
88
ms.assetid: 75d38b76-26d6-4f43-bbe7-cbacd7cc81e7
@@ -18,7 +18,7 @@ ms.workload:
1818

1919
After you build a project in the Visual Studio IDE, you can view information about that build in the **Output** window. By using this information, you can, for example, troubleshoot a build failure.
2020

21-
- For C++ projects, you can also view the same information in a log file that's created and saved when you build a project.
21+
- For C++ projects, you can also view the same information in a log file that's created and saved when you build a project.
2222

2323
- For managed code projects, you can click in the build output window and press **Ctrl**+**S**. Visual Studio prompts you for a location to save the information from the **Output** window into a log file.
2424

@@ -28,7 +28,7 @@ If you build any kind of project by using MSBuild, you can create a log file to
2828

2929
## To view the build log file for a C++ project
3030

31-
1. In **Windows Explorer** or **File Explorer**, open the following file (relative to the project root folder): *Release*\\{ProjectName}.Log* or *Debug\\{ProjectName}.log*
31+
1. In **Windows Explorer** or **File Explorer**, open the following file (relative to the project root folder): *Release\\{ProjectName}.Log* or *Debug\\{ProjectName}.log*
3232

3333
## To create a build log file for a managed-code project
3434

docs/msbuild/msbuild-target-framework-and-target-platform.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
title: MSBuild Target Framework and Target Platform | Microsoft Docs
33
description: Learn how to build an MSBuild project to run on a target .NET Framework version, and a target platform or software architecture.
44
ms.custom: SEO-VS-2020
5-
ms.date: 11/04/2016
5+
ms.date: 09/12/2022
66
ms.topic: conceptual
77
ms.assetid: df6517c5-edd6-4cc4-97ad-b3cdfc78e799
88
author: ghogen

docs/msbuild/target-build-order.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
title: Target Build Order | Microsoft Docs
33
description: Learn how to specify the order in which MSBuild targets are run, if the input to one target depends on the output of another target.
44
ms.custom: SEO-VS-2020
5-
ms.date: 05/02/2019
5+
ms.date: 09/12/2022
66
ms.topic: conceptual
77
helpviewer_keywords:
88
- msbuild, build order
@@ -25,7 +25,7 @@ Targets must be ordered if the input to one target depends on the output of anot
2525

2626
- `DependsOnTargets`. This `Target` attribute specifies targets that must run before this target can run.
2727

28-
- `BeforeTargets` and `AfterTargets`. These `Target` attributes specify that this target should run before or after the specified targets (MSBuild 4.0).
28+
- `BeforeTargets` and `AfterTargets`. These `Target` attributes specify that this target should run before or after the specified targets.
2929

3030
A target is never run twice during a build, even if a subsequent target in the build depends on it. Once a target has been run, its contribution to the build is complete.
3131

@@ -81,7 +81,7 @@ tells MSBuild that the `Serve` target depends on the `Chop` target and the `Cook
8181

8282
## BeforeTargets and AfterTargets
8383

84-
In MSBuild 4.0 and later, you can specify target order by using the `BeforeTargets` and `AfterTargets` attributes.
84+
You can specify target order by using the `BeforeTargets` and `AfterTargets` attributes.
8585

8686
Consider the following script.
8787

docs/msbuild/walkthrough-creating-an-msbuild-project-file-from-scratch.md

Lines changed: 45 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
---
22
title: Create an MSBuild project file from scratch
33
description: Walk through creating an MSBuild project file from scratch to understand how the XML is organized and how you can change it to control a build.
4-
ms.custom: SEO-VS-2020
5-
ms.date: 11/04/2016
4+
ms.date: 09/12/2022
65
ms.topic: conceptual
76
helpviewer_keywords:
87
- MSBuild, tutorial
@@ -19,7 +18,7 @@ ms.workload:
1918
Programming languages that target the .NET Framework use MSBuild project files to describe and control the application build process. When you use Visual Studio to create an MSBuild project file, the appropriate XML is added to the file automatically. However, you may find it helpful to understand how the XML is organized and how you can change it to control a build.
2019

2120
> [!NOTE]
22-
> This tutorial works only with .NET Framework 4.x and earlier, not .NET Core or .NET 5 and later.
21+
> This article is appropriate if you want to learn the basic fundamentals of how MSBuild works independently of any SDK. Building with an SDK, such as when you use `dotnet build` or you add the `Sdk` attribute to the root project element, is not covered in this article. See [.NET Project SDKs](/dotnet/core/project-sdk/overview).
2322
2423
For information about creating a project file for a C++ project, see [MSBuild (C++)](/cpp/build/msbuild-visual-cpp).
2524

@@ -45,7 +44,7 @@ Programming languages that target the .NET Framework use MSBuild project files t
4544

4645
This walkthrough shows how to build the project at the command prompt and examine the results. For more information about MSBuild and how to run MSBuild at the command prompt, see [Walkthrough: Use MSBuild](../msbuild/walkthrough-using-msbuild.md).
4746

48-
To complete the walkthrough, you must have Visual Studio installed because it includes MSBuild and the Visual C# compiler, which are required for the walkthrough.
47+
To complete the walkthrough, you must have Visual Studio installed because it includes MSBuild and the C# compiler, which are required for the walkthrough.
4948

5049
## Extend the path
5150

@@ -57,11 +56,9 @@ Before you can use MSBuild, you must extend the PATH environment variable to inc
5756

5857
1. At the command prompt, browse to the folder where you want to create the application, for example, *\My Documents\\* or *\Desktop\\*.
5958

60-
2. Type **md HelloWorld** to create a subfolder named *\HelloWorld\\*.
59+
1. Create a subfolder named *\HelloWorld\\* and change directory to go inside it.
6160

62-
3. Type **cd HelloWorld** to change to the new folder.
63-
64-
4. Start Notepad or another text editor, and then type the following code.
61+
1. In a text editor, create a new file *HelloWorld.cs* and then copy and paste the following code:
6562

6663
```csharp
6764
using System;
@@ -79,15 +76,13 @@ Before you can use MSBuild, you must extend the PATH environment variable to inc
7976
}
8077
```
8178

82-
5. Save this source code file and name it *Helloworld.cs*.
83-
84-
6. Build the application by typing **csc helloworld.cs** at the command prompt.
79+
1. Build the application by typing **csc helloworld.cs** at the command prompt.
8580

86-
7. Test the application by typing **helloworld** at the command prompt.
81+
1. Test the application by typing **helloworld** at the command prompt.
8782

8883
The **Hello, world!** message should be displayed.
8984

90-
8. Delete the application by typing **del helloworld.exe** at the command prompt.
85+
1. Delete the executable.
9186

9287
## Create a minimal MSBuild project file
9388

@@ -101,56 +96,51 @@ Before you can use MSBuild, you must extend the PATH environment variable to inc
10196

10297
- A `Target` node to contain tasks that are required to build the application.
10398

104-
- A `Task` element to start the Visual C# compiler to build the application.
99+
- A `Task` element to start the C# compiler to build the application.
105100

106101
### To create a minimal MSBuild project file
107102

108-
1. In the text editor, create a new file and enter these two lines:
103+
1. In the text editor, create a new file *HelloWorld.csproj* and enter the following code:
109104

110105
```xml
111-
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
106+
<Project>
107+
<ItemGroup>
108+
<Compile Include="helloworld.cs" />
109+
</ItemGroup>
112110
</Project>
113111
```
114112

115-
2. Insert this `ItemGroup` node as a child element of the `Project` node:
116-
117-
```xml
118-
<ItemGroup>
119-
<Compile Include="helloworld.cs" />
120-
</ItemGroup>
121-
```
122-
123-
Notice that this `ItemGroup` already contains an item element.
113+
This `ItemGroup` contains an item element `Compile` and specifies one source file as an item.
124114

125-
3. Add a `Target` node as a child element of the `Project` node. Name the node `Build`.
115+
1. Add a `Target` node as a child element of the `Project` node. Name the node `Build`.
126116

127117
```xml
128118
<Target Name="Build">
129119
</Target>
130120
```
131121

132-
4. Insert this task element as a child element of the `Target` node:
122+
1. Insert this task element as a child element of the `Target` node:
133123

134124
```xml
135125
<Csc Sources="@(Compile)"/>
136126
```
137127

138-
5. Save this project file and name it *Helloworld.csproj*.
128+
1. Save this project file and name it *Helloworld.csproj*.
139129

140130
Your minimal project file should resemble the following code:
141131

142132
```xml
143-
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
133+
<Project>
144134
<ItemGroup>
145-
<Compile Include="helloworld.cs" />
135+
<Compile Include="helloworld.cs"/>
146136
</ItemGroup>
147137
<Target Name="Build">
148-
<Csc Sources="@(Compile)"/>  
138+
<Csc Sources="@(Compile)"/>
149139
</Target>
150140
</Project>
151141
```
152142

153-
Tasks in the Build target are executed sequentially. In this case, the Visual C# compiler `Csc` task is the only task. It expects a list of source files to compile, and this is given by the value of the `Compile` item. The `Compile` item references just one source file, *Helloworld.cs*.
143+
Tasks in the Build target are executed sequentially. In this case, the C# compiler `Csc` task is the only task. It expects a list of source files to compile, and this is given by the value of the `Compile` item. The `Compile` item references just one source file, *Helloworld.cs*.
154144

155145
> [!NOTE]
156146
> In the item element, you can use the asterisk wildcard character (\*) to reference all files that have the *.cs* file name extension, as follows:
@@ -165,7 +155,7 @@ Tasks in the Build target are executed sequentially. In this case, the Visual C#
165155

166156
1. At the command prompt, type **msbuild helloworld.csproj -t:Build**.
167157

168-
This builds the Build target of the Helloworld project file by invoking the Visual C# compiler to create the Helloworld application.
158+
This builds the Build target of the Helloworld project file by invoking the C# compiler to create the Helloworld application.
169159

170160
2. Test the application by typing **helloworld**.
171161

@@ -186,9 +176,9 @@ Tasks in the Build target are executed sequentially. In this case, the Visual C#
186176

187177
### To add build properties
188178

189-
1. Delete the existing application by typing **del helloworld.exe** at the command prompt.
179+
1. Delete the existing application executable (later, you'll add a `Clean` target to handle the deletion of old output files).
190180

191-
2. In the project file, insert this `PropertyGroup` element just after the opening `Project` element:
181+
1. In the project file, insert this `PropertyGroup` element just after the opening `Project` element:
192182

193183
```xml
194184
<PropertyGroup>
@@ -197,28 +187,28 @@ Tasks in the Build target are executed sequentially. In this case, the Visual C#
197187
</PropertyGroup>
198188
```
199189

200-
3. Add this task to the Build target, just before the `Csc` task:
190+
1. Add this task to the Build target, just before the `Csc` task:
201191

202192
```xml
203-
<MakeDir Directories="$(OutputPath)" Condition="!Exists('$(OutputPath)')" />
193+
<MakeDir Directories="$(OutputPath)" Condition="!Exists('$(OutputPath)')" />
204194
```
205195

206-
The `MakeDir` task creates a folder that is named by the `OutputPath` property, provided that no folder by that name currently exists.
196+
The `MakeDir` task creates a folder that is named by the `OutputPath` property, provided that no folder by that name currently exists.
207197

208-
4. Add this `OutputAssembly` attribute to the `Csc` task:
198+
1. Add this `OutputAssembly` attribute to the `Csc` task:
209199

210200
```xml
211201
<Csc Sources="@(Compile)" OutputAssembly="$(OutputPath)$(AssemblyName).exe" />
212202
```
213203

214-
This instructs the Visual C# compiler to produce an assembly that is named by the `AssemblyName` property and to put it in the folder that is named by the `OutputPath` property.
204+
This instructs the C# compiler to produce an assembly that is named by the `AssemblyName` property and to put it in the folder that is named by the `OutputPath` property.
215205

216-
5. Save your changes.
206+
1. Save your changes.
217207

218208
Your project file should now resemble the following code:
219209

220210
```xml
221-
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
211+
<Project>
222212
<PropertyGroup>
223213
<AssemblyName>MSBuildSample</AssemblyName>
224214
<OutputPath>Bin\</OutputPath>
@@ -252,13 +242,13 @@ Your project file should now resemble the following code:
252242

253243
1. At the command prompt, type **msbuild helloworld.csproj -t:Build**.
254244

255-
This creates the *\Bin\\* folder and then invokes the Visual C# compiler to create the *MSBuildSample* application and puts it in the *\Bin\\* folder.
245+
This creates the *\Bin\\* folder and then invokes the C# compiler to create the *MSBuildSample* application and puts it in the *\Bin\\* folder.
256246

257247
2. To verify that the *\Bin\\* folder has been created, and that it contains the *MSBuildSample* application, type **dir Bin**.
258248

259-
3. Test the application by typing **Bin\MSBuildSample**.
249+
3. Test the application by typing **Bin\MSBuildSample** to run the executable.
260250

261-
The **Hello, world!** message should be displayed.
251+
The **Hello, world!** message should be displayed.
262252

263253
## Add build targets
264254

@@ -286,15 +276,15 @@ Now that you have multiple targets, you can set the Build target as the default
286276
2. Add this `DefaultTargets` attribute to the opening `Project` element:
287277

288278
```xml
289-
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
279+
<Project DefaultTargets="Build">
290280
```
291281

292282
This sets the Build target as the default target.
293283

294284
Your project file should now resemble the following code:
295285

296286
```xml
297-
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
287+
<Project DefaultTargets="Build">
298288
<PropertyGroup>
299289
<AssemblyName>MSBuildSample</AssemblyName>
300290
<OutputPath>Bin\</OutputPath>
@@ -333,7 +323,7 @@ Your project file should now resemble the following code:
333323

334324
2. To verify that the *\Bin\\* folder contains both the *MSBuildSample* application and the new *Greetings* application, type **dir Bin**.
335325

336-
3. Test the Greetings application by typing **Bin\Greetings**.
326+
3. Test the Greetings application (for example, by typing **Bin\Greetings** on Windows).
337327

338328
The **Hello, world!** message should be displayed.
339329

@@ -380,16 +370,12 @@ Your project file should now resemble the following code:
380370

381371
Remember that *helloworld.csproj* is the default project file, and that Build is the default target.
382372

383-
The **-v:d** switch specifies a verbose description for the build process.
373+
The **-v:d** switch is an abbreviation of **-verbosity:detailed** that you used previously.
384374

385-
These lines should be displayed:
375+
If you already built the output, these lines should be displayed:
386376

387377
**Skipping target "Build" because all output files are up-to-date with respect to the input files.**
388378

389-
**Input files: HelloWorld.cs**
390-
391-
**Output files: BinMSBuildSample.exe**
392-
393379
MSBuild skips the Build target because none of the source files have changed since the application was last built.
394380

395381
## C# example
@@ -399,8 +385,7 @@ The following example shows a project file that compiles a C# application and lo
399385
### Code
400386

401387
```xml
402-
<Project DefaultTargets = "Compile"
403-
xmlns="http://schemas.microsoft.com/developer/msbuild/2003" >
388+
<Project DefaultTargets = "Compile">
404389

405390
<!-- Set the application name as a property -->
406391
<PropertyGroup>
@@ -409,11 +394,11 @@ The following example shows a project file that compiles a C# application and lo
409394

410395
<!-- Specify the inputs by type and file name -->
411396
<ItemGroup>
412-
<CSFile Include = "consolehwcs1.cs"/>
397+
<CSFile Include = "*.cs"/>
413398
</ItemGroup>
414399

415-
<Target Name = "Compile">
416-
<!-- Run the Visual C# compilation using input files of type CSFile -->
400+
<Target Name="Compile">
401+
<!-- Run the C# compilation using input files of type CSFile -->
417402
<CSC
418403
Sources = "@(CSFile)"
419404
OutputAssembly = "$(appname).exe">
@@ -436,8 +421,7 @@ The following example shows a project file that compiles a Visual Basic applicat
436421
### Code
437422

438423
```xml
439-
<Project DefaultTargets = "Compile"
440-
xmlns="http://schemas.microsoft.com/developer/msbuild/2003" >
424+
<Project DefaultTargets = "Compile">
441425

442426
<!-- Set the application name as a property -->
443427
<PropertyGroup>

docs/toc.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -789,7 +789,7 @@
789789
href: ide/how-to-configure-projects-to-target-multiple-platforms.md
790790
- name: MSBuild >>
791791
href: msbuild/msbuild.md
792-
- name: Azure Pipelines and TFS >>
792+
- name: Azure Pipelines and Azure DevOps Server >>
793793
displayName: VSTS Azure DevOps CI/CD Continuous integration delivery
794794
href: /azure/devops/pipelines/index?view=vsts&preserve-view=true
795795
- name: Specify build events (Visual Basic)

0 commit comments

Comments
 (0)