Publish Single File (Release) fails for WP

2020-07-18 04:33发布

问题:

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?

回答1:

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.



回答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.



回答3:

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.



回答4:

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>