PostBuildEvent fails with cmd-based statements

1.) Create a new Command-Line App in Visual Studio 2019 on Windows
2.) Go to Project → Properties → Build Events
3.) Add the following in the “Post-build event command line:” box

REM Some Line Here
ECHO Something Here

4.) Build the project in Visual Studio - Note that it completes
5.) Note that the Output window contains “Something Here”
6.) Attempt to add the project to Travis, and build
7.) Note the failure

Possible Solution:

  • If the line starts with the cmd-compatible “REM”, change it to the sh-compatible “#”
  • If the line starts with the cmd-compatible “ECHO”, change it to the sh-compatible “echo”
1 Like

REM and ECHO are cmd.exe builtins. So you need to specify cmd.exe /c <command line> to run them.

This is actually MsBuild’s issue: for some reason, it uses Git Bash rather than cmd.exe to run the commands.

Perhaps it honors the SHELL envvar. But in Windows, the selected command interpreter is supposed to rather be specified in COMSPEC.
If this is true, you should be able to workaround this issue by unsetting SHELL before running MsBuild or changing its value for the command to point to cmd.exe:

SHELL="$COMSPEC" MsBuild.exe <etc>

If the issue persists, please link to a build because copypasting things here gives incomplete information about a problem.

@native-api I encountered problems like this, but it is not caused by REM or ECHO. I don’t understand “the SHELL envvar”. Any help?
https://travis-ci.org/yfdyh000/AntiDupl/builds/384312784#L1562

PreBuildEvent:
  /home/travis/build/yfdyh000/AntiDupl/src/AntiDupl/Antidupl.NET/External.cmd /home/travis/build/yfdyh000/AntiDupl/src/AntiDupl/Antidupl.NET
  /bin/sh: 2: /tmp/tmp2dc71b1eb54a45d29b7ac8a8682cc83c.exec.cmd: /home/travis/build/yfdyh000/AntiDupl/src/AntiDupl/Antidupl.NET/External.cmd: not found

https://github.com/yfdyh000/AntiDupl/blob/cf577c2a049fbf127b775c2b12976c766905c8e2/src/AntiDupl/AntiDupl.NET/External.cmd is a Windows batch file, you can’t run it in Linux (at least, not directly).

Consult the Mono community on how they are suggesting to implement custom scripts to be able to build in both OSes.

Or specify os: windows if you are actually intending to build in Windows. See The Windows Build Environment - Travis CI for more details.

1 Like

According to the link you just linked, C# is not a supported language on Windows.

In fact, If you simply have

os: windows
language: csharp
solution: Reecon.sln

As your travis file, it fails with a

Worker information

6Secret environment variables are not obfuscated on Windows, please refer to our documentation: Best Practices in Securing Your Data - Travis CI

70.05s0.05s3.36sDisabling Windows Defender

8$ powershell -Command Set-MpPreference -DisableArchiveScanning $true

9$ powershell -Command Set-MpPreference -DisableRealtimeMonitoring $true

10$ powershell -Command Set-MpPreference -DisableBehaviorMonitoring $true

11

12C# support for Travis-CI is community maintained.

13Please open any issues at C# - Travis CI Community and … (Removed due to new user limitation)

14latest is either an invalid version of mono or unsupported on this operating system.

15View valid versions of mono at Building a C#, F#, or Visual Basic Project - Travis CI

According to the link you just linked, C# is not a supported language of Windows (… Oddly enough)

If you specify “os: windows”, it fails

os: windows
language: csharp
solution: Reecon.sln

Results in a failure with

latest is either an invalid version of mono or unsupported on this operating system.