Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WPF Clickonce publish with Microsoft.Net.Sdk

I can successfully build a WPF application with the new csproj format using the Sdk="Microsoft.Net.Sdk".

However, it is a bit of a challenge to publish the said app. The option is definitely not available from the IDE. But what I find a bit puzzling is that the Publish target doesn't seem to be available when you call msbuild directly.

These are some of the top-level properties I set:

    <Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
    <TargetFramework>net461</TargetFramework>
    <LanguageTargets>$(MSBuildExtensionsPath)\$(VisualStudioVersion)\Bin\Microsoft.CSharp.targets</LanguageTargets>
    <OutputType>WinExe</OutputType>
    <PlatformTarget>x86</PlatformTarget>
    <Prefer32Bit>false</Prefer32Bit>
    <!--<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>-->
</PropertyGroup></Project>

I also set the typical ones associated with the ClickOnce eg PublishUrl, etc. What can I do to get at/expose the Publish target the same way the LanguageTarget above enables "CoreBuild" for the other legacy C# build tasks outside Console, Web and plain libraries.

Further Thoughts:

So, it turns out that on further inspection, there is actually a Publish target. But it does a simple folder/xcopy deployment to a subfolder called Publish rather than creating an app.publish folder and doing the ClickOnce thing.

How does one work around this?

like image 380
Eniola Avatar asked May 05 '17 16:05

Eniola


People also ask

How do I publish my ClickOnce application?

In the Publish wizard, select Folder. In the Specific target page, select ClickOnce. Enter a path or select Browse to select the publish location. In the Install location page, select where users will install the application from.

Is ClickOnce still supported?

ClickOnce and DirectInvoke are supported out of the box for all Windows users. Users that want to disable ClickOnce support can go to edge://flags/#edge-click-once and select Disabled from the dropdown list.

What is the difference between ClickOnce deployment and Windows Installer deployment?

Windows Installer deployment requires administrative permissions and allows only limited user installation; ClickOnce deployment enables non-administrative users to install and grants only those Code Access Security permissions necessary for the application.


2 Answers

You can manually publish ClickOnce using the Mage.exe (command line) or MageUI.exe (gui) tools. It's not very convenient but it does seem to work if you get everything right. I'll outline what worked for me using MageUI.exe.

Choose the correct version of the utility for the .NET version you're using from:

C:\Program Files (x86)\Microsoft SDKs\Windows\

First publish your application files to a folder. Normally this would be something like:

\\server\share\MyApplication\Application Files\MyApplication_1_0_0_25\

NOTE: I had issues with the space in Application Files, where it would be converted to %20, but I don't think UNC paths support that value. I had to remove the space and renamed the folder to ApplicationFiles. (This will probably break previously published versions though.)

Then use MageUI.exe to create a new application manifest:

  • On the Name page, give it a name, version, and choose a processor architecture (x86).
  • On the Files page, enter the directory you published the files to, and then hit populate. It should load all the program files into the DataGridView below.
  • On the Permissions Required page, I was not able to get it working with anything less than FullTrust. Without FullTrust, when the application was run, nothing happened.
  • Save the manifest file as MyApplication.exe.manifest to the application folder. (You will be able to sign the manifest when you save it.)

Now create a new Deployment manifest:

  • On the Name page, enter the same name and version and choose the right processor architecture.
  • On the Description page, enter Publisher and Product.
  • On the Deployment Options page, I chose Online Only. I did not include a Start Location.
  • On the Application Reference page, choose Select Manifest and browse to the application manifest file you previously created.
  • Save the deployment manifest as \\server\share\MyApplication\MyApplication.application; (you can sign it when you save.)
  • NOTE: A glitch here seems to be that it will have inferred the wrong relative path when you select the application manifest file. After you've saved the deployment manifest the first time, go select the application manifest file again, and it will now infer the correct relative path. Then hit save again and you should be ok.

There are a lot of things that can go wrong and a lot of ways that the procedure can differ, but these are the steps that worked for me.

(Another thing I had to do during these steps was clear my ClickOnce Application Cache, by deleting the contents of c:\users\username\AppData\Local\Apps\2.0\. But that was probably just because of all the mistakes I made. I would only do this if you get stuck.)

like image 129
Dave Cousineau Avatar answered Oct 03 '22 16:10

Dave Cousineau


Microsoft is finally adding ClickOnce functionality to SDK Style Winforms and WPF projects in .NET 5.

like image 22
Eniola Avatar answered Oct 03 '22 17:10

Eniola