|
| 1 | +--- |
| 2 | +title: Troubleshoot and create logs for MSBuild problems |
| 3 | +ms.date: 06/27/2019 |
| 4 | +ms.topic: conceptual |
| 5 | +helpviewer_keywords: |
| 6 | + - msbuild logs" |
| 7 | +author: mikeblome |
| 8 | +ms.author: mblome |
| 9 | +manager: jillfra |
| 10 | +dev_langs: |
| 11 | + - CSharp |
| 12 | + - VB |
| 13 | + - CPP |
| 14 | +ms.workload: |
| 15 | + - "multiple" |
| 16 | +ms.description: "Generate build logs for msbuild projects to collect helpful information when troubleshooting issues." |
| 17 | +--- |
| 18 | + |
| 19 | +# Troubleshoot and create logs for MSBuild problems |
| 20 | + |
| 21 | +The following procedures can help you diagnose build problems in your Visual Studio project, and, if necessary, create a log to send to Microsoft for investigation. |
| 22 | + |
| 23 | +## A property value is ignored |
| 24 | + |
| 25 | +If a project property appears to be set to particular value, but has no effect on build, follow these steps: |
| 26 | + |
| 27 | +1. Open the Visual Studio Developer Command Prompt that corresponds to your version of Visual Studio. |
| 28 | +1. Run the following command, after substituting the values for your solution path, configuration, and project name: |
| 29 | + |
| 30 | + ```cmd |
| 31 | + msbuild /p:SolutionDir="c:\MySolutionDir\";Configuration="MyConfiguration";Platform="Win32" /pp:out.xml MyProject.vcxproj |
| 32 | + ``` |
| 33 | +
|
| 34 | + This command produces a "preprocessed" msbuild project file (out.xml). You can search that file for a specific property to see where it is defined. |
| 35 | +
|
| 36 | +The last definition of a property is what the build consumes. If property is set twice, the second value overwrites the first. Also, MSBuild evaluates the project in several passes: |
| 37 | +
|
| 38 | +- PropertyGroups and Imports |
| 39 | +- ItemDefinitionGroups |
| 40 | +- ItemGroups |
| 41 | +- Targets |
| 42 | +
|
| 43 | +Therefore, given the following order: |
| 44 | +
|
| 45 | +```xml |
| 46 | +<PropertyGroup> |
| 47 | + <MyProperty>A</MyProperty> |
| 48 | +</PropertyGroup> |
| 49 | +<ItemGroup> |
| 50 | + <MyItems Include="MyFile.txt"/> |
| 51 | +</ItemGroup> |
| 52 | +<ItemDefinitionGroup> |
| 53 | + <MyItems> |
| 54 | + <MyMetadata>$(MyProperty)</MyMetadata> |
| 55 | + </MyItems> |
| 56 | +</ItemDefinitionGroup> |
| 57 | +<PropertyGroup> |
| 58 | + <MyProperty>B</MyProperty> |
| 59 | +</PropertyGroup> |
| 60 | +``` |
| 61 | + |
| 62 | +The value of "MyMetadata" for "MyFile.txt" item will be evaluated to "B" during build (not "A" and not empty) |
| 63 | + |
| 64 | +## Incremental build is building more than it should |
| 65 | + |
| 66 | +If MSBuild is unnecessarily rebuilding a project or project item, create a detailed or binary build log. You can search the log for the file which was built or compiled unnecessarily. The output looks something like this: |
| 67 | + |
| 68 | +```output |
| 69 | + Task "CL" |
| 70 | +
|
| 71 | + Using cached input dependency table built from: |
| 72 | +
|
| 73 | + F:\test\Project1\Project1\Debug\Project1.tlog\CL.read.1.tlog |
| 74 | +
|
| 75 | + Outputs for F:\TEST\PROJECT1\PROJECT1\PROJECT1.CPP: |
| 76 | + F:\TEST\PROJECT1\PROJECT1\DEBUG\PROJECT1.OBJ |
| 77 | + Project1.cpp will be compiled because F:\TEST\PROJECT1\PROJECT1\PROJECT1.H was modified at 6/5/2019 12:37:09 PM. |
| 78 | +
|
| 79 | + Outputs for F:\TEST\PROJECT1\PROJECT1\PROJECT1.CPP: |
| 80 | + F:\TEST\PROJECT1\PROJECT1\DEBUG\PROJECT1.OBJ |
| 81 | +
|
| 82 | + Write Tracking Logs: |
| 83 | + Debug\Project1.tlog\CL.write.1.tlog |
| 84 | +``` |
| 85 | + |
| 86 | +If you are building in the Visual Studio IDE (with detailed output window verbosity), the **Output Window** displays the reason why each project is not up-to-date: |
| 87 | + |
| 88 | +```output |
| 89 | +1>------ Up-To-Date check: Project: Project1, Configuration: Debug Win32 ------ |
| 90 | +
|
| 91 | +1>Project is not up-to-date: build input 'f:\test\project1\project1\project1.h' was modified after the last build finished. |
| 92 | +``` |
| 93 | + |
| 94 | +## Create a binary msbuild log |
| 95 | + |
| 96 | +1. Open the Developer Command Prompt for your version of Visual Studio |
| 97 | +1. From the command prompt, run one of the following commands. (Remember to use your actual project and configuration values.): |
| 98 | + |
| 99 | + ```cmd |
| 100 | + Msbuild /p:Configuration="MyConfiguration";Platform="x86" /bl MySolution.sln |
| 101 | + ``` |
| 102 | +
|
| 103 | + or |
| 104 | +
|
| 105 | + ```cmd |
| 106 | + Msbuild /p:/p:SolutionDir="c:\MySolutionDir\";Configuration="MyConfiguration";Platform="Win32" /bl MyProject.vcxproj |
| 107 | + ``` |
| 108 | +
|
| 109 | +A Msbuild.binlog file will be created in the directory that you ran MSBuild from. You can view and search it by using the [Msbuild Structured Log Viewer](http://www.msbuildlog.com/). |
| 110 | +
|
| 111 | +## Create a detailed log |
| 112 | +
|
| 113 | +1. From the Visual Studio main menu, go to **Tools** > **Options** > **Projects and Solutions** >**Build and Run**. |
| 114 | +1. Set **Msbuild project build verbosity** to **Detailed** in both combo boxes. The top one controls build verbosity in the **Output Window** and the second one controls build verbosity in the \<projectname\>.log file that is created in the each project's Intermediate directory during build. |
| 115 | +1. From a Visual Studio developer command prompt, enter one of these commands, substituting your actual path and configuration values: |
| 116 | +
|
| 117 | + ```cmd |
| 118 | + Msbuild /p:Configuration="MyConfiguration";Platform="x86" /fl MySolution.sln |
| 119 | + ``` |
| 120 | +
|
| 121 | + or |
| 122 | +
|
| 123 | + ```cmd |
| 124 | + Msbuild /p:/p:SolutionDir="c:\MySolutionDir\";Configuration="MyConfiguration";Platform="Win32" /fl MyProject.vcxproj |
| 125 | + ``` |
| 126 | +
|
| 127 | + An Msbuild.log file will be created in the directory that you ran msbuild from. |
0 commit comments