I have an application that cannot use OneClick publishing.

I still want to access those nice prerequisite (applications?) that install .NET and XNA for you when you create a OneClick publisher.

I can check if the frameworks are needed via the registry, but is there anyway to get something similar to what the setup.exe consists of in a publish?

  • \$\begingroup\$ I feel like this is an incomplete answer, but I think most games will include a redist folder in their install files, with all the installers needed, and then run the appropriate installers afterward. .NET and XNA should skip installation if they're already installed, so just run them anyway. \$\endgroup\$
    – Katana314
    Aug 30 '13 at 3:17
  • \$\begingroup\$ That would add almost 50MB on top of my package. The application itself is not even 30MB. I'd rather keep it as light as possible. \$\endgroup\$ Aug 31 '13 at 22:57

ClickOnce creates a "setup.exe" that checks for prerequisites (like the .NET Framework and XNA), downloads and installs them from Microsoft's servers, and then invokes your ClickOnce manifest. It is possible to create a setup.exe that installs just prerequisites and then does nothing.

The best way to do this is to with an MSBuild script. The creation of "setup.exe" is performed by the <GenerateBootstrapper> task. The MSDN entry gives the various parameters you can customise (and also a minimal MSBuild example).

Because Visual Studio project files are MSBuild scripts, I find it convenient to embed it in one, as you can then just drop it into your solution. Here is a complete project file that does what you need:

<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
    <Configuration Condition=" '$(Configuration)' == '' ">Generate</Configuration>
    <Platform Condition=" '$(Platform)' == '' ">x86</Platform>
  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Generate|AnyCPU' ">
    <None Include="Readme.txt" />
  <!-- Unused, in theory -->
  <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
    <BootstrapperPackage Include=".NETFramework,Version=v4.0,Profile=Client">
      <ProductName>Microsoft .NET Framework 4 Client Profile %28x86 and x64%29</ProductName>
    <BootstrapperPackage Include="Microsoft.Xna.Framework.4.0">
      <ProductName>Microsoft XNA Framework Redistributable 4.0</ProductName>
  <Target Name="Build">
        ApplicationName="Install Prerequisites"
        OutputPath="Installer\" />
    <Copy SourceFiles="Installer\setup.exe" DestinationFiles="Installer\Install Prerequisites.exe" />
    <Delete Files="Installer\setup.exe" />

(Put the above in a text file and give it a .csproj extension. It's tested in Visual C# Express 2010. I've also put in some tasks to rename the output to something nice.)

Typically <BootstrapperPackage> is used to indicate items to the BootstrapperItems parameter (like in regular projects using ClickOnce), but this naming is arbitrary. The above project file generates an install for XNA 4 and .NET 4 Client Profile. If you wanted to change these, you could copy them from a dummy project with ClickOnce configured.

If you want to have your installer launch a program, after it is done installing prerequisites, you can set the ApplicationFile parameter.

(Note that the GenerateBootstrapper task, as used by ClickOnce, won't appear in your regular project files - it's invoked somewhere inside Microsoft.CSharp.targets.)

  • \$\begingroup\$ Thanks for the answer! I have built a bootstrapper on top of the installer, and will download the prerequisites with a WebClient inside the application via Microsoft's links instead. The only requirement for the bootstrapper is .NET 2.0, which I can deal with. \$\endgroup\$ Aug 31 '13 at 23:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.