msbuildprojects-and-solutionsc89ansi-c

Learning about MsBuild project files for Compiling Ansi C90


The following main wants to be compiled via msbuild

#include <stdio.h>

int main (int argc, char *argv[])
{
    char Buffer[2000];
    printf("TEST");
    gets(Buffer);
}

A Batch file calls msbuild:

C:\Windows\Microsoft.NET\Framework\v4.0.30319\msbuild main.vcxproj
pause

The msbuild project file is as follows.

<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <ItemGroup Label="ProjectConfigurations">
    <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" />
  <Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
  <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
  <ItemGroup>
    <ClCompile Include="main.c" />
  </ItemGroup>
</Project>

The whole setup works so far but i need to find a good source to help me learn more about msproject files. I want to learn multiple things. How can I:


Solution

  • There is a great book with lots of sample code to do everything you are talking about.

    Inside the Microsoft® Build Engine: Using MSBuild and Team Foundation Build

    Here is how you can call clean and then the build targets and also have it compile the the debug and release configurations. C:\Windows\Microsoft.NET\Framework\v4.0.30319\msbuild main.vcxproj /t:clean;build /p:Configuration=Debug;Release /p:platform=Win32

    The copy task:

    <ItemGroup>
        <MySourceFiles Include="c:\MySourceTree\**\*.*"/>
    </ItemGroup>
    
    <Target Name="CopyFiles">
        <Copy
            SourceFiles="@(MySourceFiles)"
            DestinationFiles="@(MySourceFiles->'c:\MyDestinationTree\%(RecursiveDir)%    (Filename)%(Extension)')"
     />
    

    This link might help you with some of your other questions.

    Walkthrough: Using MSBuild to Create a Visual C++ Project