Question

I am creating an installer for an ASP.Net website using WiX. How do you set the ASP.Net version in IIS using WiX?

Was it helpful?

Solution

We use this:

First determine the .Net framework root directory from the registry:

<Property Id="FRAMEWORKROOT">
  <RegistrySearch Id="FrameworkRootDir" Root="HKLM"
                Key="SOFTWARE\Microsoft\.NETFramework" 
                Type="directory" Name="InstallRoot" />
</Property>

Then, inside the component that installs your website in IIS:

<!-- Create and configure the virtual directory and application. -->
<Component Id='WebVirtualDirComponent' Guid='{GUID}' Permanent='no'>
  <iis:WebVirtualDir Id='WebVirtualDir' Alias='YourAlias' Directory='InstallDir' WebSite='DefaultWebSite'  DirProperties='DirProperties'>
    <iis:WebApplication Id='WebApplication' Name='YourAppName' WebAppPool='AppPool'>
      <!-- Required to run the application under the .net 2.0 framework -->
      <iis:WebApplicationExtension Extension="config" CheckPath="yes" Script="yes"
                    Executable="[FRAMEWORKROOT]v2.0.50727\aspnet_isapi.dll" Verbs="GET,HEAD,POST" />
      <iis:WebApplicationExtension Extension="resx" CheckPath="yes" Script="yes"
                    Executable="[FRAMEWORKROOT]v2.0.50727\aspnet_isapi.dll" Verbs="GET,HEAD,POST" />
      <iis:WebApplicationExtension Extension="svc" CheckPath="no" Script="yes"
                    Executable="[FRAMEWORKROOT]v2.0.50727\aspnet_isapi.dll" Verbs="GET,HEAD,POST" />
    </iis:WebApplication>
  </iis:WebVirtualDir>
</Component>

For an x64 installer (THIS IS IMPORTANT) Add Win64='yes' to the registry search, because the 32 bits environment on a 64 bits machine has a different registry hive (and a different frameworkroot)

<RegistrySearch Id="FrameworkRootDir" Root="HKLM"
        Key="SOFTWARE\Microsoft\.NETFramework" 
        Type="directory" 
        Name="InstallRoot" Win64='yes' />

OTHER TIPS

Here is what worked for me after wrestling with it:

  <Property Id="FRAMEWORKBASEPATH">
     <RegistrySearch Id="FindFrameworkDir" Root="HKLM" Key="SOFTWARE\Microsoft\.NETFramework" Name="InstallRoot" Type="raw"/>
  </Property>
  <Property Id="ASPNETREGIIS" >
     <DirectorySearch Path="[FRAMEWORKBASEPATH]" Depth="4" Id="FindAspNetRegIis">
        <FileSearch Name="aspnet_regiis.exe" MinVersion="2.0.5"/>
     </DirectorySearch>
  </Property>

  <CustomAction Id="MakeWepApp20" Directory="TARGETDIR" ExeCommand="[ASPNETREGIIS] -norestart -s W3SVC/[WEBSITEID]/ROOT/[VIRTUALDIR]" Return="check"/>

  <InstallExecuteSequence>
     <Custom Action="MakeWepApp20" After="InstallFinalize">ASPNETREGIIS AND NOT Installed</Custom>
  </InstallExecuteSequence>

[WEBSITEID] and [VIRTUALDIR] are properties you have to define yourself. [VIRTUALDIR] is only necessary if you are setting the ASP.NET version for an application rather than an entire website.

The sequencing of the custom action is critical. Executing it before InstallFinalize will cause it to fail because the web application isn't available until after that.

Thanks to Chris Burrows for a proper example of finding the aspnet_regiis executable (Google "Using WIX to Secure a Connection String").

jb

Don't forget to enable ASP 2.0 on the server

<iis:WebServiceExtension Id="ExtensionASP2" Group="ASP.NET v2.0.50727" Allow="yes" File="[NETFRAMEWORK20INSTALLROOTDIR]aspnet_isapi.dll" Description="ASP.NET v2.0.50727"/>

Here is the sof-question

My answer is basically the same as others seen here; I just wanted to offer people another example.

Given the number of file extensions that ASP.NET handles, and that the list changes in each version, I think the most reliable solution is to run aspnet_regiis at the end of the installation. This does mean though, that I don't have any support for rollback or uninstallation. I you're creating a new application in IIS, it doesn't really matter because it will be deleted by Wix. If you're modifying an existing application, perhaps you could find out from the registry what version of ASP.NET is configured, and run that version's aspnet_regiis to undo your changes.

The following uses Wix 3.5.

<Fragment>
    <!-- Use the properties in Wix instead of doing your own registry search. -->
    <PropertyRef Id="IISMAJORVERSION"/>
    <PropertyRef Id="NETFRAMEWORK40FULL"/>
    <PropertyRef Id="NETFRAMEWORK40FULLINSTALLROOTDIR"/>

    <!-- The code I'm using is intended for IIS6 and above, and it needs .NET 4 to be
    installed. -->
    <Condition Message="This application requires the .NET Framework 4.0. Please install the required version of the .NET Framework, then run this installer again.">
        <![CDATA[Installed OR (NETFRAMEWORK40FULL)]]>
    </Condition>
    <Condition Message="This application requires Windows Server 2003 and Internet Information Services 6.0 or better.">
        <![CDATA[Installed OR (VersionNT >= 502)]]>
    </Condition>

    <!-- Populates the command line for CAQuietExec. IISWEBSITEID and IISVDIRNAME 
    could be set to default values, passed in by the user, or set in your installer's 
    UI. -->
    <CustomAction Id="ConfigureIis60AspNetCommand" Property="ConfigureIis60AspNet"
                  Execute="immediate"
                  Value="&quot;[NETFRAMEWORK40FULLINSTALLROOTDIR]aspnet_regiis.exe&quot; -norestart -s &quot;W3SVC/[IISWEBSITEID]/ROOT/[IISVDIRNAME]&quot;" />
    <CustomAction Id="ConfigureIis60AspNet" BinaryKey="WixCA" DllEntry="CAQuietExec" 
                  Execute="deferred" Return="check" Impersonate="no"/>
    <InstallExecuteSequence>
        <Custom Action="ConfigureIis60AspNetCommand" After="CostFinalize"/>

        <!-- Runs the aspnet_regiis command immediately after Wix configures IIS. 
        The condition shown here assumes you have a selectable feature in your 
        installer with the ID "WebAppFeature" that contains your web components. The 
        command will not be run if that feature is not being installed, or if IIS is 
        not version 6. It *will* run if the application is being repaired. 

        SKIPCONFIGUREIIS is a property defined by Wix that causes it to skip the IIS
        configuration. -->
        <Custom Action="ConfigureIis60AspNet" After="ConfigureIIs" Overridable="yes">
            <![CDATA[((&WebAppFeature = 3) OR (REINSTALL AND (!WebAppFeature = 3))) 
            AND (NOT SKIPCONFIGUREIIS) AND (IISMAJORVERSION = "#6")]]>
        </Custom>
    </InstallExecuteSequence>
    <UI>
        <ProgressText Action="ConfigureIis60AspNetCommand"
            >Configuring ASP.NET</ProgressText>
        <ProgressText Action="ConfigureIis60AspNet"
            >Configuring ASP.NET</ProgressText>
    </UI>

</Fragment>

This is a bit simpler. I don’t know if this works on updating an existing AppPool, but works for creating an APP Pool and setting the .NET version.

<iis:WebServiceExtension Id="AMS_AppPool" Name="AccountManagementSVC1" Identity="other"  ManagedPipelineMode="integrated" ManagedRuntimeVersion="v4.0" User="AMS_AppPoolUser" RecycleMinutes="120" />

I found a different way by using the WiX WebApplicationExtension. You can check out the full solution here and here.

I like Wix so far, but man does it takes a lot of digging to find what you are looking for.

  • First find the correct .NET version folder. Use DirectorySearch/FileSearch to perform search.

  • Use the above path to call aspnet_regiis.exe and set the version for the webapp from a custom action.

    aspnet_regiis.exe -s W3SVC/1/ROOT/SampleApp1

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top