Search code examples
c#wpfclickoncepublish.net-5

.NET 5 TargetFramework issue with referenced project when publishing WPF App over ClickOnce


I'm trying to publish a WPF app with Target Framework net5.0-windows using ClickOnce (Built in VS2019), which has a Project Reference to another .NET5 Class Library.

But I always run into the following exception:

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.

The diagnostic log shows me the exact exception:

System.AggregateException: One or more errors occurred. ---> Microsoft.WebTools.Shared.Exceptions.WebToolsException: 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 ---

---> (Inner Exception #0) Microsoft.WebTools.Shared.Exceptions.WebToolsException: Publish has encountered an error. We were unable to determine the cause of the error. Check the output log for more details. <---

Microsoft.WebTools.Shared.Exceptions.WebToolsException: Publish has encountered an error. We were unable to determine the cause of the error. Check the output log for more details.

The issue can be easily reproduced:

  1. Create new Solution with a WPF project (.NET5)
  2. Create new Class Library (.NET5) in this solution
  3. Reference the ClassLibrary from the WPF App
  4. Try to publish the WPF App with ClickOnce (right-click the WPF App project -> Publish -> ClickOnce, ...)

Here's a Demo project, which I've created followed the steps above:

PublishDemo.Core (Class library)

<Project Sdk="Microsoft.NET.Sdk">
   <PropertyGroup>
      <TargetFramework>net5.0</TargetFramework>
   </PropertyGroup>
</Project>

PublishDemo.Wpf (WPF App)

<Project Sdk="Microsoft.NET.Sdk">
    <PropertyGroup>
        <OutputType>WinExe</OutputType>
        <TargetFramework>net5.0-windows</TargetFramework>
        <UseWPF>true</UseWPF>
    </PropertyGroup>

    <ItemGroup>
        <ProjectReference Include="..\PublishDemo.Core\PublishDemo.Core.csproj" />
    </ItemGroup>
</Project>

The Build output displays the following error:

Metadata file 'C:\work\source\unmanaged\PublishDemo\PublishDemo\PublishDemo.Core\bin\Release\net5.0-windows\PublishDemo.Core.dll' could not be found

When using the Release-build configuration it tries to referece to the path \bin\Release\net5.0-windows which I think does not make any sense because the Class library targets the framework type net5.0. Also after checking the folders the Class library indeed puts the built files into a folder called net5.0.

Problem is I don't know where I can change that or if there is a workaround for that issue. I have already updated to the newest VisualStudio version (16.9.0), since I thought maybe it's because ClickOnce way newly implemented in Vs, but this did not solve the issue. Publishing to a Folder works. Azure I don't have, so I cannot try that.

Can anybody help me with this issue? Also if you need more information, I'm happy to provide it.


Solution

  • I have found this reported issue and the error looks like yours: https://developercommunity.visualstudio.com/t/clickonce-publish-for-net-core-31-and-net-50-may-f/1275937
    Copied with little changes from the thread above:
    It seems the publish command seeks the files in the same target runtime as the published project, even though it could be different (and builds succesfully outside the publish command). The issue occurs even when the app targets net5.0-windows and the class library is net5.0.
    The workaround is to select a specific Target Runtime (i.e. win-x64) on the Configuration page of the Publish Wizard instead of using the default Portable.