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>
PlTaylor
  • 7,345
  • 11
  • 52
  • 94

2 Answers2

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)\" />
Community
  • 1
  • 1
Michael
  • 1,272
  • 1
  • 9
  • 18
  • But how do you incorporate the XML files from 'Creating Bootstrap Packages' into the xml file above to create a click once package? – PlTaylor Feb 28 '13 at 15:05
  • 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. – PlTaylor Feb 28 '13 at 20:44
  • You can use the GenerateBootstrapper MSBuild task to do this. I will edit my answer to add an example. – Michael Mar 04 '13 at 16:57
  • this looks good. Let me try it out and I'll mark your answer as correct once I verify it. – PlTaylor Mar 06 '13 at 12:52
  • @PITaylor, were you able to verify? – Michael Mar 11 '13 at 20:31
  • Unfortunatly not yet. I've been pulled in on a different project for the time being. I have not forgotten about this though. – PlTaylor Mar 12 '13 at 00:09
  • Can you taylor this for .net 4.5 like in the question....I tried to doC:\Program Files (x86)\Microsoft SDKs\Windows\v8.0A\Bootstrapper\Packages\DotNetFX45 and dotnetfx45_full_setup.exe and it didn't like it. – PlTaylor Mar 12 '13 at 13:13
  • @PITaylor, that last edit should have made it easy for you to add the .NET 4.5 prerequisite. Have you verified it? – Michael Mar 19 '13 at 18:48
  • It is currently giving me the error of "The element beneath element is unrecognized." – PlTaylor Mar 21 '13 at 16:03
  • @PITaylor, the task should be placed inside a . I'm guessing you're seeing that error because it was placed outside of a in your MSBuild script. – Michael Mar 21 '13 at 17:30
  • That all compiled...but when I use the installer it tells me it needs 4.5 instead of installing it. – PlTaylor Mar 21 '13 at 17:56
  • @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? – Michael Mar 21 '13 at 18:16
  • 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." – PlTaylor Mar 21 '13 at 19:16
  • 1
    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). – Michael Mar 21 '13 at 20:05
1

Just posted a response on 'https://stackoverflow.com/a/39610060/1345870':

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

Community
  • 1
  • 1
espenalb
  • 538
  • 3
  • 17