Syed Farjad Zia Zaidi
Syed Farjad Zia Zaidi

Reputation: 3360

The specified task executable "cmd.exe" could not be run.The specified executable is not a valid application for this OS platform

I am getting this weird error on Windows 10 when I try to build any project. The projects are working fine if I build them on other OS.

The specified task executable "cmd.exe" could not be run. The specified executable is not a valid application for this OS platform.

When I tried to check the log I got to the following code in Nuget.targets file inside .nuget folder, I commented the code and the project builds fine now. I don't understand why the error. Any new projects that I create are working fine...

I am using Visual Studio 2013 on Windows 8, Windows Server 2008 and Visual Studio 2015 on Windows 10.

Code:

<Exec Command="$(RestoreCommand)"
      LogStandardErrorAsError="true"
      Condition="'$(OS)' == 'Windows_NT' And Exists('$(PackagesConfig)')" />

Upvotes: 4

Views: 7775

Answers (5)

TonySalimi
TonySalimi

Reputation: 8437

It happened to me when building my project on Windows 10. The problem was that the path of one file was very long (longer than 260 characters). So, by making it shorter, the problem solved for me.

Upvotes: 1

Jim G.
Jim G.

Reputation: 15382

To those who have landed here:

If you get this message I suggest that you do not, as @Hans Passant suggested, first assume that your machine or Windows has been corrupted.

Instead, I recommend that you suspect that your anti-virus or Carbon Black installation is to blame.

enter image description here

This was the case for me.

Someone from my IT Department disabled a certain Carbon Black policy and everything magically worked again.

Upvotes: 0

RamyRahman
RamyRahman

Reputation: 76

If you started to face this error after deleting some files :

  • Unload your project
  • Edit Your csprok
  • Delete any reference for the your deleted files
  • Reload your project and Build

I faced the same issue when building a .NetCore App using a template that includes an Angular app with it, and i tried to delete the ClientApp folder. I had to remove multiple Target and ItemGroup tags from within the csproj.

Upvotes: 0

niranjan
niranjan

Reputation: 19

I had the same problem with VS c++ OpenFrameWorks. I tried your suggestion but could not solve the problem. I solved it differently as under. Soln: Project Properties -> Build Events ->Post-Build Event -> Command line "robocopy "$(OF_ROOT)/export/vs/$(Platform_Actual)/" "$(ProjectDir)bin/" "*.dll" /njs /njh /np /fp /bytes if errorlevel 1 exit 0 else exit %errorlevel%"

Removed Above line from command-line. OK, Solved.

Upvotes: 0

ksp
ksp

Reputation: 132

I got the same error, and repairing the corrupted files solved my issue. Try this:

  • In administrator command prompt, run sfc /scannow
  • It should emit log file in %windir%\Logs\CBS\CBS.log. Confirm that it repaired cmd.exe. For me I saw something like this Repairing corrupted file [ml:48{24},l:46{23}]"\??\C:\WINDOWS\SysWOW64"\[l:14{7}]"cmd.exe" from store
  • If that doesn't help you can try DISM /Online /Cleanup-Image /RestoreHealth
  • See more here

Upvotes: 4

Related Questions