由于使用Wix生成安装文件导致Gmap异常

时间:2014-10-08 12:22:34

标签: c# google-maps wix installation

我想在我的C#应用​​程序中创建安装文件,这个应用程序使用外部库,这是" Gmap"库。 所以C#App的形式如下:

public Form1()
    {
        InitializeComponent();
        try
        {
            Map.Top = 2;
            Map.Left = 2;
            Map.Width = 500;
            Map.Height = 1000;
            try
            {
                System.Net.IPHostEntry q = System.Net.Dns.GetHostEntry("www.google.com");
            }
            catch
            {
                Map.Manager.Mode = AccessMode.ServerAndCache;
            }
            Map.MapProvider = GMapProviders.BingSatelliteMap;
            Map.Position = new PointLatLng(32.528361, 35.924263); //new PointLatLng(25.470709, 55.52634);//PointLatLng(32.528361, 35.924263);// Map.Position = new PointLatLng(32.49159, 35.994);
            Map.CacheLocation = Application.StartupPath;
            Map.MinZoom = 1;
            Map.MaxZoom = 20;
            Map.Zoom = 16;
            Map.DragButton = MouseButtons.Left;
        }catch(Exception e)
        { MessageBox.Show(e.ToString()); }
    }

当我运行此应用程序时,它成功显示地图并且完全没有问题。

但是当我尝试将其转换为设置文件时,我使用Wix工具集my .wsx如下:

<?xml version="1.0" encoding="UTF-8"?>

             

    <Media Id="1" Cabinet="media1.cab" EmbedCab="yes" />

    <Directory Id="TARGETDIR" Name="SourceDir">
        <Directory Id="ProgramFilesFolder">
            <Directory Id="INSTALLLOCATION" Name="Last">
                <!-- TODO: Remove the comments around this Component element and the ComponentRef below in order to add resources to this installer. -->
                 <Component Id="ProductComponent" Guid="{BA6619DF-FA4C-4537-BD61-684BB2E0457F}">
         <File Source="$(var.d.TargetPath)" KeyPath="yes" />
                 </Component>

      <Component Id="ProductComponent2" Guid="{04116569-43D0-4433-A158-E24938CCE88A}">
        <File Source="..\d\bin\Debug\GMap.NET.Core.dll" KeyPath="yes"/>
      </Component>

      <Component Id="ProductComponent3" Guid="{BCE640B2-8E99-4B02-B28C-9DA9E8841F7C}">
        <File Source="..\d\bin\Debug\GMap.NET.WindowsForms.dll" KeyPath="yes"/>
      </Component>

    </Directory>
        </Directory>
    </Directory>

    <Feature Id="ProductFeature" Title="Last" Level="1">
        <!-- TODO: Remove the comments around this ComponentRef element and the Component above in order to add resources to this installer. -->
         <ComponentRef Id="ProductComponent" />
  <ComponentRef Id="ProductComponent2" />
  <ComponentRef Id="ProductComponent3" />
  <!-- Note: The following ComponentGroupRef is required to pull in generated authoring from project references. -->
        <ComponentGroupRef Id="Product.Generated" />
    </Feature>
</Product>

当我安装安装文件,然后转到程序文件运行APP的.exe时,我有这个例外:

enter image description here

如何以正确的方式使用这些外部库?

1 个答案:

答案 0 :(得分:1)

我建议您删除Map.CacheLocation = Application.StartupPath;并使用默认位置。缓存位置必须位于用户的可写文件夹中。

程序在用户运行时,不会写入管理员安装程序文件的位置。此外,程序通常不会在用户之间共享数据,而不会使用户清楚。如果您确实想共享缓存,可以使用CommonApplicationData这样的公共位置,如下所示:

System.Environment.GetFolderPath(System.Environment.SpecialFolder.CommonApplicationData) 
  + Path.DirectorySeparatorChar + "GMap.NET" + Path.DirectorySeparatorChar