views:

3490

answers:

7

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

A: 

I do something like this

// declare Custom action

<CustomAction Id="MakeWepApp20" Value="[NETFRAMEWORK20DIR]aspnet_regiis.exe" -sn "W3SVC/[WEBSITEIISID]/Root/" />

<InstalllExecuteSequence> ... <Custom Action="MakeWepApp20" after="ConfigureIIs">
[Your conditions here]
</Custom>

CheGueVerra
A: 
  • 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

Vivek
+1  A: 

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.

JasonS
I tried this approach with my MVC app and it just wouldn't play nicely at all. Using aspnet_regiis within a CustomAction to change the AppPool to .NET 2.0 worked for me (see John Burns answer).
Jason
+10  A: 

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' />
thijs
wow. supereasy. thanks!
Michael Bray
@thjis: Why are you only registering those three extensions? Should you also register, for instance, aspx and asmx extensions? Should you go ahead a register all extensions listed in IIS just to be sure?
Ian
+2  A: 

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

John Burns
Thanks mate, in my opinion this is the most consistent answer here. I tried the other suggestion (which leaves the app pool as .NET 1.1) and it was just over-complicated and didn't work on my MVC app.One point, I had to use the LongName attribute for FileSearch (instead of Name which it complained only supports 8.3 format).Thanks again.
Jason
Sorry, what would the ExeCommand be for setting it for the entire website?
David Hodgson
Also, would [WEBSITEID] correspond to <iis:WebSite Id="WEBSITEID">?
David Hodgson
Note that this will result in a separate application pool being created for ASP.NET 4, meaning that your app may not be running where you thought it was. We had to drop this approach because of this problem.
Simon Steele
A: 

But where can I get [WEBSITEID] of my site for command-line parameters of aspnet_regiis command? I found it is varies IIS by IIS from server to server...

Ivan
+2  A: 

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

uli78
where do you reference that Id afterwards?
BozoJoe
Nowhere, the hole „iis:WebServiceExtension”-tag is inside a component-tag. That’s how it is referenced. The Id isn’t actually used anywhere else.
uli78