When I try to publish my (WPF, C#) application, I get these errors:
Cannot publish because a project failed to build.
Could not find file 'obj\x86\Debug\MyAPP.exe'
I get these errors no matter where from I publish: publish wizard, build menu or right click on project - publish.
First it was working ok, but I did the following:
I changed the date om my computer to 10/10/2013, I was trying something else.
I forgot this and I click build. Then I set the proper date on computer. After that I get these errors.
Also every time I click run Visual Studio builds project whether there are changes in project.
I also noticed that when I set the date after 10/10/2013 it works ok.
I am guessing that I am looking for some settings in my project where this date of build is set.
I tried build, rebuild, clean solution.

- 291
- 1
- 3
- 9
-
So why don't you CLEAN and REBUILD your solution? – Al Kepp Oct 23 '11 at 20:59
-
3I did that, still does not work. – Rajko Oct 23 '11 at 21:13
11 Answers
This is a problem with Visual Studio that can occur when you have add-ins installed. Instead of using the Publish button in the Publish tab, use Build/Publish from the menu on the top of Visual Studio.
If you use the Publish button, it runs through the add-ins before doing the build (or something like that). If you use Build from the menu instead, it goes straight to msbuild and ignores any add-ins you have installed.
If you have DevExpress installed and are still having problems, check out this article: http://www.devexpress.com/Support/Center/p/Q260132.aspx

- 11,723
- 3
- 30
- 33
-
I managed to escape running in safemode or uninstalling add-ins.. life-saver! – Dead.Rabit Aug 06 '12 at 14:50
-
I have SiteCore, Resharper addins recently installed and one of those components is the culprit. – Kye Jul 24 '13 at 01:45
-
-
This fixed my problem. DevExpress and VMWare addins here. Thanks – Janiek Buysrogge Sep 17 '15 at 13:49
With the date back to normal, close VS and try deleting your *.suo files next to the *.sln files and then reopen the solution

- 2,439
- 2
- 17
- 21
I'm not sure exactly how your development machine can get fouled up this way, but this started happening for several developers in our group too.
After researching it, it appears that the built in build/publish script that Visual Studio (2010 in our case) uses has a flaw in the order that it does things. Most importantly it runs a cleanup on the OBJ directory deleting the target EXE file before the publish step can grab it.
The solution
This is somewhat of a hacky workaround, but it solved the problem for me.
The fix is to copy the file back to the /obj/
folder from the /bin/
folder right before the publish step. Unfortunately there is no way that I know to specify a BeforePublish event through the IDE, so you will have to edit the .vbproj file in a text editor.
Add the following section just before the final </project>
tag.
<Target Name="BeforePublish">
<Copy SourceFiles="$(TargetPath)" DestinationFolder="$(IntermediateOutputPath)" />
</Target>

- 34,542
- 18
- 104
- 162
I solved my problem. The problem was the "Modified" time of some files. I used the program Timestamp to fix it.
As I said in my question, the problem was that I build the solution and the date was in the future. Because of that, every time I pressed F5 Visual Studio was building the whole solution again and Publish ClickOnce wasn't working.

- 30,738
- 21
- 105
- 131

- 291
- 1
- 3
- 9
-
This worked for me as well. I had put my machine's clock forward to test something, then later in the day could not publish my clickonce app. Lesson learned is that when putting the clock forward, only do it once the app is built and then set the clock back before building again. – user381624 Jan 01 '14 at 00:07
Just create a new ClickOnce manifest certificate, and it will work again.

- 30,738
- 21
- 105
- 131

- 11
- 1
-
Oh, how I wish this had been higher in the list of answers. I would have saved several hours of needless head-banging. – bwperrin Mar 30 '17 at 19:00
If nothing else works, try this :
- Set your date to the proper date.
- With VS closed, delete all the bin and obj folders of your solution.
- Create a new empty solution.
- Add your existing projects to the solution.
- Add back the needed references.
- Rebuild to make sure you didn't miss anything.
- Publish.
If you want, you can also just try step 1, 2, 6, 7 before, if you don't feel like making a new solution.

- 7,367
- 4
- 37
- 59
I just ran into the problem today. In my particular case, it was caused by Microsoft Windows Update, Microsoft Security Advisory 2661254 (concerning minimum certificate key length).
I uninstalled that update and publish began working as it always had. This is only a temporary work around and means you should probably regenerate your keys/certificates.

- 30,738
- 21
- 105
- 131

- 12,504
- 2
- 35
- 51
I've had this error when I'd been swapping git branches. A Rebuild All fixed this for me.

- 4,473
- 2
- 29
- 35
In my case, the problem arise when I added the following section in .csproj File:
<Target Name="AfterBuild">
</Target>

- 612
- 8
- 19
I have sometimes had problems with an ASP.NET project publishing, because the publish wizard couldn't delete files in the directory it was trying to publish the files to.
Try clearing out those file manually before publishing. Also check the output window; it will sometimes give you some hints as to why the publish failed.

- 30,738
- 21
- 105
- 131

- 712
- 4
- 14