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

5

6

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:

  • I set "Yes (/Gm)" to My project's configuration properties\C/C++\Code Generation\Enable Minimal Rebuild. It still compiles all the project's files upon F7.
Gastrectomy answered 21/12, 2010 at 20:38 Comment(0)
R
6

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.

Rabah answered 20/1, 2011 at 10:17 Comment(0)
L
3

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
Lipetsk answered 21/12, 2010 at 20:44 Comment(6)
Also: incorrect custom build rules, a build step that ends up touching a top level headerMerbromin
Yes, I probably messed up my configuration somehow, but I rather not start from scratch. I'm looking for the specific configuration that I changed by mistake.Gastrectomy
I don't believe there is a configuration for that. This is the way VS works always.Lipetsk
@Merbromin - could you elaborate? Where can I see the build rules?Gastrectomy
@Jonathan: The build rules are different for different file types. Did you create this project yourself? If so then you probably won't have any custom build rules. If someone else created them then they may exist. They are exposed in the 'Custom build' section of the project properties, on a per-file basis.Merbromin
One other thing to try: create an entirely new SCM checkout and see if the problem goes away. If you have some timestamp/file corruption issues in your build tree then this should solve it.Merbromin
A
2

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.

Ashcraft answered 17/8, 2013 at 5:17 Comment(0)
T
2

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#.

Threequarter answered 12/11, 2013 at 17:15 Comment(0)
H
1

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.

Himes answered 20/1, 2012 at 12:29 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.