1

I have a VS2012 solution. One of the Project A generates a .h file at runtime. This header file is used by another Project B. Project A and Project B are in the same directory.

However when Project B starts rebuild, C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V110\Microsoft.CppClean.targets deletes the files generated by Project A. Due to this Project B cannot find the file anymore and build fails.

How can I avoid the files being deleted during a clean build? Should the two projects be moved to a different directory?

Note that this problem does not occur in Visual Studio 2008.

jessehouwing
  • 106,458
  • 22
  • 256
  • 341
Amol
  • 21
  • 4

3 Answers3

1

Have you set the build order in the solution? It has to be explicitly set that project B depends on A, unless you use the project referencing functionality built into VS to directly set the dependency between the two projects.

Community
  • 1
  • 1
Mgetz
  • 5,108
  • 2
  • 33
  • 51
  • Yes, the project dependencies are correctly set. Project A builds first and generates files at runtime. When Project B start a build it deletes these files although the files are nneded for project B to build. – Amol Aug 05 '13 at 07:37
  • @YonatanSimson then ask a new question – Mgetz May 03 '15 at 15:49
1

Is this header generated in the temp ("Intermediate") directory by a "Build Event"? If so, then Project B assumes it's a temp file and deletes it. This is because project B's cleanup finds the header in the temp directory but doesn't know that it's an output of Project A. Possible solutions:

  • Separate the output folder from the temp folder and generate the header in the output folder.
  • Keep the output and temp folders together but separate the output/temp folder of Project A from that of Project B.
  • Generate the header in a Custom Build Step instead of a Build Event, and specify the header as the Output of the step.
Lev
  • 6,487
  • 6
  • 28
  • 29
0

I faced same issue while migrating to VS 2015. The solution is to set the "Configuration Property->General->Intermediate Directory" to ..\\$(ProjectName)\ so that Build.CppClean doesn't clean up previous build dlls from other unrelated projects. This worked for me.