tags:

views:

347

answers:

2
+2  Q: 

MSBuild and C++

If I am content to not support incremental builds, and to code everything via Exec tasks, is there any reason I can't build C++ binaries with an MSBuild script?

I know VS 2010 will actually have support for a true MSBuild based project file, but what I'm trying to do is to integrate an old embedded VC++ 4.0 workspace into an overall larger automated process.

I assume there will be some issues around dependency tracking, but if I'm doing a clean build everytime, is there anything else I should watch out for?

A: 

Let me share with you my build script (VS 2008) perhaps it will be helpful to you. I have this on the windows task scheduler to run every day at noon.

call "C:\Program Files\Microsoft Visual Studio 9.0\VC\bin\vcvars32.bat"

"C:\Program Files\TortoiseSVN\bin\TortoiseProc.exe" /command:update /path:"C:\Users\***\Desktop\Project\***" /closeonend:2

chdir c:\Users\**\Desktop\Project\**

rmdir /s /q C:\Users\***\Desktop\Project\***\bin\x86\Debug\app.publish

msbuild

msbuild /target:publish

chdir c:\Users\***\Desktop\Project\***\bin\x86\Debug

"C:\Program Files\WinRaR\Rar.exe" a -r -df -m5  C:\Users\***\Desktop\Project\***\BetaTest.zip app.publish

"C:\Program Files\SSH Communications Security\SSH Secure Shell\scp2.exe" C:\Users\***\Desktop\Project\***\BetaTest.zip ***@***.****:

del /q C:\Users\***\Desktop\Project\***\CCBetaTest.zip

Edit: in further explanation I load the environment variables for vs build, I then perform an svn update. I clean earlier builds. I build twice (because I'm using XNA and it will fail to copy files half the time), I then zip it and scp it to my server (I have RSA keys for my ssh).

I removed my personal information with the ***

tzenes
I would be more interested in the the MSBuild file itself, unless it is just the project/solution file format from XNA
Joseph Kingry
MSBuild is a program in .Net frameworks 2.0 and later, you can call it from the command line as specified here: http://msdn.microsoft.com/en-us/library/ms164311.aspxIt will build your solution as you specify it (which is actually a number of calls to other programs like the compiler and linker).Its worth noting that you do need to load the vcvars32.bat variables into the shell to make it build properly.You asked if you can build C++ binaries with a script using MSBuild, this is how to do so.
tzenes
+2  A: 

You can write your own ITask or simply call the Exec task with arguments, something like this:

<PropertyGroup> 
  <EvcPath>$(programfiles)\Microsoft eMbedded C++ 4.0\Common\EVC\Bin\EVC</EvcPath>  
  <EvcProjectPath>your.vcw</EvcProjectPath>
</PropertyGroup> 
  <PropertyGroup Condition=" '$(CEPlatform)' == 'WCEARM2003SP' "> 
  <EvcBuildConfig>All - Win32 (WCE ARMV4) $(Configuration)</EvcBuildConfig>
<EvcCEConfig>Smartphone 2003 Device</EvcCEConfig>
</PropertyGroup> 
  <PropertyGroup Condition=" '$(CEPlatform)' == 'WCEARM2003' "> 
  <EvcBuildConfig>ALL - Win32 (WCE ARMV4) PPC2003 $(Configuration)<EvcBuildConfig>
  <EvcCEConfig>POCKET PC 2003</EvcCEConfig>
</PropertyGroup> 

<Target Name="BuildEvcProjects">
  <Exec Command="$(EvcPath) %22$(EvcProjectPath)%22 /make %22$(EvcBuildConfig)%22 /CEConfig=%22$(EvcCEConfig)%22"
  IgnoreExitCode="true">
   <Output TaskParameter="ExitCode" PropertyName="EvcExitCode"/>
  </Exec>
  <Error Text="eVC 4.0 build has encountered an error. Exit code=$(EvcExitCode) " Condition="$(EvcExitCode) != 0" />
</Target>

Ultimately you could have the CE definitions and logic in its own .targets file referenced by the main MSBuild project. Another approach would be calling a batch file.

KMoraz