11

I'm trying to publish a WPF Application (to a folder) targeting .NET Core 3.1, using Publish Single File, targeting win-x86. The application publishes fine for Debug, but fails for Release. If I deselect Produce Single File, the publish works fine. I'm using Visual Studio 2019 (16.4.1 and preview 16.5.1)

I get this generic error when I publish:

Publish has encountered an error. Publish has encountered an error. We were unable to determine the cause of the error. Check the output log for more details.

A diagnostic log has been written to the following location: "C:\Users\username\AppData\Local\Temp\tmpD176.tmp"

Plus a not-so-helpful log file:

System.AggregateException: One or more errors occurred. ---> System.Exception: Publish has encountered an error. We were unable to determine the cause of the error. Check the output log for more details. 
   --- End of inner exception stack trace ---
   at System.Threading.Tasks.Task.ThrowIfExceptional(Boolean includeTaskCanceledExceptions)
   at System.Threading.Tasks.Task.Wait(Int32 millisecondsTimeout, CancellationToken cancellationToken)
   at Microsoft.Publish.Framework.Model.DefaultPublishSteps.<>c__DisplayClass26_0.<IsBuildCompletedSuccessfully>b__2()
   at System.Threading.Tasks.Task`1.InnerInvoke()
   at System.Threading.Tasks.Task.Execute()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.Publish.Framework.Model.DefaultPublishSteps.<DefaultCorePublishStep>d__23.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.Publish.Framework.ViewModel.ProfileSelectorViewModel.<RunPublishTaskAsync>d__156.MoveNext()
---> (Inner Exception #0) System.Exception: Publish has encountered an error. We were unable to determine the cause of the error. Check the output log for more details. <---

System.Exception: Publish has encountered an error. We were unable to determine the cause of the error. Check the output log for more details. 

I found this question that suggests that it might be an issue with Visual Studio timing out, though that issue is related to Azure. I also found this Github issue that showed a similar when I tried publishing with ReadyToRun.

We published with success a few weeks ago, with minimal changes. Could this be an issue with Visual Studio? I realize that this may be an issue with references and NuGet packages, but I don't really know where to start to get to the core of this issue... publishing doesn't provide any helpful information on what might be causing the issue. Any ideas?

VirtualValentin
  • 1,131
  • 1
  • 11
  • 19
  • 3
    Did you try to publish it from the command-line using the `dotnet` CLI? – mm8 Dec 16 '19 at 13:42
  • 1
    @mm8 Thanks, that helped provide more information, but it still did not resolve the issue. I suspect the issue may be with Visual Studio though. – VirtualValentin Dec 17 '19 at 11:39

6 Answers6

5

I had the same problem with a WPF application :

VS2019 16.3 and dotnet Core 3.0 - publish worked fine.

Updated to VS2019 16.4.1 and dotnet Core 3.1 - publish failed as described.

Only difference is I am targeting X64.

After multiple attempts editing the publish FolderProfile (none of which fixed the problem), I deleted the FolderProfile completely and created a new one targeting a different folder.

Publish works again.

Hope this helps.

MaxTheCoder
  • 125
  • 9
  • 1
    Somehow, that worked for me..but only sometimes. After reverting back to .net core 3.0, I was able to Publish, but then when I switched the runtime between 64 and 86, it ran into the same issue. Switching back also ran into the same error again. I'm trying to play around with it to see what might be triggering this, but I can't seem to reproduce the error now. What worked for me was to clear out my NuGet cache (and delete the nuget folders if necessary). I'll continue to investigate and if I can track down the issue to reproduce it, I'll mention so here. – VirtualValentin Dec 17 '19 at 11:38
  • 1
    Further update: Still having intermittent problems with subsequent builds. Solution: Delete bin, obj and publish folders. Then rebuild and create new publish folder. Then seems to publish OK – MaxTheCoder Jan 02 '20 at 17:57
2

I am getting the same issue, but I think mine is related to the project not even being able to build when I set "PublishSingleFile".

I added a comment to their github issue post, assuming that it's a bug on their end since .net core 3.0 is publishing for me fine.

Alienator
  • 185
  • 2
  • 9
2

For me the error has to do with custom nuget sources, like Azure DevOps Artifacts. Sometimes the build script tries to restore nugets from Azure DevOps and fails with a (Unauthorized) error, which produces the error in the post.

Temporarily disabling the custom nuget sources, makes publish work again regardless of the options used like single file.

1

i have a same problem, in my case the solution is delete some dll of X86 system from .csproj file :

<ItemGroup>
    <Reference Include="System.Management">
      <HintPath>..\..\..\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.6.1\System.Management.dll</HintPath>
    </Reference>
  </ItemGroup> 
izik f
  • 2,387
  • 2
  • 16
  • 17
0

It is worth checking your Internet connection. I had a problem publishing self-contained deployment, because I was behind corporate firewall. Same error as yours:

Publish has encountered an error. We were unable to determine the cause of the error. Check the output log for more details.

And nothing more informative in that log file. After I disconnected VPN app was published with no errors.

Pawel
  • 891
  • 1
  • 9
  • 31
0

I had this same issue when i publish my application also. And the weird thing is it solved when i added this to my package reference in .csproj file

    <PackageReference Include="EFCore.BulkExtensions" Version="5.2.8" />

After adding this package reference, when i rebuild and publish, it is working.

RABI
  • 692
  • 2
  • 15