2013-04-24 34 views
7

Tôi hiện đang cố sửa đổi trình cài đặt Wix (V3.5) của mình để chỉnh sửa cài đặt Web.config của ứng dụng .NET mà tôi muốn cài đặt. Điều này là tốt cho các ứng dụng ASP.NET bình thường nhưng bây giờ tôi đang cố gắng áp dụng dự án thiết lập Wix của tôi cho ứng dụng Entity Framework .NET, như bạn có thể biết có một thiết lập chuỗi kết nối phức tạp hơn với các thiết lập mô hình .csdl và .ssdl.Chỉnh sửa cài đặt chuỗi kết nối Web.Config Connection với Wix

Vì vậy, nếu web.config thiết lập chuỗi kết nối của tôi trông somehting như thế này: (trong đó [DBSERVER] & [DBNAME] là tài sản retrived từ một hộp thoại)

<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=&quot;Data Source=sd-sql2008r2;Initial Catalog=SsiTacticalSolution1.2.4;Integrated Security=True;MultipleActiveResultSets=True&quot; /> 
    </connectionStrings> 

Và tôi sửa Web.config của tôi trong tôi tập tin Product.Wsx với somehting như thế này:

<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&quot;" Sequence="5"/> 

tôi nhận được một chuỗi kết nối như thế này:

<connectionStrings> 
     <add name="SSITacticalSolutionEntities" connectionString="Data Source=sd-sql2008r2;Initial Catalog=SsiTacticalSolution1.2.4;Integrated Security=true;providerName=System.Data.EntityClient;MultipleActiveResultSets=True&quot;"/> 
    </connectionStrings> 

Tất nhiên là có ý nghĩa, vì im yêu cầu nó thay thế thuộc tính chuỗi kết nối hiện tại bằng những gì tôi đã xác định trong giá trị.

Nhưng những gì tôi thực sự cần ở đây là chỉnh sửa các phần cụ thể trong chuỗi kết nối của mình và để phần còn lại (có một số hành động thay thế tôi có thể sử dụng tại đây), tức là. để lại tất cả các thiết lập mô hình của tôi tại chỗ và chỉ cần thay thế máy chủ cơ sở dữ liệu và tên vv như tôi cần. Tôi sử dụng để làm điều này với các trình cài đặt Visual Studio không có vấn đề và nó rất dễ sử dụng.

Vì vậy, câu hỏi của tôi là điều này có thể được thực hiện bằng cách sử dụng util.XMLFile, hoặc có lẽ util: XmlConfig? Tôi đã thử cả hai mà không có may mắn.

Hoặc điều này không thể thực hiện với util.XMLFile và tôi có phải thực hiện việc này trong CustomAction thay thế không? Bất kỳ ý tưởng nào sẽ giúp ích rất nhiều, cảm ơn trước ...

Trả lời

8

Tôi đã làm việc này cuối cùng, cuối cùng tôi không sử dụng các hành động tùy chỉnh cho cài đặt cụ thể này, tôi sử dụng các biến được thiết lập trong tệp bản địa hóa của tôi.

Tôi đã làm điều này bởi vì nó sẽ là dev thay vì sau đó người dùng sẽ biết tên mô hình và tên thực thể (không phải là người dùng thông qua hộp thoại cài đặt, họ sẽ không biết thông tin này), vì vậy tôi có một tập tin bản địa hóa với các thuộc tính khác nhau trong nó như tên sản phẩm, vv, vì vậy tôi đã thêm vào một tên model và đặt tên cho nó. Mọi thứ khác tôi nhận được từ hộp thoại, được nhập bởi người dùng: nghĩa là tên cơ sở dữ liệu, thư mục ảo, người dùng mạo danh, v.v ...

Nếu nó giúp bất cứ ai, đây là những gì tôi đưa ra cuối cùng cho web.config; Đây là phần của sản phẩm của tôi.wxs đề cập đến vấn đề này. Như bạn có thể thấy tôi có một tài sản chuỗi kết nối ở phía trên, với một giữ chỗ cho loc.ModelName mà được thiết lập trong file nội địa hóa của tôi:

<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=&quot;"/> 

<!-- 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&quot;" 
         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"/> 

Đây là tập tin nội địa hóa của tôi:

<?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> 
+1

Necro nhưng ... thực hành tốt hơn là thay thế GUID thực của bạn bằng "PUT-GUID-HERE" trong ví dụ. – Izzy

+1

Cảm ơn bạn đã nhờ mẹo Izzy – Alicia

2

XmlFileXmlConfig cả hai thuộc tính ghi ở cấp nguyên tử. Để có được hành vi bạn muốn, bạn muốn viết một hành động tùy chỉnh ngay lập tức để đọc tệp XML và lưu trữ kết quả trong một Property. Sau đó, thao tác rằng Property như bạn thấy phù hợp (bạn có thể cần phải làm điều đó trong hành động tùy chỉnh của bạn nếu thao tác phức tạp), sau đó có XmlFile hoặc XmlConfig viết toàn bộ giá trị thao tác trở lại.

Phương pháp này sẽ yêu cầu tập hợp hành động tùy chỉnh ít phức tạp nhất trong mã của bạn bằng cách cho phép XmlFileXmlConfig thực hiện việc nâng và xử lý nặng và tất cả nội dung đó. Chỉ cần thực hiện các sửa đổi đối với mã định danh Property.

Chúc may mắn!

+0

Cảm ơn Rob.I hiện không thêm web.config của tôi thông qua quá trình msbuild và thêm nó seperatly thông qua một thành phần trên trong product.wsx của tôi. Lý do cho điều này là, cũng như thao tác các thiết lập connectionstring, tôi cũng có một số Alicia

+0

Vâng, cuối cùng, bạn phải nạp kết quả vào một thuộc tính '' hoặc chuỗi thuộc tính để phân giải thành một dòng trong 'XmlFile'. Tôi chắc chắn nó có thể làm được, ma quỷ chỉ là trong các chi tiết. :) –

Các vấn đề liên quan