问题
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.
回答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.
回答2:
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.
回答3:
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.
来源:https://stackoverflow.com/questions/18018634/microsoft-cppclean-targets-deletes-files-i-need