dotnet / deployment-tools

This repo contains the code to build the .NET deployment tools and installers for all supported platforms, as well as the sources to .NET deployment tools.
MIT License
169 stars 50 forks source link

Clickonce deployment from the command line #69

Closed MarcDrexler closed 3 years ago

MarcDrexler commented 3 years ago

Hi, I'm trying to publish a winforms app (net core 3.1) through the command line. I created a new ClickOnce Profile using Visual Studio (16.8.1), and a click on the publish button was also successful.

I think Visual Studio is using "dotnet publish" in the background. What command line options are used?

When I try "dotnet publish -p:PublishProfile=ClickOnceProfile" I get the following output:

Microsoft (R) Build Engine version 16.8.0+126527ff1 for .NET
Copyright (C) Microsoft Corporation. All rights reserved.

  Determining projects to restore...
  All projects are up-to-date for restore.
C:\Program Files\dotnet\sdk\5.0.100\Microsoft.Common.CurrentVersion.targets(4187,5): error : MSB4803: The task "FormatUrl" is not supported on the .NET Core version of MSBuild. Please use the .NET Framework version of MSBuild. See https://aka.ms/msbuild/MSB4803 for further details. [C:\Users\Marc\source\repos\WindowsFormsApp2\WindowsFormsApp2\WindowsFormsApp2.csproj]
NikolaMilosavljevic commented 3 years ago

@MarcDrexler I believe dotnet publish experience is not enabled at the moment. However, you can still use command-line to publish projects created in Visual Studio using VS Developer prompt and an MSBuild command like the following: msbuild /t:publish -p:PublishProfile=ClickOnceProfile

cc @sujitnayak @John-Hart

RomainAn commented 3 years ago

It works with msbuild you will face some issues as i do. Some attribute of your pubxml file will not being used (Such as Configuration, PublishFolder) Also the version will not being incremented.

MarcDrexler commented 3 years ago

@NikolaMilosavljevic thanks! That helped me and I have now been able to integrate it into our pipeline.

However, I can install the application and updates are also detected and installed at startup. BUT then unfortunately the actual app does not start and the event log shows this error:

Description: A .NET Core application failed.
Application: WindowsFormsApp.exe
Path: C:\Users\Marc\AppData\Local\Apps\2.0\1WJ1DONM.ET3\MRA6O97E.P2Z\mwm...tion_0000000000000000_0001.0000_7b484d170583d1a4\WindowsFormsApp.exe
Message: Error:
  An assembly specified in the application dependencies manifest (WindowsFormsApp.deps.json) was not found:
    package: 'System.Data.SqlClient', version: '4.8.1'
    path: 'runtimes/win/lib/netcoreapp2.1/System.Data.SqlClient.dll'

I have no idea how to fix this or what to do. When I start the executable from the application files directory and not through the application reference shortcut, everything is fine. So I think it must have something to do with the ClickOnce/Launcher mechanism?

I have also updated to TargetFramework net5.0-windows in the meantime, but the error still persists.

@RomainAn In our process we have separated the creation of the final ClickOnce package from the build time and postponed it further when it comes to deployment. At build time we don't know e.g. what environment it is and thus what the PublishLocation should be... and many other configuration settings. Therefore we update the application manifest and sign it again with dotnet-mage at the time of deployment. The files are then copied into the respective directory via a separate task. With dotnet-mage, all switches worked wonderfully. Perhaps this information can help you achieve your goal.

John-Hart commented 3 years ago

We're tracking the missing file issue here: https://developercommunity2.visualstudio.com/t/A-NET-Core-31-or-NET-50-application-/1248873.

Using dotnet-mage is the only work around right now.

NikolaMilosavljevic commented 3 years ago

Closing in favor of the VS issue linked above.

AchimStuy commented 3 years ago

@NikolaMilosavljevic

However, you can still use command-line to publish projects created in Visual Studio using VS Developer prompt and an MSBuild command like the following: msbuild /t:publish -p:PublishProfile=ClickOnceProfile

What is the exact command?

I have following .csproj (stripped down):

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <OutputType>WinExe</OutputType>
    <TargetFramework>net5.0-windows</TargetFramework>
    <UseWindowsForms>true</UseWindowsForms>
    <UseWPF>true</UseWPF>
  </PropertyGroup>

</Project>

I also tried with Sdk="Microsoft.NET.Sdk.WindowsDesktop" and <TargetFramework>netcoreapp3.1</TargetFramework>

AchimStuy commented 3 years ago

Please excuse, I tried with normal PowerShell. With Developer Command prompt, as you said, it's working.

mc0re commented 3 years ago

Any chance ClickOnce will work with dotnet cli?

John-Hart commented 3 years ago

We recommend using dotnet mage for creating a ClickOnce manifests from the cli

mc0re commented 3 years ago

@John-Hart mage is a tool that has to be installed via dotnet tool install, which means I cannot use it in an Azure DevOps pipeline. Is there a way to create a click once package along with setup.exe from a pipeline?

mc0re commented 3 years ago

@John-Hart Creating manifests comes after the files are published. I cannot publish due to "FormatUrl task not supported".

mc0re commented 3 years ago

mage is a tool that has to be installed via dotnet tool install, which means I cannot use it in an Azure DevOps pipeline. Is there a way to create a click once package along with setup.exe from a pipeline?

I guess I can use the dotnet custom command to install it.