2012-08-08 143 views
47

因此,我在Wix中安裝了此項目,並希望在桌面上擁有快捷方式。 這一定很容易,你可能會想。但事實並非如此。 在因特網上找到的所有代碼片段都不起作用。 經過幾個小時的努力和閱讀文檔,我終於明白了,所以我在這裏與你分享。使用WiX創建桌面快捷方式

+0

這是我覺得有這麼多的微軟的「技術」這幾天的方式。這個評論差不多三年後。所以顯然,現有技術水平沒有得到改善。 – 2018-01-21 05:59:52

回答

61

快捷方式是非廣告的,希望這有助於某人。請記住將組件放入功能標籤中。

<Directory Id="TARGETDIR" Name="SourceDir"> 
    <Directory Id="DesktopFolder" Name="Desktop"> 
     <Component Id="ApplicationShortcutDesktop" Guid="*"> 
      <Shortcut Id="ApplicationDesktopShortcut" 
       Name="Text under your icon" 
       Description="Comment field in your shortcut" 
       Target="[MYAPPDIRPROPERTY]MyApp.exe" 
       WorkingDirectory="MYAPPDIRPROPERTY"/> 
      <RemoveFolder Id="DesktopFolder" On="uninstall"/> 
      <RegistryValue 
       Root="HKCU" 
       Key="Software/MyAppName" 
       Name="installed" 
       Type="integer" 
       Value="1" 
       KeyPath="yes"/> 
     </Component> 
    </Directory> 

    <Directory Id="ProgramFilesFolder" Name="PFiles"> 
     <Directory Id="MyCompany" Name="MyCompany"> 
      <Directory Id="MYAPPDIRPROPERTY" Name="MyAppName"> 
       <!-- main installation files --> 
      </Directory> 
     </Directory> 
    </Directory> 
</Directory> 
+0

您的註冊表項上需要反斜槓 – 2013-05-14 19:36:21

+7

請勿發佈硬編碼的GUID。把'Guid =「*」'改爲自動生成GUID,或者使用{PUT-GUID-HERE} – 2014-08-10 19:13:55

+1

註冊表值是什麼? – BatteryBackupUnit 2015-06-17 11:59:37

26

我認爲我的方式比較容易,沒必要爲你創建一個註冊表項:

<Directory Id="TARGETDIR" Name="SourceDir"> 
    <Directory Id="DesktopFolder" SourceName="Desktop" /> 
    <Directory Id="MergeRedirectFolder"> 
    <Component Id="MyExeComponent" Guid="{PUT-GUID-HERE}"> 
     <File Id="MyExeFile" Source="$(var.ExeSourcePath)" KeyPath="yes"> 
     <Shortcut 
      Id="DesktopShortcut" 
      Directory="DesktopFolder" 
      Name="$(var.ShortcutName)" 
      WorkingDirectory="MergeRedirectFolder" /> 
     </File> 
    </Component> 
    </Directory> 
</Directory> 
+1

從[documentation](http://wixtoolset.org/documentation/manual/v3/howtos/files_and_registry/create_start_menu_shortcut.html)註冊表項:_「這是必需的,因爲當爲當前用戶安裝非通告的快捷方式時,快捷方式不能充當組件的KeyPath。」_ – blins 2017-08-04 16:33:32

+0

文件組件本身是關鍵路徑,快捷方式「繼承」文件屬性。這種方式可能有點令人困惑,雖然當您嘗試追蹤許多文件中的桌面快捷方式時..用戶對於緊湊性和可追溯性的偏好我認爲? – 2018-01-02 13:55:36

13

感謝例子。在WIX 3.8中它仍然引發: 「錯誤3 ICE43:組件...具有未公佈的快捷方式,它應該使用HKCU下的註冊表項作爲其KeyPath,而不是文件。」

所以,我沒有與功能的文件這樣這樣的方式:

<Component Id="cmp79F6D61F01DD1060F418A05609A6DA70" 
       Directory="dirBin" Guid="*"> 
     <File Id="fil34B100315EFE9D878B5C2227CD1454E1" KeyPath="yes" 
      Source="$(var.SourceDir)\FARMS.exe" > 
     <Shortcut Id="DesktopShortcut" 
        Directory="DesktopFolder" 
        Name="FARMS $(var.FarmsVersion)" 
        Description="Local Land Services desktop application" 
        WorkingDirectory="INSTALLFOLDER" 
        Icon="FARMS.exe" 
        IconIndex="0" 
        Advertise="yes" > 
      <Icon Id="FARMS.exe" SourceFile="$(var.SourceDir)\FARMS.exe" /> 
     </Shortcut> 
     </File> 
    </Component> 

而且在產品定義文件中提到桌面文件夾:

<Fragment> 
    <Directory Id="TARGETDIR" Name="SourceDir"> 
     <Directory Id="DesktopFolder" Name="Desktop" /> 

     <Directory Id="ProgramFilesFolder"> 
     <Directory Id="INSTALLFOLDER" Name="FARMS" > 
     </Directory> 
     </Directory> 
    </Directory> 
    </Fragment> 
1

似乎在這個documentation輕鬆了許多。

首先,你必須指向你的DesktopFolder,

<Fragment> 
    <Directory Id="TARGETDIR" Name="SourceDir"> 
     <Directory Id="DesktopFolder" Name="Desktop"/> 

那麼你應該要創建的快捷方式文件創建快捷方式組件。

<Component Id="PutYourComponentIdHere" Directory="FileDirectory" Guid="*"> 
    <File Id="NotYourComponentId" KeyPath="yes" Source="..\YourFileSource\YourExecutable.exe"> 
     <Shortcut Id="desktopServer" Directory="DesktopFolder" Name="YourShourtcutName" WorkingDirectory='WhereShouldYourShortcutPoint' Advertise="yes"/> 
    </File> 
    </Component> 

它爲我工作。我需要把圖標,但這很容易的一部分。希望它有效。

2

太多精力後,我用這樣的方式:

<Product ...> 
    <Feature Id="ProductFeature" Title="SetupProject" Level="1"> 
     ... 
     ... 
     <ComponentRef Id="cmpDesktopShortcut" /> 
    </Feature> 

    <Component Id="cmpDesktopShortcut" Guid="PUT-GUID-HERE" Directory="DesktopFolder" > 
     <Shortcut Id="MyDesktopShortcut" 
        Name="Setup Project" 
        Description="Opens the program." 
        Directory="DesktopFolder" 
        Target="[INSTALLFOLDER]App.exe" 
        WorkingDirectory="INSTALLFOLDER"/> 
     <RegistryValue Root="HKCU" Key="Software\My Company\Sample Application" Name="installed" Type="integer" Value="1" KeyPath="yes" /> 
    </Component> 
</Product> 
相關問題