1

Here are the errors I get:

Cannot publish because a project failed to build.

Could not copy the file "obj\Release\JobsRunner.exe.config" because it was not found.

After an hour of searching for a similar problem, the closest thing I found was a problem with a missing exe file (I had a missing config file), I tried the suggested solutions but it didn't solve my problem.

The reason I'm posting this question is because: a. I still don't have a working solution b. I did found a workaround which I want to share with people who will experience the same issue.

My workaround relies on the fact that I'm willing to give up on publishing my config file since I already have a copy of it at the publish destination and it's not about to change in the near future. What I did was editing the .csproj file, where I found the last block to be the cause to the problem:

<!--Override After Publish to support ClickOnce AfterPublish. Target replaces the untransformed config file copied to the deployment directory with the transformed one.-->
  <Target Name="AfterPublish">
    <PropertyGroup>
      <DeployedConfig>$(_DeploymentApplicationDir)$(TargetName)$(TargetExt).config$(_DeploymentFileMappingExtension)</DeployedConfig>
    </PropertyGroup>
    <!--Publish copies the untransformed App.config to deployment directory so overwrite it-->
    <Copy Condition="Exists('$(DeployedConfig)')" SourceFiles="$(IntermediateOutputPath)$(TargetFileName).config" DestinationFiles="$(DeployedConfig)" />
  </Target>

So I figured the problem was that the publish process tried overwriting a non existent file or something like that, and I removed that block. Now the publish works for me.

I also tried disabling ClickOnce since I've noticed this block is related to it, but with no success.

Does anyone has a better solution than my ugly workaround? :)

Thanks

Alonzzo2
  • 959
  • 10
  • 24
  • If the project cannot be built then there's very little reason to hope that what happens next can work. Including copying a .config file that isn't there because, you know, it couldn't be built. Focus on the first error, not the last. – Hans Passant Oct 13 '15 at 11:56
  • @HansPassant, you're right, and it's my bad that I failed to mention that when I try to build the project, not publishing it, everything builds fine and there are no issues. – Alonzzo2 Oct 13 '15 at 12:01

1 Answers1

0

I encountered the error message(s) in VS 2013. Mostly it occured when the debug proces was stopped somewhere in an exception. When clean+build has no effect, closing VS, deleting 'bin' and 'obj' folders en openening VS again has till now always resolved the issue.

The bug exists since VS2003. Compare this site for 31 other answers. Also: renaming the file is often possible and then you can delete it.

Answered by : Visual Studio "Could not copy" .... during build

Community
  • 1
  • 1