1

I have a WPF C# 4.0 Application. I was publishing projects fine before but all of a sudden one particular project starts to not publish. I get the following errors after a successful build.

Error 2 Could not find file 'obj\x86\Release\CSCDemo.exe'. CSCDemo.0

Next error is 'failed to Publish'

I know that CSCDemo.exe is in the Release folder because I checked.

Would Microsoft Visual Studio 2010 Service Pack 1 fix this?

Jason
  • 652
  • 8
  • 23
  • possible duplicate of [ClickOnce - Cannot publish because a project failed to build](http://stackoverflow.com/questions/7869129/clickonce-cannot-publish-because-a-project-failed-to-build) – JohnFx Jun 15 '12 at 03:16

4 Answers4

1

I have just suffered from this problem. It seems my Avast Anti-Virus was deleting the file as soon as it was created. I just added my project folder to it's global exclude list and everything worked fine again.

AriesUK
  • 11
  • 2
1

The packager is looking at the obj\x86 folder, not the normal bin\release folder for your exe. I am thinking the issue has to do with either the packager looking in the wrong place or you have changed the project properties for your CSCDemo project. Have you changed it from being an x86 application to x64?

Another thing to try would be a complete rebuild.

IAmTimCorey
  • 16,412
  • 5
  • 39
  • 75
  • I did not change it from x86 to x64 as a matter of fact, it is just that project that won't build. Others build without any problem. – Jason May 02 '11 at 19:58
  • Have you deleted all of the dynamically-created files and done a complete rebuild? Maybe the file appears to be there when it builds but it isn't. – IAmTimCorey May 02 '11 at 20:05
0

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 followign section just before the final </project> tag.

<Target Name="BeforePublish">
<Copy SourceFiles="$(TargetPath)" DestinationFolder="$(IntermediateOutputPath)" />
</Target> 
JohnFx
  • 34,542
  • 18
  • 104
  • 162
  • Be careful when posting copy and paste boilerplate/verbatim answers to multiple questions, these tend to be flagged as "spammy" by the community. If you're doing this then it usually means the questions are duplicates so flag them as such instead: http://stackoverflow.com/questions/7869129/clickonce-cannot-publish-because-a-project-failed-to-build/11041599#11041599 – Kev Jun 15 '12 at 00:05
  • 1
    Sorry. I just spent forever Googling this and searching SO for this answer today and every place I went it was a Q without an A. Trying to help other people avoid my fate. – JohnFx Jun 15 '12 at 03:13
0

change the platform from x86 to Any CPU will help

Build>configuration manager change the platform against CSCDemo to Any CPU

sugee
  • 11
  • 3