Skip to content

Commit a2fcea3

Browse files
author
Colin Robertson
committed
Updates per comments and review
1 parent e8eabbd commit a2fcea3

2 files changed

Lines changed: 62 additions & 31 deletions

File tree

docs/build/reference/vcxproj-file-structure.md

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,26 +7,39 @@ ms.assetid: 14d0c552-29db-480e-80c1-7ea89d6d8e9c
77
---
88
# `.vcxproj` and `.props` file structure
99

10-
[MSBuild](../msbuild-visual-cpp.md) is the default project system in Visual Studio; when you choose **File** > **New Project** in Visual C++ you're creating an MSBuild project whose settings are stored in an XML project file that has the extension *`.vcxproj`*. The project file may also import *`.props`* files and *`.targets`* files where settings can be stored. In most cases, you never need to manually edit the project file. In practice, you should never edit it manually unless you have a good understanding of MSBuild. Whenever possible you should use the Visual Studio property pages to modify project settings. For more information, see [Set C++ compiler and build properties in Visual Studio](../working-with-project-properties.md). However, in some cases you may need to modify a project file or property sheet manually. For those scenarios, this article contains basic information about the structure of the file.
10+
[MSBuild](../msbuild-visual-cpp.md) is the default project system in Visual Studio; when you choose **File** > **New Project** in Visual C++ you're creating an MSBuild project whose settings are stored in an XML project file that has the extension *`.vcxproj`*. The project file may also import *`.props`* files and *`.targets`* files where settings can be stored.
11+
12+
We recommend you only create and modify *`.vcxproj`* projects in the IDE, and avoid manual editing as much as possible. In most cases, you never need to manually edit the project file. Whenever possible you should use the Visual Studio property pages to modify project settings. For more information, see [Set C++ compiler and build properties in Visual Studio](../working-with-project-properties.md).
13+
14+
If you need customizations that aren't possible in the IDE, we recommend you add custom props or targets. Handy places to insert customizations are the *`Directory.Build.props`* and *`Directory.Build.targets`* files, which are automatically imported in all MSBuild-based projects.
15+
16+
In some cases, you may still need to modify a *`.vcxproj`* project file or property sheet manually. We don't recommend you edit it manually unless you have a good understanding of MSBuild, and follow the guidelines in this article. In order for the IDE to load and update *`.vcxproj`* files automatically, these files have several restrictions that don't apply to other MSBuild project files. They weren't designed for manual editing. Mistakes can cause the IDE to crash or behave in unexpected ways.
17+
18+
For manual editing scenarios, this article contains basic information about the structure of *`.vcxproj`* and related files.
1119

1220
**Important:**
1321

1422
If you choose to manually edit a *`.vcxproj`* file, be aware of these facts:
1523

1624
1. The structure of the file must follow a prescribed form, which is described in this article.
1725

18-
1. The Visual Studio C++ project system currently doesn't support wildcards directly in project items. For example, this form isn't supported:
26+
1. The Visual Studio C++ project system currently doesn't support wildcards or lists directly in project items. For example, these forms aren't supported:
1927

2028
```xml
21-
<ClCompile Include="*.cpp"/>
29+
<ItemGroup>
30+
<None Include="*.txt"/>
31+
<ClCompile Include="a.cpp;b.cpp"/>
32+
</ItemGroup>
2233
```
2334

24-
For more information on wildcard support in projects, see [`.vcxproj` files and wildcards](vcxproj-files-and-wildcards.md).
35+
For more information on wildcard support in projects and possible workarounds, see [`.vcxproj` files and wildcards](vcxproj-files-and-wildcards.md).
2536

2637
1. The Visual Studio C++ project system currently doesn't support macros in project item paths. For example, this form isn't supported:
2738

2839
```xml
29-
<ClCompile Include="$(IntDir)\generated.cpp"/>
40+
<ItemGroup>
41+
<ClCompile Include="$(IntDir)\generated.cpp"/>
42+
</ItemGroup>
3043
```
3144

3245
"Not supported" means that macros aren't guaranteed to work for all operations in the IDE. Macros that don't change their value in different configurations should work, but might not be preserved if an item is moved to a different filter or project. Macros that change their value for different configurations will cause problems. That's because the IDE doesn't expect project item paths to be different for different project configurations.
@@ -208,7 +221,7 @@ Contains item definitions. These definitions must follow the same conditions rul
208221
<ItemGroup />
209222
```
210223

211-
Contains the items (source files, and so on) in the project. Conditions aren't supported for Project items (that is, item types that are treated as project items by rules definitions).
224+
`ItemGroup` elements contain the items (source files, and so on) in the project. Conditions aren't supported for Project items (that is, item types that are treated as project items by rules definitions).
212225

213226
The metadata should have configuration conditions for each configuration, even if they're all the same. For example:
214227

@@ -289,5 +302,6 @@ To make your own property sheet, copy one of the *`.props`* files in the *`VCTar
289302

290303
## See also
291304

292-
[Set C++ compiler and build properties in Visual Studio](../working-with-project-properties.md)<br/>
293-
[Property Page XML Files](property-page-xml-files.md)
305+
[Set C++ compiler and build properties in Visual Studio](../working-with-project-properties.md)\
306+
[Property Page XML Files](property-page-xml-files.md)\
307+
[`.vcxproj` files and wildcards](vcxproj-files-and-wildcards.md)

docs/build/reference/vcxproj-files-and-wildcards.md

Lines changed: 40 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,45 @@ ms.assetid: 14d0c552-29db-480e-80c1-7ea89d6d8e9c
77
---
88
# `.vcxproj` files and wildcards
99

10-
As mentioned in [`.vcxproj` and `.props` file structure](vcxproj-file-structure.md), wildcards aren't supported in project items in *`.vcxproj`* files.
10+
The Visual Studio IDE doesn't support certain constructs in project items in *`.vcxproj`* files. These unsupported constructs include wildcards, semi-colon delimited lists, or MSBuild macros that expand to multiple files. The `.vcxproj` project system for C++ builds is more restrictive than MSBuild. Each project item is required to have its own MSBuild item. For more information on the `.vcxproj` file format, see [`.vcxproj` and `.props` file structure](vcxproj-file-structure.md).
1111

12-
It's possible to edit a project file to add wildcards. The project may seem to work at first. However, as soon as the project is modified by Visual Studio and then saved on disk, build issues are sure to occur. The issues will grow, and eventually cause random crashes and undefined behavior in the IDE. The more files a wildcard expands to, the sooner the problems manifest themselves.
12+
These construct examples aren't supported by the IDE:
1313

14-
We've recently seen an increase of reports of related build crashes from customers. We worked on addressing them as a bug fix in Visual Studio 2019 version 16.6. The choices were either to:
14+
```xml
15+
<ItemGroup>
16+
<None Include="*.txt">
17+
<ClCompile Include="a.cpp;b.cpp"/>
18+
<ClCompile Include="@(SomeItems)" />
19+
</ItemGroup>
20+
```
21+
22+
In versions of Visual Studio before 16.7, if a `.vcxproj` project file that includes these constructs gets loaded in the IDE, the project may seem to work at first. However, issues are likely as soon as the project is modified by Visual Studio and then saved on disk. You may experience random crashes and undefined behavior.
23+
24+
To mitigate this problem, starting in Visual Studio 2019 version 16.7, when Visual Studio loads a `.vcxproj` project file, it automatically transforms unsupported entries in project items. You'll see warnings in the Output window during solution load that mention automatic wildcards expansion. If you don't want your project modified in this way, you can unload the project without saving it.
25+
26+
Visual Studio 2019 version 16.7 also adds read-only project support. Read-only support allows the IDE to use manually authored projects that don't have the additional limitations of IDE-editable projects.
27+
28+
If you have a `.vcxproj` file that uses one or more of the unsupported constructs, you can make it load in the IDE by using one of these options:
29+
30+
- List all items explicitly
31+
- Mark your project as read-only
32+
- Move wildcard items to a target body
33+
34+
## List all items explicitly
35+
36+
Currently, there's no way to make wildcard expansion items visible in the Solution Explorer window in a non-read-only project. Solution Explorer expects projects to list all items explicitly.
1537

16-
- fail project load in the IDE if it contains wildcards, or
17-
- automatically modify the project, so it doesn't contain wildcards.
38+
To make `.vcxproj` projects automatically expand wildcards in Visual Studio 2019 version 16.7 or later, set the `ReplaceWildcardsInProjectItems` property to `true`. We recommend you create a *`Directory.Build.props`* file in a root directory, and use this content:
1839

19-
We chose the second option, to help people bring their projects into a supported state. The modified projects aren't saved automatically. You'll see warnings in the Output window during solution load that mention automatic wildcards expansion. If you don't want your project modified in this way, you can unload the project without saving it. This behavior is equivalent to the first option, that fails to load the project.
40+
```xml
41+
<Project>
42+
<PropertyGroup>
43+
<ReplaceWildcardsInProjectItems>true</ReplaceWildcardsInProjectItems>
44+
</PropertyGroup>
45+
</Project>
46+
```
47+
48+
This property is a way to explicitly specify the same actions that Visual Studio 2019 version 16.7 or later takes on project load.
2049

2150
## Mark your project as read-only
2251

@@ -32,11 +61,9 @@ The `<ReadOnlyProject>` setting prevents Visual Studio from editing and saving t
3261

3362
It's important to know that the project cache isn't available if Visual Studio detects wildcards in project items in the *`.vcxproj`* file or any of its imports. Solution load times in the IDE are much longer if you have lots of projects that use wildcards.
3463

35-
## Use wildcards in a project that's not read-only
64+
## Move wildcard items to a target body
3665

37-
Currently, there's no way to make wildcard expansion items visible in the Solution Explorer window in a non-read-only project. That would require full wildcard support in *`.vcxproj`* projects. Instead, you must change your projects to list all items explicitly.
38-
39-
Maybe you don't need to see the wildcard items in the Solution Explorer, but you do want to use wildcards. You might use them for gathering resources, adding generated sources, and so on. If so, you can use this procedure instead:
66+
You may want to use wildcards to gather resources, add generated sources, and so on. If you don't need them listed in the Solution Explorer window, you can use this procedure instead:
4067

4168
1. Change the name of the item group to add wildcards. For instance, instead of:
4269

@@ -52,7 +79,7 @@ Maybe you don't need to see the wildcard items in the Solution Explorer, but you
5279
<_WildCardClCompile Include="*.cpp" />
5380
```
5481

55-
1. Add this content to your *`.vcxproj`* file. Or, add it to *`Directory.Build.targets`* in a root directory, to affect all projects under that root:
82+
1. Add this content to your *`.vcxproj`* file. Or, add it to a *`Directory.Build.targets`* file in a root directory, to affect all projects under that root:
5683

5784
```xml
5885
<Target Name="AddWildCardItems"
@@ -64,7 +91,7 @@ Maybe you don't need to see the wildcard items in the Solution Explorer, but you
6491
</Target>
6592
```
6693

67-
This change makes the build see the items as they're defined in the *`.vcxproj`* file. However, now they aren't visible in the Solution Explorer window, and they won't cause build problems.
94+
This change makes the build see the items as they're defined in the *`.vcxproj`* file. However, now they aren't visible in the Solution Explorer window, and they won't cause problems in the IDE.
6895

6996
1. To show correct IntelliSense for `_WildCardClCompile` items when you open those files in the editor, add the following content:
7097

@@ -80,17 +107,7 @@ Maybe you don't need to see the wildcard items in the Solution Explorer, but you
80107
Effectively, you can use wildcards for any items inside a target body. You can also use wildcards in an `ItemGroup` that isn't defined as a project item by a [`ProjectSchemaDefinition`](https://devblogs.microsoft.com/cppblog/vc-MSBuild-extensibility-example/).
81108

82109
> [!NOTE]
83-
> If you move wildcard includes from a *`.vcxproj`* file to an imported file, they won't be visible in the Solution Explorer window. This change also allows project load in the IDE without modification. We don't recommend this approach, because it disables the project cache.
84-
85-
## Why `.vcxproj` projects don't have the same wildcard support as C# projects
86-
87-
The reason for the current C++ *`.vcxproj`* project structure and feature set is historical. The original C++ project system in Visual Studio existed before MSBuild and C# were created. When the Visual Studio C++ build system moved to MSBuild, the main goal was to allow the best conversion from the old project format. We wanted to maintain all the features of the original C++ build system. The *`.vcxproj`* projects were never designed to be human editable, even before MSBuild. So, Visual Studio has never supported all MSBuild constructs in *`.vcxproj`* files. Visual Studio needs the ability to automatically edit the project. It's required so the right things happen during a build, and to show the correct things in the Property Pages UI. This automation means the project has to have a particular structure, correctly ordered groups, and strictly limited conditions.
88-
89-
This inflexibility causes a number of pain points in manually created *`.vcxproj`* files. There are extra rules and limitations on them so they're editable in the IDE: more than what's needed to just build them in MSBuild. Currently, we recommend you only create and edit *`.vcxproj`* projects in the IDE, and avoid manual editing as much as possible. Instead, add custom props or targets if you need more customizations. Handy places to insert customizations are the *`Directory.Build.props`* and *`Directory.Build.targets`* files, which are automatically imported in all MSBuild-based projects.
90-
91-
In Visual Studio 2019 version 16.7, we've also added read-only project support. Read-only support allows the IDE to use manually authored projects that don't have the additional limitations of IDE-editable projects.
92-
93-
Performance and scalability have always been high priorities for Microsoft C++, so developers can work with large codebases of 10,000 projects or more. Wildcard support hasn't been a priority before. Future wildcard support in *`.vcxproj`* files is possible, but it's not simple. It has significant performance implications. That's because of the inevitable increase in disk I/O during solution load, up-to-date checks (F5), and IntelliSense operations. If you'd like to voice your support for wildcards in C++ projects in the IDE, you can [upvote this suggestion ticket on Developer Community](https://developercommunity.visualstudio.com/idea/1080317/support-globwildcards-first-class-in-visual-studio.html).
110+
> If you move wildcard includes from a *`.vcxproj`* file to an imported file, they won't be visible in the Solution Explorer window. This change also allows your project to load in the IDE without modification. However, we don't recommend this approach, because it disables the project cache.
94111
95112
## See also
96113

0 commit comments

Comments
 (0)