# How to open prerequisite retrieval application

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?

• 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. Aug 30 '13 at 3:17
• 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. 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">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Generate</Configuration> <Platform Condition=" '$(Platform)' == '' ">x86</Platform>
<ProductVersion>8.0.30703</ProductVersion>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>{B65DD26E-6A17-47E0-A21B-E7AF0F156610}</ProjectGuid>
<OutputType>Library</OutputType>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Generate|AnyCPU' ">
<OutputPath>bin\Ignore\</OutputPath>
</PropertyGroup>
<ItemGroup>
</ItemGroup>
<!-- Unused, in theory -->
<Import Project="\$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<ItemGroup>
<BootstrapperPackage Include=".NETFramework,Version=v4.0,Profile=Client">
<Visible>False</Visible>
<ProductName>Microsoft .NET Framework 4 Client Profile %28x86 and x64%29</ProductName>
<Install>true</Install>
</BootstrapperPackage>
<BootstrapperPackage Include="Microsoft.Xna.Framework.4.0">
<Visible>False</Visible>
<ProductName>Microsoft XNA Framework Redistributable 4.0</ProductName>
<Install>true</Install>
</BootstrapperPackage>
</ItemGroup>
<Target Name="Build">
<GenerateBootstrapper
BootstrapperItems="@(BootstrapperPackage)"
ApplicationName="Install Prerequisites"
OutputPath="Installer\" />
<Copy SourceFiles="Installer\setup.exe" DestinationFiles="Installer\Install Prerequisites.exe" />
<Delete Files="Installer\setup.exe" />
</Target>
</Project>


(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.)

• 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. Aug 31 '13 at 23:01