我正在使用 WiX 为 ASP.Net 网站创建安装程序。如何使用 WiX 在 IIS 中设置 ASP.Net 版本?
7 回答
我们使用这个:
首先从注册表中确定.Net框架根目录:
<Property Id="FRAMEWORKROOT">
<RegistrySearch Id="FrameworkRootDir" Root="HKLM"
Key="SOFTWARE\Microsoft\.NETFramework"
Type="directory" Name="InstallRoot" />
</Property>
然后,在 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>
对于 x64 安装程序(这很重要)将 Win64='yes' 添加到注册表搜索,因为 64 位机器上的 32 位环境具有不同的注册表配置单元(和不同的 frameworkroot)
<RegistrySearch Id="FrameworkRootDir" Root="HKLM"
Key="SOFTWARE\Microsoft\.NETFramework"
Type="directory"
Name="InstallRoot" Win64='yes' />
在与它搏斗之后,这对我有用:
<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] 和 [VIRTUALDIR] 是您必须自己定义的属性。[VIRTUALDIR] 仅当您为应用程序而不是整个网站设置 ASP.NET 版本时才需要。
自定义操作的顺序至关重要。在 InstallFinalize 之前执行它会导致它失败,因为在此之后 Web 应用程序不可用。
感谢 Chris Burrows 提供了一个查找 aspnet_regiis 可执行文件的正确示例(Google“使用 WIX 保护连接字符串”)。
jb
不要忘记在服务器上启用 ASP 2.0
<iis:WebServiceExtension Id="ExtensionASP2" Group="ASP.NET v2.0.50727" Allow="yes" File="[NETFRAMEWORK20INSTALLROOTDIR]aspnet_isapi.dll" Description="ASP.NET v2.0.50727"/>
我的回答与这里看到的其他人基本相同;我只是想为人们提供另一个例子。
鉴于 ASP.NET 处理的文件扩展名的数量,以及每个版本中列表的变化,我认为最可靠的解决方案是aspnet_regiis
在安装结束时运行。但这确实意味着,我不支持回滚或卸载。我在 IIS 中创建一个新应用程序,这并不重要,因为它将被 Wix 删除。如果您正在修改现有应用程序,也许您可以从注册表中找出配置了 ASP.NET 的哪个版本,然后运行该版本aspnet_regiis
来撤消您的更改。
以下使用 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=""[NETFRAMEWORK40FULLINSTALLROOTDIR]aspnet_regiis.exe" -norestart -s "W3SVC/[IISWEBSITEID]/ROOT/[IISVDIRNAME]"" />
<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>
这有点简单。我不知道这是否适用于更新现有的 AppPool,但适用于创建 APP Pool 和设置 .NET 版本。
<iis:WebServiceExtension Id="AMS_AppPool" Name="AccountManagementSVC1" Identity="other" ManagedPipelineMode="integrated" ManagedRuntimeVersion="v4.0" User="AMS_AppPoolUser" RecycleMinutes="120" />
首先找到正确的 .NET 版本文件夹。使用 DirectorySearch/FileSearch 执行搜索。
使用上述路径调用 aspnet_regiis.exe 并通过自定义操作设置 webapp 的版本。
aspnet_regiis.exe -s W3SVC/1/ROOT/SampleApp1