How do you publish a clickonce installer that includes .net installer and Auto-Update functionality?
Asked Answered
B

2

7

I am using TeamCity for a continuous integration server and am deploying my application using a ClickOnce installer. I can get the installer to function and deploy my application but I cannot figure out how to include the installer for .net 4.5 if the computer does not already have it installed or how to enable the auto-update check feature in ClickOnce deployments. I am currently using the MSBuild file below to build my installer

<Project DefaultTargets="DoPublish" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <Import Project="$(MSBuildExtensionsPath)\MSBuildCommunityTasks\MSBuild.Community.Tasks.Targets"/>
  <PropertyGroup>
    <Version>$(BUILD_NUMBER)</Version>
    <Install>true</Install>
    <InstallFrom>Unc</InstallFrom>
    <UpdateEnabled>true</UpdateEnabled>
    <UpdateMode>Background</UpdateMode>
    <ClickOnceBuildDirectory>$(MSBuildProjectDirectory)\MyProject\bin\$(Configuration)\app.publish</ClickOnceBuildDirectory>
    <ClickOnceInstallDirectory>$(MSBuildProjectDirectory)\Publish</ClickOnceInstallDirectory>
    <ClickOnceFinalLocation>$(env_PublishUrl)</ClickOnceFinalLocation>
  </PropertyGroup>
  <Target Name="DoPublish">
    <RemoveDir Directories="$(ClickOnceInstallDirectory)" ContinueOnError="true" />
    <MSBuild Projects="MyProject.sln" Targets="Clean;Build" Properties="ApplicationVersion=$(Version);Configuration=$(Configuration)"/>
    <MSBuild Projects="MyProject\MyProject.csproj" Targets="Publish" Properties="ApplicationVersion=$(Version);Configuration=$(Configuration);InstallUrl=$(ClickOnceFinalLocation)" />
    <MakeDir Directories="$(ClickOnceInstallDirectory)"/>    
    <Exec Command="xcopy /E $(ClickOnceBuildDirectory) $(ClickOnceInstallDirectory)" />    
  </Target>  
</Project>
Binturong answered 27/2, 2013 at 20:35 Comment(0)
C
4

You can use a bootstrapper to handle prerequisites like checking for the .NET Framework. Check the Application Deployment Prerequisites MSDN article, especially the sections about bootstrapping with ClickOnce and MSBuild.

There are also 2 more MSDN articles that detail how to install ClickOnce prerequisites and Creating bootstrapper packages.

As for auto-updates, do you want to locate the auto-update functionality outside the application itself, i.e., in an installer vs. in the application? There are several ways to allow ClickOnce updates in your application, including auto-updates via the ClickOnce Deployment API.

A brief explanation of using ClickOnce Bootstrapper packages can be found in this existing Stackoverflow article. Though you're not using WiX here, you can also check this this WiX thread, which is useful because you see some of the steps that didn't work along the way. These examples show the use of the GenerateBootstrapper MSBuild task to create the bootstrapper for the ClickOnce installer. Note that in the examples at the above links, the "Path" in the GenerateBootstrapper task is set to a subfolder under a Windows SDK location. This can be changed to another location, as long as that location has the necessary prerequisite packages.

Below is an example in which the .NET 4.5 Framework is set as a prerequisite for the install. The parent directory structure for the .NET 4.5 prerequisite is specified by the $(MyPathToPrerequisitePackages) property.

The BootstrapperFile item in the below example specifies the .NET 4.5 Framework prerequisite package. The value ".NETFramework,Version=v4.5" comes from the product.xml file in the Bootstrapper\Packages\DotNetFX45 folder, and allows the GenerateBootstrapper task to correctly identify the .NET 4.5 prerequisite/bootstrapper package. The "ProductName" value is simply a friendly description of the package.

<PropertyGroup>
  <MyPathToPrerequisitePackages>C:\Program Files (x86)\Microsoft SDKs\Windows\v8.0A\Bootstrapper</MyPathToPrerequisitePackages>
</PropertyGroup>
<ItemGroup>
  <BootstrapperFile Include=".NETFramework,Version=v4.5">
    <ProductName>.NET Framework 4.5</ProductName>
  </BootstrapperFile>
</ItemGroup>
<GenerateBootstrapper 
  ApplicationFile="$(MyAppAssembly).application"
  ApplicationUrl="$(MyClickOnceAppUrl)"
  ApplicationName="$(MyClickOnceAppName)"
  BootstrapperItems="@(BootstrapperFile)"
  Culture="en"
  FallbackCulture="en-US"
  CopyComponents="true"
  Validate="false"
  Path="$(MyPathToPrerequisitePackages)"
  SupportUrl="$(MyAppSupportUrl)"
  OutputPath="$(MyDesiredOutputPath)\" />
Caye answered 28/2, 2013 at 13:39 Comment(14)
But how do you incorporate the XML files from 'Creating Bootstrap Packages' into the xml file above to create a click once package?Binturong
p.s. the auto updater references were right on. I just wish I could figure out how to add a bootstrapper to the clickonce installer.Binturong
You can use the GenerateBootstrapper MSBuild task to do this. I will edit my answer to add an example.Caye
this looks good. Let me try it out and I'll mark your answer as correct once I verify it.Binturong
@PITaylor, were you able to verify?Caye
Unfortunatly not yet. I've been pulled in on a different project for the time being. I have not forgotten about this though.Binturong
Can you taylor this for .net 4.5 like in the question....I tried to do<MyPathToPrerequisitePackages>C:\Program Files (x86)\Microsoft SDKs\Windows\v8.0A\Bootstrapper\Packages\DotNetFX45</MyPathToPrerequisitePackages> and <BootstrapperFile Include="Microsoft.Net.CoreFramework.4.5"> <ProductName>dotnetfx45_full_setup.exe</ProductName> </BootstrapperFile> and it didn't like it.Binturong
@PITaylor, that last edit should have made it easy for you to add the .NET 4.5 prerequisite. Have you verified it?Caye
It is currently giving me the error of "The element <GenerateBootstrapper> beneath element <Project> is unrecognized."Binturong
@PITaylor, the <GenerateBootstrapper> task should be placed inside a <Target>. I'm guessing you're seeing that error because it was placed outside of a <Target> in your MSBuild script.Caye
That all compiled...but when I use the installer it tells me it needs 4.5 instead of installing it.Binturong
@PITaylor, you should have all you need to get the rest of your process going at this point. Which installer are you talking about and what was the exact error/message you received?Caye
Upon running the ClickOnce installer that I am building, message: "Unable to install or run this application. This application requires Version 4.5 Full or other compatible .NET Framework. Please contact your system administrator."Binturong
Sounds like you're not using the bootstrapper installer. The GenerateBootstrapper task creates a setup.exe which should be run as the installer. It will prompt for .NET 4.5 installation and will call the ClickOnce installer (that's why you specify the .application file for the value of the 'ApplicationFile' attribute in the GenerateBootstrapper task).Caye
E
1

Just posted a response on 'https://mcmap.net/q/182776/-issue-with-clickonce-bootstrapper-and-msbuild':

Just struggled with this myself - I chose to commit the bootstrapper files to source control. It is possible to override the path to bootstrappers, just provide /p:GenerateBootstrapperSdkPath=.build\Bootstrapper

Then no need to modify registry - and the added benefit that the build is now self-contained.

Only "problem" is that I have to manually copy the Bootstrapper files into source control. In my case (VStudio2015), this meant copying the files from C:\Program Files (x86)\Microsoft Visual Studio 14.0\SDK\Bootstrapper

Estell answered 21/9, 2016 at 7:28 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.