2016-04-08 13 views
1

こんにちは私はWixを使用してインストーラを作成しています。このインストーラは、インストーラがユーザのシステムにコピーするファイルのパスにレジストリ値を書き込む必要があります。問題は、レジストリエントリがこの形式私は私は本当に後者の表記を変換するのに苦労していますWixで文字列を操作してプロパティを設定するカスタムアクション

C:\Program Files\.... 

を指すINSTALLFOLDERディレクトリIDを持ってウィックスコードプロジェクトで

file:///C:/Program Files/.... 

で書かれるべきであるということです前者に私はそれを使用できるようにプロパティを設定することを望むカスタムアクションを作成しました。コード

カスタムアクションされ、次の(今のところ別のDLLは、それをインライン化することができますか?)

public class CustomActions 
    { 
     [CustomAction] 
     public static ActionResult CustomAction1(Session session) 
     { 
      session.Log("Begin CustomAction1"); 
      string origValue = session["INSTALLFOLDER"]; 
      MessageBox.Show(origValue); 
      string retVal = origValue.Replace("\\", "//"); 
      MessageBox.Show(retVal); 
      session["Custom_Prop"] = retVal; 
      return ActionResult.Success; 
     } 
    } 

そしてProduct.wxsを

<?xml version="1.0" encoding="UTF-8"?> 
<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi"> 

    <Product Id="*" Name="SetupProject1" Language="1033" Version="1.2.0.0" Manufacturer="nik" UpgradeCode="4a74ff86-49a9-4011-9794-e1c18077172f"> 
    <Package InstallerVersion="200" Compressed="yes" InstallScope="perMachine" /> 

    <MajorUpgrade DowngradeErrorMessage="A newer version of [ProductName] is already installed." /> 
    <MediaTemplate /> 

    <Feature Id="ProductFeature" Title="SetupProject1" Level="1"> 
     <ComponentGroupRef Id="ProductComponents" /> 
    </Feature> 

    <InstallExecuteSequence> 
     <Custom Action='FooAction' Before='InstallFinalize'>NOT Installed</Custom> 
    </InstallExecuteSequence> 

    </Product> 

    <Fragment> 
    <CustomAction Id='FooAction' BinaryKey='FooBinary' DllEntry='CustomAction1' Execute='immediate' 
        Return='check'/> 

    <Binary Id='FooBinary' SourceFile='MyCustomAction.CA.dll'/> 
    </Fragment> 


    <Fragment> 
    <Directory Id="TARGETDIR" Name="SourceDir"> 
     <Directory Id="ProgramFilesFolder"> 
     <Directory Id="INSTALLFOLDER" Name="SetupProject1" /> 
     </Directory> 
    </Directory> 
    </Fragment> 

    <Fragment> 
    <Property Id="Custom_Prop" Value="[ProgramFilesFolder]"></Property> 
    <ComponentGroup Id="ProductComponents" Directory="INSTALLFOLDER"> 
     <!-- TODO: Remove the comments around this Component element and the ComponentRef below in order to add resources to this installer. --> 
     <!-- <Component Id="ProductComponent"> --> 
     <!-- TODO: Insert files, registry keys, and other resources here. --> 
     <!-- </Component> --> 
     <Component Id="cmp_Add_Mainfest_To_Registry" Guid="955A3A76-F010-4FCB-BCAF-B297AFD1C05B"> 

     <RegistryKey Root="HKCU" Key="SOFTWARE\company"> 

      <RegistryValue Name="LoadBehavior" Value="3" Type="integer" Action="write" /> 

      <RegistryValue Name="Manifest" Value="[Custom_Prop]" Type="string" Action="write" KeyPath="yes"/> 
     </RegistryKey> 
     </Component> 
    </ComponentGroup> 
    </Fragment> 
</Wix> 

しかし、私は値が書かれた、このセットアップを実行するとC:\またはC:/

誰かに助けてもらえるリテラル文字列[ProgramFolder]です。

答えて

1

この作品を作った以下のように属性の前の値を変更するには、この行

<InstallExecuteSequence> 
     <Custom Action='FooAction' Before='InstallFinalize'>NOT Installed</Custom> 
    </InstallExecuteSequence> 

私のコードだっ働いていなかった理由は、

<InstallExecuteSequence> 
     <Custom Action='FooAction' Before='CostFinalize'>NOT Installed</Custom> 
    </InstallExecuteSequence> 

しかし与えられた私のニーズは非常に単純な私でしたCustomActionのための別のDLLを持たないことに決め、代わりにWix Project内のvbscriptでカスタムアクションを実行しました。だからコードは次のようになります

<?xml version="1.0" encoding="UTF-8"?> 
<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi"> 

    <Product Id="*" Name="SetupProject1" Language="1033" Version="1.3.1.0" Manufacturer="nik" UpgradeCode="4a74ff86-49a9-4011-9794-e1c18077172f"> 
    <Package InstallerVersion="200" Compressed="yes" InstallScope="perMachine" /> 

    <MajorUpgrade DowngradeErrorMessage="A newer version of [ProductName] is already installed." /> 
    <MediaTemplate /> 

    <Feature Id="ProductFeature" Title="SetupProject1" Level="1"> 
     <ComponentGroupRef Id="ProductComponents" /> 
    </Feature> 

    <InstallExecuteSequence> 
     <Custom Action="VBScriptCommand" After="CostFinalize">NOT REMOVE</Custom> 
    </InstallExecuteSequence> 

    </Product> 

    <Fragment> 


    <CustomAction Id="VBScriptCommand" Script="vbscript"> 
     <![CDATA[   
    value = Session.Property("INSTALLFOLDER") 
    origPath=Session.Property("INSTALLFOLDER") 
    If Right(webdir, 1) = "\" Then 
     value = Left(value, Len(value) - 1) 
    End If 

    Session.Property("SOME_PROPERTY") = Replace(origPath,"\","//")  
    ]]> 
    </CustomAction> 

    </Fragment> 

    <Fragment> 
    <Directory Id="TARGETDIR" Name="SourceDir"> 
     <Directory Id="ProgramFilesFolder"> 
     <Directory Id="INSTALLFOLDER" Name="SetupProject1" /> 
     </Directory> 
    </Directory> 
    </Fragment> 

    <Fragment> 
    <Property Id="Custom_Prop" Value="[ProgramFilesFolder]"></Property> 
    <ComponentGroup Id="ProductComponents" Directory="INSTALLFOLDER"> 

     <Component Id="cmp_Add_Mainfest_To_Registry" Guid="955A3A76-F010-4FCB-BCAF-B297AFD1C05B"> 

     <RegistryKey Root="HKCU" Key="SOFTWARE\something"> 

      <RegistryValue Name="LoadBehavior" Value="3" Type="integer" Action="write" /> 
      <!--<RegistryValue Name="Manifest" Value="[#FILE_VstoManifest]|vstolocal" Type="string" Action="write" />--> 
      <RegistryValue Name="Manifest" Value="file:///[SOME_PROPERTY]" Type="string" Action="write" KeyPath="yes"/> 
     </RegistryKey> 
     </Component> 
    </ComponentGroup> 
    </Fragment> 
</Wix> 

恐らく純粋主義者はこのようには思えませんが、なぜショット銃を使ってフライを殺すのでしょうか?

関連する問題