views:

1790

answers:

11

I know the ideal way to build projects is without requiring IDE based project files, since it theoretically causes all sort of trouble with automation and what not. But I've yet to work on a project that compiles on Windows that doesn't depend on the VisualStudio project (Ok, obviously some Open Source stuff gets done with Cygwin, but I'm being general here).

On the other hand if we just use VS to run a makefile, we loose all the benefits of the compile options window, and it becomes a pain to maintain the external makefile.

So how do people that use VS actually handle external makefiles? I have yet to find a painless system to do this...

Or in reality most people don't do this, although its preached as good practice?

+1  A: 

Personally, I use Rake to call msbuild on my solution or project. For regular development I use the IDE and all the benefits that provides.

Rake is set up so that I can just compile, compile and run tests or compile run tests and create deployable artifacts.

Once you have a build script it is really easy to start doing things like setting up continuous integration and using it to automate deployment.

You can also use most build tools from within the IDE if you follow these steps to set it up.

Garry Shutler
Garry: I have a question out there about using MsBuild and Rake together. I'd love to get your answer to it! Thanks! http://stackoverflow.com/questions/679009/anyone-have-experience-calling-rake-from-msbuild-for-code-gen-and-other-benefits
Charlie Flowers
That's beyond anything I've done if I'm honest but I'll be keeping tabs on that question as I'd be interested to know what you or someone else comes up with.
Garry Shutler
We just call msbuild directly, it's not rocket science.
Anton Tykhyy
+2  A: 

Ideally perhaps, in practice no.

Makefiles would be my preference as the build master, however, the developers spend all their time inside the visual studio IDE and when they make a change, it's to the vcproj file, not the makefile. So if I'm doing the global builds with makefiles, it's too easily put out of synch with the project/solution files in play by 8 or 10 others.

The only way I can stay in step with the whole team is to run devenv.exe on the solution files directly in my build process scripts.

There are very few makefiles in my builds, where there are they are in the pre-build or custom build sections or a separate utility project.

SumoRunner
What's wrong with custom building everything? It enforces keeping the makefiles up to date, doesn't it?
Simon Buchan
The developers prefer the IDE over all else and I can't force them to learn Nmake. That would put all the makefile maintenance on my shoulders and I'm not going to do their work for them.
SumoRunner
You don't need to run devenv.exe. Msbuild is part of the .NET framework.
Anton Tykhyy
msbuild is what is used by Visual Studio to run builds, and msbuild can be run from the command line, without ever opening VS or running devenv.exe. Use the VS tool for development and command-line msbuild for automated builds - same build, and same project structure.
Cheeso
+1  A: 

We use the devenv.exe (same exe that launches the IDE) to build our projects from the build scripts (or the command line). When specifying the /Build option the IDE is not displayed and everything is written back to the console (or the log file if you specify the /Out option)

See http://msdn.microsoft.com/en-us/library/xee0c8y7(VS.80).aspx for more information

Example:

devenv.exe [solution-file-name] /Build [project-name] /Rebuild "Release|Win32" /Out solution.log

where "Release|Win32" is the configuration as defined in the solution and solution.log is the file that gets the compiler output (which is quite handy when you need to figure out what went wrong in the compile)

Milander
Actually it's devenv.com that displays results in the console. devenv.exe immediately returns after it's run and does the building process in background.
macbirdie
At least that's the case in VS 2005.
macbirdie
It's better to use msbuild for console build, because VS uses msbuild for solution and project compilation
abatishchev
devenv.exe is required for things like Setup projects, which don't have an msbuild-compatible project file format. For other projects using msbuild from the cmd line is superior.
Cheeso
+1  A: 

We have a program that parses the vcproj files and generates makefile fragments from that. (These include the list of files and the #defines, and there is some limited support for custom build steps.) These fragments are then included by a master makefile which does the usual GNU make stuff.

(This is all for one of the systems we target; its tools have no native support for Visual Studio.)

This didn't require a huge amount of work. A day to set it up, then maybe a day or two in total to beat out some problems that weren't obvious immediately. And it works fairly well: the compiler settings are controlled by the master makefile (no more fiddling with those tiny text boxes), and yet anybody can add new files and defines to the build in the usual way.

That said, the combinatorical problems inherent to Visual Studio's treatment of build configurations remain.

brone
+5  A: 

Take a look at MSBuild!

  • MSBuild can work with the sln/csproj files from VS, so for simple projects you can just call them directly.
  • if you need more control, wrap the projects in your own build process, add your own tasks etc. - it is very extensible!

(I wanted to add a sample but this edior totally messed up the XML... sorry)

chris
+1  A: 

We use a NAnt script, which at the compile step calls MSBuild. Using NAnt allows us to perform both pre- and post-build tasks, such as setting version numbers to match source control revision numbers, collating code coverage information, assembling and zipping deployment sources. But still, at the heart of it, it's MSBuild that's actually doing the compiling.

You can integrate a NAnt build as a custom tool into the IDE, so that it can be used both on a build or continuous integration server and by the developers in the same way.

David M
+1  A: 

Why would you want to have project that "compiles on Windows that doesn't depend on the VisualStudio project"? You already have a solution file - you can just use it with console build.

I'd advise you to use msbuild with conjunction with makefile, nant or even simple batch file if your build system is not as convoluted as ours...

Is there something I'm missing?

ya23
Well a full build of our system's ten components and modules takes about 2 hours (release only), and a few more in all build modes. Plus 8 of the systems need to compile under unix and several other compilers. Yeah it's kinds complex :)
Robert Gould
We need to make a build for unix and windows. For this, we use combination of msbuild, makefiles and ant. And it isn't that bad :) Perhaps you should try to optimize the build process - at least iterative build speed. We recently cut build time from 35 mins to 7...
ya23
well we have solid state drives, because linking and full program optimization eat up about a third of the time. Been looking into other optimizations, but no luck yet.Anyways your set up beats our current setup, we don't have a build engineer.
Robert Gould
+1  A: 

How about this code?

public TRunner CleanOutput()
{
    ScriptExecutionEnvironment.LogTaskStarted("Cleaning solution outputs");

    solution.ForEachProject(
        delegate (VSProjectInfo projectInfo)
            {             
                string projectOutputPath = GetProjectOutputPath(projectInfo.ProjectName);

                if (projectOutputPath == null)
                    return;

                projectOutputPath = Path.Combine(projectInfo.ProjectDirectoryPath, projectOutputPath);

                DeleteDirectory(projectOutputPath, false);

                string projectObjPath = String.Format(
                    CultureInfo.InvariantCulture,
                    @"{0}\obj\{1}",
                    projectInfo.ProjectName,
                    buildConfiguration);
                projectObjPath = Path.Combine(productRootDir, projectObjPath);
                DeleteDirectory(projectObjPath, false);
            });

    ScriptExecutionEnvironment.LogTaskFinished();
    return ReturnThisTRunner();
}

public TRunner CompileSolution()
{
    ScriptExecutionEnvironment.LogTaskStarted ("Compiling the solution");

    ProgramRunner
        .AddArgument(MakePathFromRootDir(productId) + ".sln")
        .AddArgument("/p:Configuration={0}", buildConfiguration)
        .AddArgument("/p:Platform=Any CPU")
        .AddArgument("/consoleloggerparameters:NoSummary")
        .Run(@"C:\Windows\Microsoft.NET\Framework\v3.5\msbuild.exe");

    ScriptExecutionEnvironment.LogTaskFinished ();
    return ReturnThisTRunner ();
}

You can find the rest of it here: http://code.google.com/p/projectpilot/source/browse/trunk/Flubu/Builds/BuildRunner.cs

Igor Brejc
Interesting proposal
Robert Gould
+1  A: 

I haven't tried it myself yet, but Microsoft has a Make implementation called NMake which seems to have a Visual Studio integration:

Armin Ronacher
no - nmake is old, has been around for years and years. It is delivered as part of the .NET Framework sDK and Windows SDK. But it is not the thing that VS uses for builds. Visual Studio uses msbuild. That's what you should look into.
Cheeso
+2  A: 

One possibility is to use CMake - you describe with a script how you project is to be built, and CMake generates the Visual Studio solution/project files for you.

And if you need to build your project from the command line, or in a continuous integration tool, you use CMake to generate a Makefile for NMake.

And if you project is a cross-platform one - you can run CMake to generate the makefiles for the toolchain of your choice.

A simple CMake script looks like this:

project(hello)
add_executable(hello hello.cpp)

Compare these two lines with a makefile or the way you setup a simple project in your favorite IDE.

In a nutshell CMake does not only cross-platform-enables your project it also makes it cross-IDE. If you like to just test your project with eclipse or KDevelop, or codeblocks, just run CMake to generate the corresponding project files.

Well, in practice it is no always so easy, but the CMake idea just rocks.

For example, if you consider using CMake with Visual Studio there is some tweaking required to obtain the familiar VS project feeling, main obstacle is to organize your header and source files, but it is possible - check the CMake wiki (and by writting a short script you might even simplify this task).

siddhadev
+1  A: 

Visual Studio since VS2005, uses "msbuild" to define and run builds. When you fiddle with project settings in the Visual Studio designer - let's say you turn XML doc generation on or off, or you add a new dependency, or you add a new project or Assembly reference - Visual Studio will update the .csproj (or .vbproj, etc) file, which is an msbuild file.

Like Java's ant or Nant before it, msbuild uses an XML schema to describe the project and build. It is run from VS when you do a "F6" build, and you can also run it from the command line, without ever opening VS or running devenv.exe.

So, use the VS tool for development and command-line msbuild for automated builds - same build, and same project structure.

Cheeso
Almost--Visual Studio 2005 and 2009 use msbuild only for VB and C# projects. C and C++ projects still use the older vcproj engine in these versions. VS2010 apparently switches to MSBuild for C++ as well.If he's talking about external makefiles, chances are he's building C or C++.
Tim Lesher