I've turned off the dialog "build failed do you want to launch last successful build", and don't want to turn it back on.
Is there a way to manually (menu command, macro) launch the last successful build, without having to start a build at all?
This is useful to show something to another person while I'm the middle of coding and I've broken the build (or simply don't want to wait for the next compilation, whether it succeeds or fails).
Launching the exe in the bin folder doesn't work, first because it doesn't have the current command-line argument & working directory setup in the build options, and secondly I get asserts: apparently it's expecting to be attached to the debugger (which I think we still have with the "last successful build" dialog?).
This is for Visual C++ 2010.
Tools > Options > Projects and Solutions > Build and Run > "On Run, when projects are out of date:" > Never build
Here is an AutoHotKey script that I use to toggle between "Prompt for build" (using Ctrl+1) and "Never build" (using Ctrl+2).
ToggleBuildBeforeRun(skipBuild)
{
SetTitleMatchMode, 2
IfWinActive, Visual Studio
{
Send !to^ebuild{Space}and{Space}run
Sleep 800
Send {Tab 4}{Down 2}
if (skipBuild)
{
Send {Up 1}
}
Sleep 600
Send {Enter}
}
}
^1::
ToggleBuildBeforeRun(false)
return
^2::
ToggleBuildBeforeRun(true)
return
Related
The VSCode terminal is so slow. I want to run my code in the Windows Command Prompt. I want to set up Visual Studio Code so that every time I click on the "Run Code" icon (like the Youtube play icon) it runs the code in the command prompt. I'm fine if it runs the code in VSCode's integrated command prompt.
I have a Visual Studio 2019 project with a Post-Build-Event, that is calling an EXE file I have written in C#.
Post-Build event:
MyTool.exe "$(TargetPath)"
This EXE file is doing some stuff and then calling another EXE file.
AnotherTool.exe SomeArguments
Problem is, if that second EXE file (AnotherTool.exe) gives an error (on StandardError output) or an exit code != 0, Visual Studio is "seeing" that codes, although the AnotherTool.exe is not called directly from the Post-Build event. The Post-Build just called the MyTool.exe.
I want MyTool.exe to handle that exit codes, so Visual Studio should ignore them. But the build fails, when AnotherTool.exe exits with an error.
Any ideas?
Edit: The "MyTool.exe" is calling the "AnotherTool.exe" using System.Diagnostics.Process. I set RedirectStandardOutput = true and RedirectStandardError = true, and then call the Process with Start() and WaitForExit().
But no matter what that process result is, MyTool.exe is always exiting with Environment.Exit(0) to give a clean exit.
Not an answer, but a Workaround that is working:
I created a batch file, that is calling:
start MyTool.exe %1
With this workaround, the build succeeds without error, and the tool chain is started correctly. I get no more error messages displayed in Visual Studio.
Trade off 1: The "MyTool.exe" is now displayed in a command window while running.
Trade off 2: If "MyTool.exe" fails with exit code != 0, Visual Studio won't notice.
If I remove the "start" from the batch, behaviour is like a direct call of MyTool.exe.
I'm trying to launch a grunt process that will watch for .js file changes and transpile them into one file using grunt tasks. I can run it manually all day long, but I want to make it a pre-build so when a new dev gets the solution, building will launch the watcher. The problem (as you may have guessed) is that the grunt process stays running, so as a pre-build event, it never continues the build. I thought that using start would be asynchronous and would launch it without VS waiting on it to complete to continue the build, but I was mistaken. So, currently, my pre-build event is
cmd /c start $(SolutionDir)ProjectName.Web\run-grunt.cmd $(SolutionDir)
and run-grunt.cmd looks like
cd %1ProjectName.Web
grunt
This works but hangs until I close the cmd window which defeats the whole purpose. So, two questions:
Is this the wrong way to get this watcher kicked off?
Is there a way to structure these such that VS will launch the cmd and then resume the build without waiting for a return?
Have you tried setting your pre-build event to simply run a batch file that executes your current pre-build event? It seems like it will work because the batch file that Visual Studio executes will actually complete, leaving another command window in its wake.
I tested my theory with two batch files:
test1.bat
call "cmd /C start test2.bat"
echo test1
test2.bat
echo test2
pause
If you're still needing some parts of the grunt task to execute pre-build, you can break them out into separate tasks, so your pre-build event may end up looking like this:
cd $(SolutionDir)ProjectName.Web\
grunt build
grunt-watch.bat
I have a solution with multiple projects. One project only needs to build if both two events, in the pre-build event, exit with error code 0.
So I thought I could do the following:
"C:\Path\To\Binary1.exe" & "C:\path\to\binary2.exe"
In my test scenario something goes wrong so Binary1.exe exits with a non-zero value. But visual studio goes on building the project anyway.
When I run the pre-build event commandline in cmd and echo %errorlevel% I see the exit code being non-zero.
When I only put
"C:\Path\To\Binary1.exe"
in the pre-build event, the build is stopped and en error is shown in the Error List window of Visual Studio.
I am definitely sure that Binary1.exe is exiting with a non-zero value as its also shows a messagebox prior to exit.
I can think of one solution. Binary1.exe calling Binary2.exe and exiting with a non-zero exit code when Binary2.exe exits with a non-zero exit code. But that is not really a flexible solution.
To summarize:
How can I run multiple pre-build events and stop buidling when one of the commands returns a non-zero value?
I think yuou can do as follows:
run command 1
if ERRORLEVEL 1 (
exit /b 1
)
run command 2
If the two projects are in the same solution, you can set the dependency in Visual studio.
Right-click on the solution in the solution explorer and choose "Project Dependencies".
Set the 'last' project to be depending on the first two. In this case Visual studio will build in the right order and will stop building if one of the dependencies fail to build.
(Visual Studio 2013)
I'm trying to change the start action for debugging in a VS2010 (C-)project to run a .bat file.
I found on MSDNA a How to: Change the Start Action for Application Debugging on how to do that. Unfortunately, I can't find the mentioned "start action", although I'm using VS2010 (no express version). I have - when choosing the "Local Windows Debugger" - a "Command" field I can edit. I tried to enter there the full path to my .bat file, but that doesn't work, because the "file is unrecognized or unsupported binary format".
Do you know a) why I don't have "start action", b) why the bat file in the "command" field won't run?
Edit This is what it looks like:
just created "console application" in vs2010 and found "Start Action" in place. What kind of project do you have?
edit:
a) "Start Action" is available only for .net projects
b) may be there is a problem with your .bat file. I just created an empty cpp project and set simple .bat file as Command. Everything works as expected.
Here is my .bat file
#echo on
pause
Try to use simple .bat and post the result here