Q: how to ignore errors in Visual Studio Custom Build Steps & continue with the Build process?
In my case, I have a NodeJS script which exec
's an executable which may or may not yet be present, as it will be constructed by the first successful Build run. This is a bootstrap script, faking it until that binary does deliver.
Hence, errors are to be expected in there, all of whom are caught by the NodeJS script and handled by 'faking it'.
The problem is that Visual Studio 2019 aborts the Build process after running this script when it observes any errors being reported by it as it logs the exec
(or rather: process.execFileSync
) output. Doesn't seem to matter if I log to stderr or stdout.
Not so relevant, but for the curious folks: here's that NodeJS script. Rough & Ready.
Note: unimportant parts are snipped for brevity: [...]
. The full script is at @@@@
[...]
if (fs.existsSync(replCfile)) {
fs.unlinkSync(replCfile);
}
[...]
try {
if (fs.existsSync(mutoolExe)) {
const stdout = execFileSync(mutoolExe, ['qjsc', '-v', '-c', '-o', replCfile, replJSfile]);
console.log(stdout);
if (fs.existsSync(replCfile)) {
console.log("Successfully generated the repl C source file from repl.js");
}
else {
bootstrap();
}
}
else {
bootstrap();
}
} catch (ex) {
// Note this bit; it'll show up in the answer again!
console.log("COMPILE FAILED:", ex);
bootstrap(true);
}
[...]
function bootstrap(forced) {
if (forced) {
forced = "FORCED";
}
if (!fs.existsSync(replCfile) || forced) {
console.log(`BOOSTRAPPING ${ forced }: faking an empty repl C source file`);
fs.writeFileSync(replCfile, `
[...]
`, 'utf8');
}
[...]
process.exit(0);
}
Investigated: the stuff I tried & looked at
Swallowing errors in pre-build steps in Visual Studio 2010 -- no dice.
set ERRORLEVEL=0
: fails to deliver. No effect.EXIT 0
: ditto. No effect.EXIT /B 0
: no effect. (See also What are the ERRORLEVEL values set by internal cmd.exe commands? https://learn.microsoft.com/en-us/visualstudio/msbuild/how-to-ignore-errors-in-tasks?view=vs-2019 why: if I read that one correctly,/B
is there to let exit codes pass through.)... ContinueOnError="true"
patched into the.vcxproj
file anywhere: no fly zone! This gets worse: now your project won't load at all.
Clearly, MS feels there's a big difference between Pre/Post-Build Steps and Custom Build Steps? Anyway, we look further...
Using robocopy with Visual Studio 2010 Post-build and Pre-build events
I thought: "Heck, I am using robocopy in my builds, let's have a look!". No dice. Same solutions, no worky.
How to suppress initial post-build event error in Visual Studio 2017 (C#)?
That is more recent! But...
I don't have no
<Target>
in.vcxproj
like that. (C# vs C/C++ Project files XML differences.) Jiggled a few bits just for kicks, but again: no worky. This is starting to irritate.How about the Microsoft Documentation?
https://learn.microsoft.com/en-us/cpp/build/troubleshooting-build-customizations?view=msvc-160 ... and its surroundings. Nothing useful. So much for troubleshooting.
Also spent a couple of desperate minutes going through the Microsoft DevStudio forum but as usual, if you want to find something useful, forget that whole arena and go straight to SO. Sigh.
Plenty not worth mentioning
Curious observations (Hints towards an answer)
Whatever I do, it always ends up either as:
✅ no error what-so-ever, ✅ happy Build and we're good ✅.
This happens ONLY after nuking the compiled binaries, i.e. destroying that
muToolExe
the NodeJS script is looking for and trying toexec
.Or when I take out that
execFileSync
call, thus ruining the bootstrap script.❌ errors galore, ❌ Build aborted immediately, ❌ no good ❌.
The only variable here being how many errors you'll get reported in the Visual Studio
Errors
tab. (Of course, you can see those in yourOutput
tab too, but depending on what you just did and messed with, you get either 1(one) error or 2(two). Never (0)zero.
BTW, which version of DevStudio are you using?
v16.10.2 - that's the latest update of DevStud2019 at the time of writing.
I suspect all 2019 versions suffer from this, though. I don't want to downgrade just to verify this, so YMMV.