How to configure VS to compile only changed code

前端 未结 5 2083
Happy的楠姐
Happy的楠姐 2021-02-14 01:01

I have very big solution, and it compiling every time I\'m tring to debug.
So I know that I can to disable building of all projects at all in solution configuration, but is

5条回答
  •  别那么骄傲
    2021-02-14 01:47

    As Marnix and Anton already said this is what VS normally does. But if you have a lot of projects within your solution which depend on each other and you make changes to a component which will be used by all or most of the other projects it has to build also the others again to make sure everything works as expected.

    Update

    So if it starts to recompile even if you didn't make any change we need to find out how VS tries to find out what it needs to do on a incremental build.

    For this it simply checks the datetimes of every file and if there are any changes. If yes, recompile that file and all its dependents (e.g. changes in a stdafx.h will result in a complete rebuilt, cause normally every source file will reference to this one).

    But there are also exceptions to this behaviour. A setup project for example will always rebuilt, even if there are no changes made (due to this fact I normally exclude the setup project from the build process and start it only manually when needed).

    So if you only have C/C++, C#, VB etc. project which normally support incremental builds there must be something that changes between two builds, even if you don't change anything.

    Here are some possibilities:

    • A pre or post build command that make a change to a source file
      • this can maybe an auto-update of adding the revision number from your repo into a resource of AssemblyInfo file.
      • or a copy/delete command that makes some changes in your directory structure (I used this one time to delete the output directory in a pre-build command to force a rebuild on every build).
    • An auto incrementer of the assembly version
      • maybe by using [assembly: AssemblyVersion("1.0.*")] or some other external process to increase the build number

    If one of the above steps happens to a module from which all or most of your other projects depends on than everything needs to be rebuilt.

提交回复
热议问题