14

I have a project on TFS that is working on everyone else's machine, except mine. When building I get the error that can be seen in the image. "The specified task executable location csc.exe is invalid." currently trying to repair VS 2017 now.

Jayendran
  • 9,638
  • 8
  • 60
  • 103
Ha66y-Day
  • 197
  • 1
  • 2
  • 12
  • Possible duplicate of [The specified task executable location "...\packages\Microsoft.Net.Compilers.1.3.2\build\..\tools\csc.exe" is invalid](https://stackoverflow.com/questions/50686183/the-specified-task-executable-location-packages-microsoft-net-compilers-1-3) – NH. Sep 20 '18 at 15:43

4 Answers4

19

Based on the message, seems the csc.exe is damaged.

Just try below things to narrow down the issue:

  • Navigate to the Microsoft.Net.Compilers package location, delete the package folder, then rebuild. Generally the package will be restored automatically during the build.

    YOUR_PROJECT_DIR\packages\Microsoft.Net.Compilers.2.6.1

  • Uninstall and Re-install the Microsoft.Net.Compilers package:

    1. Open Visual Studio
    2. Go to Tools -> NuGet Package Manager -> Manage NuGet Packages for Solution
    3. Go to Installed tab and find Microsoft.Net.Compilers package
    4. Uninstall the package from your project
    5. Try to build your project now. (Thus it will use the default compiler which lives in the .NET framework folder: C:\Windows\Microsoft.NET\Framework\v4.0.30319\csc.exe)
    6. If you really need the Microsoft.Net.Compilers package then go ahead and find it in the Browse tab and install the latest stable version.
    7. Build the project and if everything works, make sure you commit changes to your code repository.
  • You can also try to run below command to uninstall and reinstall the Nuget packages from the Package Manager Console: See Microsoft.Net.Compilers

    Uninstall-Package Microsoft.Net.Compilers -Version 2.6.1

    Install-Package Microsoft.Net.Compilers -Version 2.6.1

Trenton McKinney
  • 56,955
  • 33
  • 144
  • 158
Andy Li-MSFT
  • 28,712
  • 2
  • 33
  • 55
5

Remove Microsoft.CodeDom.Providers.DotNetCompilerPlatform and Microsoft.Net.Compilers Nuget Packages.

Ronen Festinger
  • 2,260
  • 1
  • 23
  • 32
  • 1
    This indeed worked for me, so good answer. None-the-less, I have to ask "Why Microsoft, why?" On the surface, this seems a very harmful thing to do, so the fact that it makes things better is just really odd. – JosephDoggie Apr 24 '23 at 20:48
2

Installing MSBuild 2015 will resolve the issue. https://www.microsoft.com/en-us/download/confirmation.aspx?id=48159

  • 1
    The specified task executable location "C:\Program Files (x86)\MSBuild\14.0\Bin\csc.exe" is invalid. Now it is not. Thanks. – Corey Alix Jul 31 '20 at 22:49
1

I hit this question even though my error was "The specified task executable csc.exe could not be run" when pulling down existing web project with unit tests and trying to run it locally for the first time.

I was able to resolve this by building each project individually in my solution.

Dennis Mieszala
  • 549
  • 4
  • 8