Reputation: 2847
I have a C++ solution with many projects. During compilation I need to build part of projects in Win32 mode. Then execute several shell commands. Then build several projects in x64 mode. Then execute several more shell commands. Then, finally, build one more project in Win32 mode.
I'm tired to do this again and again manually ) How I could automate all these steps?
I use Visual Studio 2015
Upvotes: 4
Views: 4696
Reputation: 491
I would suggest a combination of MSBuild XML automation and Jenkins. In detail :
MSBuild : It comes with Visual Studio. You need to access VS command prompt to access it. In VS command prompt, if you type "MSBuild your_project.vcproj" it will build it for you.
MSBuild XML Files : You can create a simple XML file and pass it to MSBuild. This will greatly help you to organize your build process. It is a large topic , however, you can think of it as Microsoft style makefile/build system ( even though Microsoft has nmake ) and much more convenient. You can define targets, set variables , put conditions , parallelize builds, set actions in order to call shell commands. A very simple one looks like :
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build"
xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<CPPProject>your_cpp_project.sln</CPPProject>
<powershell_execute>powershell.exe -executionpolicy bypass -command</powershell_execute>
<UtilityScript>utility.ps1</UtilityScript>
</PropertyGroup>
<Target Name="Build">
<Exec Command="msbuild.exe $(CPPProject) /p:Configuration=Release /p:Platform=Win32" />
<Exec Command="msbuild.exe $(CPPProject) /p:Configuration=Release_x64 /p:Platform=x64" />
<Exec Command="$(powershell_execute) $(UtilityScript) args" />
</Target>
<Target Name="Clean">
<!-- DO YOUR CLEANING HERE-->
</Target>
</Project>
Jenkins : Once you install it , it will run as a Windows service which has its embedded HTTP server. You can quickly access it with your browser via localhost:8080. Jenkins is another topic on its own , but I find it very convenient to automate commands and organize them as job definitions.
Extra sauce ( Powershell & MSBuild extensions ) : As you can call commands from either MSBuild or Jenkins, you can always Powershell ( in which you can also inline C# code if necessary) I have found this useful where I needed to implement custom logics quickly and easily such as incrementing minor versions before each release etc. Note that there are also extension packs for enriching MSBuild XMLs` functionality.
Downsides of Jenkins and TFS as an alternative : Jenkins is generally very convenient. The main downside on Windows is that it was not straightforward to colorize console outputs , however, it can be dealt with. In general, I have found it very stable. On the other hand, TFS already is a Microsoft solution , I am not sure about its licensing options but it can also be an alternative to Jenkins. In that case , you will be relying more on MSBuild XML file. One of the downsides of TFS 2013 for me was , it was not always working accurately in over network operations due to some conflicts with Microsoft`s http.sys , which was quite disappointing. However, I have not checked TFS2015
General suggestion : As it is a central solution , I`d highly recommend implementing most of your logic in an MSBuild XML file as this will make your build system also easily invokable via command line and also easy to switch between different systems like Jenkins , TFS or others
Other notes :
If it is only MSVC 2015 , you might avoid installing VisualStudio as MSVC2015 has a standalone build : https://blogs.msdn.microsoft.com/vcblog/2015/11/02/announcing-visual-c-build-tools-2015-standalone-c-tools-for-build-environments/
If you go Jenkins way, the very first thing you need to handle is accessing to Visual Studio command prompt. In that case see this : How do I write a build batch script that runs vcvars32.bat, and then continues with the build?
Upvotes: 4
Reputation: 6427
For the same task I've configured local build server with use of TeamCity. It perfectly fulfills your requirements. Here is the instruction for how to create build configuration.
Upvotes: 0