Visual Studio - Check for Errors After Pre-Build Events - visual-studio

I have a two projects in my visual studio solution. One of them generates source code files for the other, and I want to set up the build events so that this is done automatically when building the child project.
I have a pre-build event command in the child project which executes the parent project. This works as intended, and correctly generates the source code in the child. At this point, the source code is complete and can compile without errors.
However, when I try to build the child project visual studio stops with an error, saying that it cannot find the generated source code files. When pre-build completes though, the files exist and the code compiles without errors.
How do I ensure that pre-build has completed before visual studio checks for errors and compiles?
I’m using VS 2019 if it matters.

Related

Visual Studio 2015 - Minimum Rebuild when Start Debug

My project has 15 projects and 1 solution file
If my source code has not been modified, Visual Studio prompts me if I want to build the 15 project files?
There is a box to say not to display it again, I'm not sure why Visual Studio thinks the code is out of date?
Thanks for the feedback
If my source code has not been modified, Visual Studio prompts me if I
want to build the 15 project files?
No. If your code has not been changed, it will always show up-to-date, not build. VS has the feature of incremental build.
Note: you should click Build button rather than Rebuild. Rebuild will execute clean and then build, so it will always execute the whole build process.
Once you do not modify the resource files, MSBuild will detect that the project has not changed and does not need to be built again, turns out to up-to-date.
Therefore, under normal circumstances, MSBuild will not build again without changing the project.
There is a box to say not to display it again, I'm not sure why Visual
Studio thinks the code is out of date?
In fact, it should not happen.
If you have not made any changes to the project but the build still displays out-of-date, you have to check the diagnostic build log and find it out.
Enter Tools-->Options-->Projects and Solutions-->Build and Run--> set MSBuild project build output verbosity to Diagnostic . And then build your project to find the cause out.
Maybe you have set Copy To Output Directories of some files to Copy always or you have lost the files for inputs and ouputs, .... so on.

Pre-build event stuck in an infinite loop

I'm trying to create a pre build event similar to one described in this post
Build another project by prebuild event without adding reference
This is the command line I'm using in the Pre-build command line of the build events tab in Visual Studio 2015.
"$(DevEnvDir)devenv.exe"
$(SolutionDir)MyFolder\SubFolder\MyProject.csproj /Rebuild "Debug|Any
CPU"
However when I hit Build on the project that contains the pre-build event, it begins launching multiple instances of Visual Studio. I am watching the output directory for bin/Debug and it is conintually cleaning and rebulding the project, each time a new instance of Visual Studio is launched. None of the instances close. They remain running.
EDIT: I noticed even after cancelling the build in the IDE and exiting the IDE, the processes are still running and the debug folder is still being cleaned and updated with new dll's each time.
This is what my task manager looks like during the process

Building a solution file using MSBuild Vs inside Visual Studio

I have a question regarding the difference I have noticed when building a solution file using MSBuild from command line and when doing it inside Visual Studio 2013 Update 4. The solution file I am using contains a lot of projects.
Case: Using MSBuild
After successfully building the solution file, if I try to build it again, MSBuild notifies me that the projects are up-to-date and it doesn't try to compile any source files, which is evidently the expected behavior. Nevertheless, it actually tries to execute or goes through the targets in the Build step trying to determine whether the Output files are out-of-date and this occurs for every project that is existent in the solution. Even though it doesn't build the solution again, the process of checking time stamps of files for each project actually takes quite a long time.
Case: Using Visual Studio
When doing it inside Visual Studio, after a successful build, if I try to build the solution again, then it automatically notifies me that the projects are up-to-date. It actually takes few seconds to return this output. Looking at the build output, I noticed Visual Studio doesn't really execute targets in the Build step to conclude that the projects are up-to-date. So I figured it must be using something different to check the statuses of the projects.
I really want to bridge the performance gap between these two "worlds". I would appreciate any help or hints in regards to how Visual Studio is performing this check or ways I could implement something similar in MSBuild.
Cheers!

VS 2010 - Always execute pre-build event

In my solution I have a project with an attached pre-build event to check if certain files need to be regenerated. This all works fine if something changed in the project (or dependent projects). However, if nothing changed the pre-build event is not triggered.
Is there a way to run the pre-build event everytime VS tries to build a project (even if it is clean from a code file standpoint)?
Alternatively, is there any other way to run a script first before building a project so that I can regenerate my files first?
For a Visual C++ project you may specify Command Line in the Custom build step (Configuration Properties - Custom build step) and leave the field Outputs empty. It will be executed even if the project has no changes.
Here is the similar question.

Visual Studio 2010 custom compile using batch file

I have recently converted a mid-sized Visual Studio 2005 solution to Visual Studio 2010.
One of the projects contains files which are not C/C++ files and are compiled using a batch file running a custom build tool. The output of the custom build step is some C++ files, which must be compiled after that.
The output of the custom build step in the properties for the relevant files is correctly set to the generated C++ files.
The problem is that sometimes VS2010 tries to compile the generated C++ files before the files with the custom build step, which means in a clean build it fails to find the C++ files and fails. If I try building several times eventually it would compile the custom files and then the build will succeed, but this is obviously not a good solution for automated build.
In VS2005 there is no problem building this project, but VS2010 fails to determine the correct compile order from the outputs of the custom build step. Is there another way to force correct compile order in VS2010?
Visual Studio supports parallel builds, it can build more than one project at the same time. This will not work properly if it cannot properly see the dependencies between projects. A custom build can certainly be a troublemaker here. The number of parallel builds is configurable, setting it to 1 would be a very crude but effective workaround. Tools + Options, Projects and Solutions, Build and Run, "maximum number of parallel project builds" setting.
But don't do that, parallel builds can be a huge time saver. You fix this kind of problem by setting project dependencies explicitly. Right-click the project that uses the generated C++ files in the Solution Explorer window and click Project Dependencies. Tick the check box for the project that produces the C++ files. In case it is relevant to other readers, check this answer for a way to create a project that only does the custom build step and nothing else.
Visual Studio 2008 by default executes custom build tools first. The order can be changed via right click menu on project with command "Tool Build Order". This facility is not available in Visual Studio 2010. I do not know of a work-around.
Consider using Visual Studio 2010's "Properties >> Configuration Properties >> Build Events >> Pre-Build Event" as the place where you should issue command(s) to build source files that must be compiled first. In the Command Line field, call upon the cl.exe compiler or use a small external makefile to compile those files. Visual Studio will then compile the rest of your project following this initial step.
I resolved my problem when I noticed that my custom build step runs for only one file at a time. It runs for the next file on the next build etc.
The reason apparently is that my custom build steps are calling a batch file and VS2010 creates one temporary batch file to execute all custom build files.
The solution was pointed in this discussion:
http://social.msdn.microsoft.com/Forums/en-HK/msbuild/thread/ca392036-ebdb-4812-930e-f90aa445cca5
It is simply to prefix all calls to batch files with a "call" statement, thus not terminating the execution of the master batch file prematurely.

Resources