开发者

Build MSI to install DLL and make it accessible from "Add References" in VS

I'd like to build an MSI installer that installs a managed DLL and makes it accessible to users from Visual Studio's "Add References" menu in Solution Explorer. I believe I am supposed to add a key into the Windows registry but I cannot see how to tell the VS project for the MSI to do this at install.

How is this done and where should I loo开发者_开发问答k for tutorials on this kind of thing?


Go to the following registry key:

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\.NETFramework\AssemblyFolders

Add a subkey (the name of which doesn't matter, but might as well be descriptive) whose default value is the folder containing your assemblies, and you should be good to go.

How to add the required key using WiX

This is a stripped-down fragment of WiX code for creating the required key and setting its default value to the folder in which your assemblies were installed. This is not a complete WiX installer and cannot be pasted directly -- I have removed Guid attributes and shown only the Directory, Component and Feature declarations. Once you've seen some complete WiX code it should be reasonably clear how to merge these bits in.

<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi">
  <!-- Path from WiX file to the DLL(s) you're installing -->
  <?define BuildPath="..\Bin\Release" ?>
  <!-- The base key path - note no HKLM -->
  <?define AssemblyFolders = "Software\Microsoft\.NETFramework\AssemblyFolders" ?>

  <Product>
    <Directory Id="TARGETDIR" Name="SourceDir">
      <Directory Id="ProgramFilesFolder">
        <Directory Id="CompanyFolder" Name="YourCompany">
          <Directory Id="INSTALLLOCATION" Name="Your Product">
            <!-- Id="AssemblyFolder" captures the location where the DLL gets installed -->
            <Directory Id="AssemblyFolder" Name="Bin">
              <Component Id="AssemblyComponent">
                <!-- This is the bit that copies the assembly file -->
                <File Id="YourDll.dll" Checksum="yes" Source="$(var.BuildPath)YourDll.dll" />
              </Component>
              <Component Id="ControlRegistrationComponent">
                <!-- This is the bit that creates the registry key -->
                <RegistryKey Action="createAndRemoveOnUninstall" Root="HKLM" Key="$(var.AssemblyFolders)\Your Product Name">
                  <!-- Square brackets result in a reference -- so the install folder gets picked up -->
                  <RegistryValue Action="write" Value="[AssemblyFolder]" Type="string" />
                </RegistryKey>
              </Component>
            </Directory>
          </Directory>
        </Directory>
      </Directory>
    </Directory>

    <Feature Id="PRODUCTROOTFEATURE">
      <!-- This causes the assembly to be installed -->
      <ComponentRef Id="AssemblyComponent" />
      <!-- This causes the registry key to be created -->
      <ComponentRef Id="ControlRegistrationComponent" />
    </Feature>

  </Product>
</Wix>

To build the MSI once you've got a full WiX script, you can use a batch file, the core of which looks like this:

candle.exe "%WXS_NAME%.wxs" -out "%WXS_NAME%.wixobj"
light.exe "%WXS_NAME%.wixobj" -out "%WXS_NAME%.msi"

where %WXS_NAME% is the name of the WiX .wxs source file.

(I realise this probably looks a bit cryptic but (a) there are lots of WiX samples, tutorials and reference material out there to help you get started and (b) the Votive add-in for Visual Studio may shield you from some of the guts anyway.)

To automatically build the MSI, use the Votive add-in (part of WiX), or a post-build step, or a MSBuild build script. We use a build script because we usually want to build the MSI only as part of our automated build -- doing it in a post-build step would slow down development builds -- but your mileage may vary.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜