2017-02-02 3 views
1
<?xml version="1.0" encoding="UTF-8"?> 
<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi"> 
    <Product Id="*" Name="MyApp" Language="1033" Version="1.0.0.0" Manufacturer="MyAppDev" UpgradeCode="067ac37f-0d36-4173-a24a-5037927bd6da"> 
    <Package InstallerVersion="200" Compressed="yes" InstallScope="perMachine" /> 
    <MajorUpgrade DowngradeErrorMessage="A newer version of [ProductName] is already installed." /> 
    <MediaTemplate /> 
    <Feature Id="ProductFeature" Title="MyApp" Level="1"> 
     <ComponentGroupRef Id="ProductComponents" /> 
    </Feature> 
    </Product> 
    <Fragment> 
    <Directory Id="TARGETDIR" Name="SourceDir"> 
     <Directory Id="ProgramFilesFolder"> 
     <Directory Id="INSTALLFOLDER" Name="MyApp" /> 
     </Directory> 
    </Directory> 
    </Fragment> 
    <Fragment> 
    <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> 
     <File Source="$(var.MyApp.TargetPath)" /> 
     </Component> 
     <Component> 
     <File Id="Postcodes.txt" Source="C:\Project\MyApp\MyApp\Files\Postcodes.txt" KeyPath="yes" /> 
     </Component> 
    </ComponentGroup> 
    <Feature Id="MainApplication" Title="Main Application" Level="1"> 
      <ComponentRef Id="Postcodes.txt" /> 
     </Feature> 
    </Fragment> 
</Wix> 

Приложение для Windows Form, используя текстовый файл, который хранится в каталоге приложения. И с помощью набора инструментов WIX. Я создал установщик Но проблема в том, что текстовый файл контента не существует. Вот почему я получаю исключение File not found.Как добавить файл содержимого в установщик Wix

Пожалуйста, помогите мне, как я могу добавить этот текстовый файл для контента в установщик WIX? Или что мне нужно добавить файл «Product.wxs»?

+0

вам нужно создать новый файл класса, а затем запустить его во время установки. Я выкопаю какой-нибудь код, который покажет вам, как это сделать. –

+0

Да, пожалуйста, поделитесь этим кодом. Спасибо @SimonPrice –

ответ

0

Вам необходимо добавить специальное действие. Это прямая копия моей работы за вычетом названия компании, для которой она была создана.

<CustomAction Id="RestAction" BinaryKey="myCompanyAgentSetup.WixExtension.Package.dll" DllEntry="Execute" Execute="immediate" Return="check" /> 

Это файл класса \ dll, созданный в проекте Wix. Это мой фактический длл \ файл класса

using System; 
using System.Collections.Generic; 
using System.Data; 
using System.IO; 
using System.Linq; 
using System.Net; 
using System.Text; 
using System.Text.RegularExpressions; 
using System.Threading.Tasks; 
using Microsoft.Deployment.WindowsInstaller; 

namespace myCompanyAgentSetup.WixExtension 
{ 
public static class myCompanyAgentSetupWixExtension 
{ 
    [CustomAction] 
    public static ActionResult Execute(Session session) 
    { 
     var errorMsg = string.Empty; 
     var record = new Record(); 
     var token = Environment.GetEnvironmentVariable("RX_JOB_NO"); 

     var restUser = session["RESTUSER"]; 
     var restPass = session["RESTPASS"]; 
     var restUrl = string.Format(session["RESTURL"], token); 

     var request = (HttpWebRequest)WebRequest.Create(restUrl); 
     var encoded = Convert.ToBase64String(Encoding.Default.GetBytes(restUser + ":" + restPass)); 
     request.Headers.Add(HttpRequestHeader.Authorization, "Basic " + encoded); 
     request.Credentials = new NetworkCredential(restUser, restPass); 
     Console.WriteLine("attempting to get API Key"); 

     try 
     { 
      var response = (HttpWebResponse)request.GetResponse(); 

      if (response.StatusCode.ToString() != "OK") 
      { 
       record = new Record 
       { 
        FormatString = string.Format(response.StatusDescription) 
       }; 
       session.Message(InstallMessage.Error, record); 
       Console.WriteLine("Unable to get API Key"); 
       Console.WriteLine("Adding RX_CLOUDBACKUP_API Environment Variable with no value"); 
       UpdateConfigFiles(""); 

      } 
      else 
      { 
       var apiKey = new StreamReader(response.GetResponseStream()).ReadToEnd(); 
       if (apiKey.Contains("Error")) 
       { 

        record = new Record 
        { 
         FormatString = string.Format(apiKey) 
        }; 
        session.Message(InstallMessage.Error, record); 
        session.Message(InstallMessage.Terminate, record); 
       } 
       Console.WriteLine("Adding RX_CLOUDBACKUP_API with value - " + apiKey); 
       UpdateConfigFiles(apiKey); 

       return ActionResult.Success; 
      } 

     } 
     catch (Exception e) 
     { 
      record = new Record 
      { 
       FormatString = string.Format(e.Message) 
      }; 
      session.Message(InstallMessage.Error, record); 
      session.Message(InstallMessage.Terminate, record); 
     } 

     //An error has occurred, set the exception property and return failure. 
     session.Log(errorMsg); 
     session["CA_ERRORMESSAGE"] = errorMsg; 

     record = new Record 
     { 
      FormatString = string.Format("Something has gone wrong!") 
     }; 
     session.Message(InstallMessage.Error, record); 
     session.Message(InstallMessage.Terminate, record); 
     return ActionResult.Failure; 
    } 

    private static void UpdateConfigFiles(string apiKey) 
    { 
     if (!string.IsNullOrEmpty(apiKey)) 
     { 
      Environment.SetEnvironmentVariable("RX_CLOUDBACKUP_API", null, EnvironmentVariableTarget.Machine); 
      Environment.SetEnvironmentVariable("RX_CLOUDBACKUP_API", apiKey, EnvironmentVariableTarget.Machine); 
     } 
     else 
     { 
      Environment.SetEnvironmentVariable("RX_CLOUDBACKUP_API", "", EnvironmentVariableTarget.Machine); 
     } 

    } 
} 

}

Надеюсь, это поможет вам идти. Если вам нужно что-то еще, дайте мне знать