2
\$\begingroup\$

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?

\$\endgroup\$
2
  • \$\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, 2013 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, 2013 at 22:57

1 Answer 1

4
\$\begingroup\$

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>
    <None Include="Readme.txt" />
  </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.)

\$\endgroup\$
1
  • \$\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, 2013 at 23:01

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .