'Network share ClickOnce publish creates corrupt setup.exe

I'm using msbuild (version 17.1.0+ae57d105c, from a VS 2022 Developer Command Prompt) to publish a ClickOnce application to a UNC path using the commandline. As such, I'm running what amounts to

>msbuild /t:publish -p:PublishProfile=.\Properties\PublishProfiles\ClickOnceProfile.pubxml /p:PublishDir=\\some\unc\path\

Here, ClickOnceProfile.pubxml is more or less the default one generated by Visual Studio:

<?xml version="1.0" encoding="utf-8"?>
<!--
https://go.microsoft.com/fwlink/?LinkID=208121.
-->
<Project>
  <PropertyGroup>
    <ApplicationRevision>9</ApplicationRevision>
    <ApplicationVersion>1.0.0.*</ApplicationVersion>
    <BootstrapperEnabled>True</BootstrapperEnabled>
    <Configuration>Release</Configuration>
    <CreateWebPageOnPublish>False</CreateWebPageOnPublish>
    <GenerateManifests>True</GenerateManifests>
    <Install>True</Install>
    <IsRevisionIncremented>True</IsRevisionIncremented>
    <IsWebBootstrapper>False</IsWebBootstrapper>
    <MapFileExtensions>True</MapFileExtensions>
    <OpenBrowserOnPublish>False</OpenBrowserOnPublish>
    <PublishProtocol>ClickOnce</PublishProtocol>
    <PublishReadyToRun>False</PublishReadyToRun>
    <PublishSingleFile>False</PublishSingleFile>
    <RuntimeIdentifier>win-x64</RuntimeIdentifier>
    <SelfContained>False</SelfContained>
    <SignatureAlgorithm>(none)</SignatureAlgorithm>
    <SignManifests>False</SignManifests>
    <TargetFramework>net5.0-windows7.0</TargetFramework>
    <UpdateEnabled>False</UpdateEnabled>
    <UpdateMode>Foreground</UpdateMode>
    <UpdateRequired>False</UpdateRequired>
    <WebPageFileName>Publish.html</WebPageFileName>
  </PropertyGroup>
  <ItemGroup>
    <BootstrapperPackage Include="Microsoft.NetCore.DesktopRuntime.5.0.x64">
      <Install>true</Install>
      <ProductName>.NET Desktop Runtime 5.0.16 (x64)</ProductName>
    </BootstrapperPackage>
  </ItemGroup>
</Project>

The command works and reports no errors:

Build succeeded.
    0 Warning(s)
    0 Error(s)

At this point, I would expect \\some\unc\path\setup.exe to be an executable that can be used to install the underlying application. However, the resulting setup.exe is a corrupt 1 kB file consisting mostly of 0x00.

Moreover, if I use publish wizard in Visual Studio 2022, I run into the exact same issue.

I've noticed that during publishing, setup.exe is some ~480 kB large while there's a small temporary file around as well, before setup.exe is ultimately replaced by the corrupt file.

If I change the publish directory from a network path to, say, bin\publish\, the generated setup.exe (which is now 658 kB) works fine.

Is this expected? Am I doing something wrong?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source