I am trying to understand the visual cpp project document here (https://docs.microsoft.com/en-us/cpp/build/walkthrough-using-msbuild-to-create-a-visual-cpp-project).
<Project DefaultTargets="Build" ToolsVersion="12.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<ProjectConfiguration Include="Debug|Win32">
<Configuration>Debug</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|Win32">
<Configuration>Release</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.default.props" />
<PropertyGroup>
<ConfigurationType>Application</ConfigurationType>
<PlatformToolset>v120</PlatformToolset>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ItemGroup>
<ClCompile Include="main.cpp" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="main.h" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Targets" />
</Project>
I gather that ClCompile, is an item as it is nested under the ItemGroup tag, it also seems that the files to be compiled are referred to in the ClCompile tag. On the documentation page for Items, https://docs.microsoft.com/en-us/visualstudio/msbuild/msbuild-items, it states that Items are inputs into the build system. I dont see a task above which takes these ClCompile items and compiles them, how is compilation being achieved? Is the ClCompile item as task as well?
After search all the
.targets
and.props
files in theVCTargets
folder under following path:We could find following code snippet in the
Microsoft.CppCommon.targets
file:So
ClCompile
should be a target, which is used to execute the Visual C++ compiler tool,cl.exe
to compile the C/C++ source file. That is reason why it not in the MSBuild-item.See MSBuild (Visual C++) Overview for some more details.
Yes, CLCompile actually runs the CLTask task class. I suspect (though don't know for sure) they did it that way so they could have both CLCompile and CLInclude without having to write task implementations for each. I am not sure what namespace that is found in or the assembly, unlike tasks for pure .net languages the c++ tasks are not in the .net library docs.