Jonathan Livni
Jonathan Livni

Reputation: 107292

Visual Studio - How to refrain from compiling all project files every build?

Each time I build my Visual C++ solution in Visual Studio 2010, the entire project (not the entire solution) recompiles.

There must be a flag or configuration somewhere to make VS compile only the changed files + depending files. Where is it?

UPDATES:

Upvotes: 6

Views: 6344

Answers (5)

RedBaron
RedBaron

Reputation: 21

So, I was having the same problem with one of our projects. First, I was able to debug the compiler output by selecting:

-> Tools -> Options -> Projects and Solutions -> Build and Run -> MSBuild project build output verbosity -> Detailed.

It turned out that someone had set the project to always create precompiled headers for all files (/Yc). I changed the option as listed below.

-> Configuration Properties -> Precompiled Header -> Use (/Yu)

Then I set the same option for stdafx.cpp to (/Yc). So compilation of the stdafx.cpp creates the precompiled header, and all the other .cpp files use the precompiled header. This is the default scenario, and I'm not sure how it had changed for out project.

Additionally, I have changed all our compiler settings to be consistent across all projects, including:

1) Setting: C/C++ -> Precompiled Headers -> Precompiled Header -> Use (/Yu) Switch: /Yu Reason: Faster build time.

2) Setting: C/C++ -> General -> Debug Information Format -> Program Database for Edit and Continue Switch: /ZI
Reason: Enables edit-and-continue, thereby improving debugging capability.

3) Setting: C/C++ -> Code Generation -> Enable Minimal Rebuild -> Yes Switch: /Gm Reason: Allow and speed up incremental builds and this is required for /ZI.

Hope that helps. I spent a lot of time messing with our project build settings and reading posts to Stack Overflow, and in the end, I miss C#.

Upvotes: 2

Ruslan Zasukhin
Ruslan Zasukhin

Reputation: 389

The post of tul was push forward for us, because we also have had some projects, which always did re-compile. As result I have found that:

  • yes, option 'Minimal Rebuild' somehow was corrupted in our visual 2010 projects. I guess, this could happens when they was transformed from visual 2005.
  • sign of "corruption" in a particular project is that this option is assigned, i.e. it is in bold. This could be only for some configurations, e.g. Release, or for some architectures, e.g. x64. It could be in bold "NO", but still recompiles.

FIX is as easy as the next steps:

  • select one or even few projects in solution
  • right click on project -> Properties
  • choose Configurations: "All Configurations"
  • choose Platform: "All Platforms" (if you have both x32/x64)
  • Expand C++ group
  • Goto "Code Generation"
  • note option "Enable Minimal Rebuild" -- most probably it will be empty, because different projects/configurations have different values
  • set this option to NO
  • click button Apply
  • again set this option to "inherited from parent"
  • click button Apply. NO you should see that this option becomes "NO" but in plain text.

DONE. No need even to recompile. The next build will be much faster.

Upvotes: 2

tul
tul

Reputation: 1779

I had the same issue, except mine started without reason, without me making any project configuration changes.

I would edit one file, hit build, and it would rebuild the entire project.

After much painstaking experimentation, I found that turning OFF 'Minimal Rebuild' made the problem go away. With that off, I could once more change a file and it would only compile that one file.

The weird thing was, once I had successfully made a build with minimal rebuild disabled, I could turn it back on, and everything was back to normal.

Makes me think that some cache file somewhere had become corrupted perhaps? I had tried deleting all my intermediary directories without joy, so if it was a corrupt file I don't think it was anywhere within my project directories.

Hope this helps.

Upvotes: 1

bavaza
bavaza

Reputation: 11057

If in addition you get the a message similar to:

Creating ".\Release\SomeLib.unsuccessfulbuild" because "AlwaysCreate" was specified.

when building, the reason might be that one of your projects refers to a header file which does not exist on disk (see here and here).

The first link also includes a small C# script to check for this situation. To fix, simply remove the reference to the non-existing header files from your project.

Update

It might be possible that you have your precompiled-headers setting on 'Create'. To fix, right-click your project in the solution browser and select: properties -> C/C++ -> Precompiled Headers -> Precompiled Header. Change the setting from Create to Use or Not Using Precompiled Headers.

Upvotes: 6

tenfour
tenfour

Reputation: 36906

VS should behave like you want it to by default; it sounds like something is flaky going on. Clean the project, and delete your settings files (e.g. .suo / vcproj..user / etc). There are several reasons for this, some of which I've seen are:

  • corrupt settings files
  • system date/time / time zone changes confusing vc
  • permissions issues on the source files

Upvotes: 3

Related Questions