59

When using Visual Studio 2008, when I "Publish Web Site", the application builds correctly, but then I get a "Publish failed" message:

enter image description here

What possible reasons are there for this, and how can I prevent it?

6
  • @yytg - What sort of info do you require? I'm not given any sort of warnings. Build is successful, why would publish fail?
    – Curtis
    Nov 14, 2011 at 11:30
  • 2
    @curt: output window log might give some more required info. Also, check this link
    – NaveenBhat
    Nov 14, 2011 at 11:48
  • Hi @Knvn, this has solved my problem. I didn't know I could check that. The folder I was compiling to, I didn't have correct permissions. Please create an answer, and I'll mark it :)
    – Curtis
    Nov 14, 2011 at 11:57
  • For me it was when I tried to publish a service with "Delete Existing Files = true" option, but the service's directory contained a file which I kept open. So I close the file, and the service was published successfully.
    – Alex34758
    Dec 22, 2017 at 11:37
  • @NaveenBhat In my case (VS 2017) the output window immediately clears after "Publish failed" message pop-ups. I barely had a time to print screen it.
    – Alex34758
    Dec 22, 2017 at 11:44

25 Answers 25

67
+50

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.

8
  • 11
    That was my issue too, thanks. I had to remove CodeDom.Providers.DotNetCompilerPlatform first, as it has a dependancy on Net.Compilers.
    – Mackan
    Feb 20, 2018 at 15:28
  • 3
    FWIW, If I use version 2.4 of Microsoft.Net.Compilers then my publish succeeds. If I upgrade then it fails to publish.
    – Dan
    Apr 19, 2018 at 13:30
  • 1
    This fixed the problem for me, it is certainally worth testing if you have this problem. HOWEVER, now I watch for the inclusion of these assemblies, and I have noticed projects will sometimes include them and not have any publishing issues. (Differing versions? Build Settings? I don't know why they sometimes will cause publish failures yet.)
    – Roger Hill
    Apr 27, 2018 at 20:35
  • 1
    Wow! Removing Microsoft.Net.Compilers solved my problem! I thought I'd try it before doing it the hard way and that was it. I'd love to know why - will have to research it some time.
    – Steve
    Feb 20, 2019 at 18:21
  • 1
    Hat's of to you for discovering this one, very tricky and very annoying.
    – GBGOLC
    Mar 13, 2019 at 11:51
18

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.

1
  • I had to completely delete the source folders and re-clone from git. Once I did that, the deploy worked without warnings or errors!
    – Owen
    Mar 17, 2021 at 15:46
12

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

1
  • This is what worked for me, simply right click VS, run as Administrator, and then open the project inside the VS that just opened.
    – RedNet
    Jun 1, 2018 at 12:24
6

I had to copy project to C:\a\ and than publish. I suspect problems with long path. Strange, but worked for me.

2
  • 1
    I am still getting this on windows 10... The message showed up once in the "Web Publish Activity" window. Something about file path greater than 260 characters, which matches msdn.microsoft.com/en-us/library/windows/desktop/…. But I've tried publishing several times since, and the message hasn't come back.
    – Stephen
    Jan 25, 2018 at 19:43
  • Thank you, I was able to publish the app after copying the project from the shared drive to a local folder. I'm using VS 2022.
    – ln29st
    Dec 16, 2022 at 15:07
4

The conclusion is: Try another VS edition and see if that does it.

Here is what did it for me.

I have VS 2013 Pro and Visual Studio 2015 Community. I sort of use one or another to work on my MVC project and all was fine. Then all of the sudden VS 2013 could not publish though it would build just fine. There was no erros other than some silly ...code is not returned from all paths...

So when I open it in VS 2017 - it published the same project just fine. I am suspecting a compiling issue - because that was the stage it would fail at.

Hope that helps you save a bit of time.

1
  • 1
    Thanks Alexey Shevelyov. You gave me an idea. My project was created in VS2017 and i was trying to publish from VS2013 so it was throwing error and when i tried with VS2017 it worked. Apr 13, 2018 at 6:28
3

Make sure you empty the target folder (manually) before publishing. Sometimes vs cant delete a file which will result in a failed publish

3

Not sure if this happens in different versions of Visual Studio, but at least in 2015 Professional Edition, the problem arises when we try to update all Nuget packages from the solution using the Packages Manager.

As pointed out by @SimonGoldstone the issue is caused by the package "Microsoft.Net.Compilers". By default, the package gets added to the solution while creating a new web application. The default version 1.0.0 does not introduce any problems. I was able to keep testing with latest versions until 2.4.0 and everything works fine, but from 2.6.0 henceforth is when it all starts. If an update is strictly required, I would recommend updating the aforementioned package until version 2.4.0. After doing some research, seems that some bugs on later versions than 2.4.0 are introduced and not fixed on the long term. What is curious though, is how this problem gets included on Nuget with no basic quality control checkpoint.

1
  • 2
    Also, pre-2.4.0 versions seem to have a dependency on Microsoft.CodeDom.Providers.DotNetCompilerPlatform, while 2.4.0 and later do not. Aug 30, 2018 at 21:37
3

There are many proposed solutions for this. I think they are overcomplicating the issue. I found the following worked for me:

  1. Locate the obj(Release or Debug) folder in your solution
  2. Inside the Release or Debug folder delete the CONTENTS of the 'AspnetCompileMerge' folder

Now try and publish.

1
  • 2
    Tried it. Doesn't work.. went as far as deleting the entire obj folder. Oct 10, 2019 at 9:16
2

After trying a Rebuild, having other Projects in my Solution able to publish correctly, and changing my publish location to the C: drive (locally attached) instead of pushing to a mapped network drive, I was still having an issue where the only error output said:

========== Build: 5 succeeded, 0 failed, 0 up-to-date, 0 skipped ==========
========== Publish: 0 succeeded, 1 failed, 0 skipped ==========

My solution is targeting x86, but I think during a Git Merge, this project had it's profile switched to Any CPU. After creating an x86 profile for the project and having it match the target of the publish goal and of the active solution configuration, I was able to successfully publish again.

1

Check Project BIn directory. there must be a DLL of your page or control. which has to be recreated during publish. So exclude it or remove it

1
  • 1
    Please provide more clarification as to why this would cause the given error message. Jan 3, 2013 at 7:45
1

I ran into this same problem today and it was due to the Thumbs.db file that was created when I opened my images folder to look for an image. I deleted the file and the project deployed successfully. Hope this helps someone else in the same situation.

1
  • I deleted an image from sln folder but it showed in VS. I delete an image from VS then publish succssed. Jan 1, 2018 at 6:48
1

Delete publish profile and create another one . Worked for me

0

In my case, I was publishing to a directory in a mapped network drive, but the Output panel/window was indicating that the location didn't exist. The path was correct, and the drive was fully accessible. The problem resolved itself when I re-set the path to publish to in Visual Studio by using the ... button.

0

With me it was simple - the dist folder was locked. I unlocked it by an unlocker and the publishing resumed.

0

I have several user controls that are registered in the web.config, and have a ClassName in the .ascx file header. For normal builds everything works fine, but with a publish those class names were not recognized anymore. At some point I found out that the errors were not in my regular code files, but in copies in a temp directory for publishing.

I had "Precompile during publishing" turned on (to be found under Settings > File Publish Options). Turning that option off worked for me.

0

I had the same issue with VS2017 with a website project. Build worked, but publish gave me an error: Error CS0012: The type 'System.Net.Http.HttpMessageHandler' is defined in an assembly that is not referenced. You must add a reference to assembly 'System.Net.Http, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. All my projects already had a reference to System.Net.Http so it was really confusing.

To fix it, I had to copy System.Net.Http.dll into my website project / bin folder so publish could find it and copy it to my web host. I found System.Net.Http.dll by looking at another project's references (a class library), then System.Net.Http.dll Properties, and seeing the path (C:\Program Files(x86)\Reference Assemblies\Microsoft\Framework.NetFramework\v4.6\System.Net.Http.dll).

0

i know iam late but i think it should use for someone whos searching for this query.

just uninstall all your nuget pakages , then clean and rebuilt solution , now click on publish , sure it works and u will see publishing starts and works correctly now

0

If any one had changed the version of the project file and related framework. then this type of issue happened.

please go to "C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\MSBuild\Microsoft\VisualStudio\v16.0\Web" location for visual studio published and build setting -> edit -> comment the force copy of all file section.

enter image description here

0

I had one file that was not found. I had copied in a png file to replace a jpg in the content folder , same name except filetype extension. Project built fine, but refused to build and publish . changed extension of file so it could find that file name and it worked - no errors amazing 1 thing wrong and everything else is an error.

0

The case for me was that Visual Studio was not signed in to Azure, but provided no indication of that. I edited the publish profile, clicked "Validate Connection" then clicked "Save" and then it worked.

enter image description here

enter image description here

0

I was working on a feature branch, which was failing. Switched to Master Branch, deleted the feature one and created another one. It worked.

0

I had this problem with an ASP.NET application targeting 4.6.1 version using VS 2017 Community Edition. The issue started to appear just out of nowhere. The build would succeed and I can run the project locally. But, when I tried to publish the app to Azure using publish profile, it gave me build errors (like namespace missing or class not found).

What worked for me is deleting the Release folders of all the projects in the solution and then publishing the app.

0

I had the same problem. Fixed it switching the debug mode to release modeand cleaned and then switched to debug mode and started publish. This fixed the issue for me.

I'm using visual studio 2022

-1

What caused my issue was a little different, but has similarities to some of the reasons stated above.

I managed to trash my local copy of a given application and did a GIT hard reset to get the most recent from the repository in question. This in turn, wiped out the web.config file (which was not stored in the GIT repository for various reasons).

This cause configuration information for various NuGet packages to be "lost" (since it was stored in web.config).

Fortunately, I had "backed up" the web.config, so once I figured out it was not out there (a migration failed because I was unable to connect to the database), I was able to replace it.

Tried the publish again, after fixing the web.config, and everything worked perfectly.

-1

If you are opting for the "Delete all existing files prior to publish" in the publish web dialog box, then make sure that the Visual Studio is started with Admin rights. Right click the Visual Studio and click Run as Administrator. Hope this helps.

0

Not the answer you're looking for? Browse other questions tagged or ask your own question.