目前我正在试图修改我的维克斯(V3.5)的安装程序来编辑我想安装的.NET应用程序的Web.config设置。 这是罚款正常的ASP.NET应用程序,但现在即时通讯试图运用我的维克斯成立项目实体框架.NET应用程序,正如你可能知道有一个更复杂的连接字符串与模型.csdl和.ssdl设置的设置。
所以,如果我的web.config连接字符串设定看起来服用点是这样的:(其中[DBSERVER] [数据库]是从对话框retrived属性)
<connectionStrings>
<add name="SSITacticalSolutionEntities" connectionString="metadata=res://*/Model.TacticalSolutionModel.csdl|res://*/Model.TacticalSolutionModel.ssdl|res://*/Model.TacticalSolutionModel.msl;provider=System.Data.SqlClient;provider connection string="Data Source=sd-sql2008r2;Initial Catalog=SsiTacticalSolution1.2.4;Integrated Security=True;MultipleActiveResultSets=True" />
</connectionStrings>
我修改我的web.config中像这样服用点我Product.Wsx文件:
<util:XmlFile Id="ModifyConnectionString" Action="setValue" Permanent="yes" File="[INSTALLLOCATION]Web.config"
ElementPath="/configuration/connectionStrings/add[\[]@name='!(loc.EntityName)'[\]]" Name="connectionString"
Value="Data Source=[DBSERVER];Initial Catalog=[DBNAME];Integrated Security=true;providerName=System.Data.EntityClient;MultipleActiveResultSets=True"" Sequence="5"/>
我得到一个连接字符串是这样的:
<connectionStrings>
<add name="SSITacticalSolutionEntities" connectionString="Data Source=sd-sql2008r2;Initial Catalog=SsiTacticalSolution1.2.4;Integrated Security=true;providerName=System.Data.EntityClient;MultipleActiveResultSets=True""/>
</connectionStrings>
这当然是有道理的,因为即时通讯要求它取代了我的价值已定义的当前连接字符串属性。
但我真的需要这里是编辑我的连接字符串的特定部分和其余部分留(是有某种形式的替代作用,我可以在这里使用的),即留在原地我所有的模型设定,只是更换数据库服务器和名称等因为我需要。 我以前做这与Visual Studio安装没有问题,这是很容易使用。
所以我的问题是可以这样使用util.XMLFile完成,或者UTIL:XMLConfig的? 我没有任何的运气已经试过这两种。
或者,这是不可能的util.XMLFile做,我将不得不这样做在CustomAction呢? 任何想法将有很大的帮助,在此先感谢...
我到底该工作,最终我没有使用自定义操作,这一特定的设置,我用我的本地化文件中设置的变量。
我这样做是因为这将是开发而不是谁知道型号名称和实体名称的用户(不是通过安装对话框用户,他们也不会知道这个信息),所以我必须在不同性质的本地化文件它像产品名等,所以我说在型号名称和entites的名字这一点。 一切我从对话框,通过用户输入得到:即数据库名,虚拟目录,模拟用户等..
如果有帮助的人,这里是我想出了到底是为了我的web.config,这是我的product.wxs的,与此问题涉及的部分。 正如你可以看到我有一个连接字符串属性在顶部,与这是在我的本地化文件中设置的loc.ModelName的占位符:
<Property Id="CONNECTION_STRING"
Value="metadata=res://*/Model.!(loc.ModelName).csdl|res://*/Model.!(loc.ModelName).ssdl|res://*/Model.!(loc.ModelName).msl;provider=System.Data.SqlClient;provider connection string=""/>
<!-- The root of the installer. -->
<Directory Id='TARGETDIR' Name='SourceDir'>
<!-- Install into the inetpub/wwwroot directory -->
<Directory Id="IISMain" Name='inetpub'>
<Directory Id="WWWMain" Name='wwwroot' ComponentGuidGenerationSeed='C38ED13E-E1E3-40DB-B1FA-39400C6B2BC4'>
<Directory Id='INSTALLLOCATION' Name="!(loc.ProductName)">
<!-- The component to define the Virtual Directory.-->
<Component Id="WebVirtualDirComponent"
Guid="D814F88F-6E0C-4365-A411-2F9807522C3D">
<!-- WebVirtualDir: The virtual directory we are installing. -->
<!-- Alias: Alias attribute is the name that we will see in IIS.-->
<!-- Directory: The Directory attribute is the "Physical Path" property in
IIS and needs to tie to the ID specified above as the install location. -->
<!-- WebSite: The WebSite attribute ties to a <WebSite> element in the
setup file(see below). As this is an example of installing into the
"Default Web Site" so that element is not under a component.-->
<iis:WebVirtualDir Id="VDir" Alias="[VIRTUALDIRECTORYVALUE]"
Directory="INSTALLLOCATION"
WebSite="DefaultWebSite">
<!-- This turns the Virtual Directory into a web application. -->
<iis:WebApplication Id="MyWebAppApplication"
Name="[VIRTUALDIRECTORYVALUE]" WebAppPool="AppPool"/>
<iis:WebDirProperties Id="WebSite_Properties" AnonymousAccess="no"
WindowsAuthentication="yes" DefaultDocuments="!(loc.DefaultDocument)"
Script="yes" Read="yes" />
</iis:WebVirtualDir>
<CreateFolder/>
<RemoveFolder Id= "GuidFolders" On= "uninstall"/>
</Component>
<!-- Components - this decides what we want to incude in our install
Here we will alter our web.config for Impersonation , debug to false and connection string. -->
<Component Id="Web.config" Guid="2ED81B77-F153-4003-9006-4770D789D4B6">
<!--install our web.config file , this isnt part of our initial MSBUILD-->
<File Id="Web.config" Name="Web.config" Source="$(var.SolutionDir)!(loc.WebApplicationProjectName)\Web.config" DiskId="1" KeyPath="yes" />
<!--Modify our web.config - here we need to add Identity impersonation , changes session settings , add connection string settings and set debug setting-->
<!--Ensure that the identity setting exists-->
<util:XmlFile Id="system.webidentity"
File="[INSTALLLOCATION]Web.config"
Action="createElement"
ElementPath="/configuration/system.web"
Name="identity"
SelectionLanguage="XPath"
Sequence="1" />
<util:XmlFile Id="system.webIdentityAttribute"
Action="setValue"
File="[INSTALLLOCATION]Web.config"
ElementPath="/configuration/system.web/identity"
Name="impersonate"
Value="true"
SelectionLanguage="XPath"
Sequence="2" />
<util:XmlFile Id="system.webIdentityAttribute2"
Action="setValue"
File="[INSTALLLOCATION]Web.config"
ElementPath="/configuration/system.web/identity"
Name="password"
Value="[IMPERSONATIONUSERPASSWORD]"
SelectionLanguage="XPath"
Sequence="3" />
<util:XmlFile Id="system.webIdentityAttribute3"
Action="setValue"
File="[INSTALLLOCATION]Web.config"
ElementPath="/configuration/system.web/identity"
Name="userName"
Value="[IMPERSONATIONUSER]"
SelectionLanguage="XPath"
Sequence="4" />
<util:XmlFile Id="ModifyConnectionString"
Action="setValue"
Permanent="yes"
File="[INSTALLLOCATION]Web.config"
ElementPath="/configuration/connectionStrings/add[\[]@name='!(loc.EntityName)'[\]]"
Name="connectionString"
Value="[CONNECTION_STRING]Data Source=[DBSERVER];Initial Catalog=[DBNAME];Integrated Security=True;MultipleActiveResultSets=True""
SelectionLanguage="XPath"
Sequence="5"/>
<!--<authentication mode="Forms">-->
<util:XmlFile Id="AuthenticationModeWindows"
Action="setValue"
File="[INSTALLLOCATION]Web.config"
ElementPath="/configuration/system.web/authentication"
Name="mode"
Value="Windows"
Sequence="6" />
<!--Switch off debug-->
<util:XmlConfig Sequence="7"
Id="SwitchOffDebug"
File="[INSTALLLOCATION]\web.config"
Action="create" On="install"
Node="value"
ElementPath="/configuration/system.web/compilation"
Name="debug"
Value="false" />
<!--Session configuration <sessionState mode="InProc" timeout="15" />-->
<util:XmlFile Id="system.websessionState"
File="[INSTALLLOCATION]Web.config"
Action="createElement"
ElementPath="/configuration/system.web"
Name="sessionState"
Sequence="8" />
<util:XmlFile Id="system.websessionStateAttribute"
Action="setValue"
File="[INSTALLLOCATION]Web.config"
ElementPath="/configuration/system.web/sessionState"
Name="mode" Value="InProc"
Sequence="9" />
<util:XmlFile Id="system.websessionStateAttribute2"
Action="setValue"
File="[INSTALLLOCATION]Web.config"
ElementPath="/configuration/system.web/sessionState"
Name="timeout"
Value="15"
Sequence="10" />
<util:XmlFile Id="system.websessionStateAttribute3"
Action="setValue"
File="[INSTALLLOCATION]Web.config"
ElementPath="/configuration/system.web/sessionState"
Name="cookieName"
Value="[VIRTUALDIRECTORYVALUE]"
Sequence="11" />
</Component>
<iis:WebSite Id='DefaultWebSite'
Description='Default Web Site'
Directory='INSTALLLOCATION' SiteId ='[WEBSITEVALUE]' >
<iis:WebAddress Id="AllUnassigned" Port="80" />
</iis:WebSite>
<iis:WebAppPool Id="AppPool" Name="[APPPOOLVALUE]" />
<CustomAction Id="MapVirtualDirectory" Directory="INSTALLLOCATION" Return="asyncNoWait"
ExeCommand='[ASPNETREGIIS] -norestart -s "W3SVC/[WEBSITEVALUE]/ROOT/[VIRTUALDIRECTORYVALUE]"' />
<InstallExecuteSequence>
<Custom Action="MapVirtualDirectory" After="InstallFinalize" >ASPNETREGIIS AND NOT Installed</Custom>
</InstallExecuteSequence>
<CustomAction Id="GetIISWebSites" BinaryKey="IisManager" DllEntry="GetWebSites" Execute="immediate" Return="check" />
<CustomAction Id="GetIISAppPools" BinaryKey="IisManager" DllEntry="GetAppPools" Execute="immediate" Return="check" />
<InstallUISequence>
<Custom Action="GetIISWebSites" After="CostFinalize" Overridable="yes">NOT Installed</Custom>
<Custom Action="GetIISAppPools" After="CostFinalize" Overridable="yes">NOT Installed</Custom>
</InstallUISequence>
<Feature Id='ApplicationFeatures' Title="!(loc.ProductName)" Level='1'>
<ComponentRef Id='WebVirtualDirComponent' />
<ComponentGroupRef Id="MyWebApp_Project" />
<ComponentRef Id="Web.config" />
</Feature>
<!-- Specify UI -->
<Property Id="WIXUI_INSTALLDIR">INSTALLLOCATION</Property>
<UIRef Id="MyCustomUI"/>
这里是我的本地化文件:
<?xml version="1.0" encoding="utf-8"?>
<WixLocalization Culture="en-us" xmlns="http://schemas.microsoft.com/wix/2006/localization">
<!--application settings-->
<String Id="LANG">1033</String>
<String Id="ProductName">MyTestWebSite</String>
<String Id="ProductVersion">1.0.0.0</String>
<String Id="CompanyName">MyCompanyName</String>
<String Id="DefaultDocument">Default.aspx</String>
<String Id="WebApplicationProjectName">MyWebApp</String>
<!--database settings-->
<String Id="EntityName">MyEntities</String>
<String Id="ModelName">MyModel</String>
</WixLocalization>
XmlFile
和XmlConfig
都写在原子水平的属性。 为了得到你想要的行为,你会想要写立即自定义操作来读取XML文件,并把结果保存在一个Property
。 然后操作这些Property
,您认为合适(你可能需要做的是,在您的自定义操作,如果操作很复杂),然后有XmlFile
或XmlConfig
写入整个操作值退了出去。
此方法将允许需要至少一套复杂的代码中的自定义操作XmlFile
和XmlConfig
做繁重和手柄回滚和所有的东西。 只是要修改的Property
幂等。
祝好运!