'Publish failed' but build succeeded?

I had the same issue. Nightmare to identify the problem, because the logs and outputs show no errors or failures. I simply get "Build: 39 succeeded" and "Publish: 1 failed".

I resolved the problem by systematically removing all NuGet packages one at a time (and removing code that references it) until I identified the offending one.

This takes a LONG time!

However, the answer for me was Microsoft.Net.Compilers.

No idea how I ended up with that in my project, but as soon as I removed that package, everything publishes fine again.

Edit - For what it's worth, this problem occurs on VS 2008, 2012 and 2015 but does not occur on 2017.


You can try this:

  1. Perform precompilation against the web application.

  2. Clear the target directory(virtual directory in IIS or physical file folder) and deploy all the files (of the web application) into the target directory.

In the output window you can check at which stage does the publish website operation fail. For example, at the first stage, if there are some error which will only occur at precompilation, that will cause the stage 1 fail. Or some times if the target directory has something configured incorrectly. Such as the IIS virtual dir is not set to the correct ASP.NET version or some old files are locked and prevent them from being cleared. Mostly, publish failed will be caused by IIS side configuration issue such as authentication setting....

Source link

You can open the output window by pressing Ctrl+W, O.


Sometimes it's because you need to be running VS as Administrator to be able to write to the target directory.

Check the Output messages, they should help you solve the problem