简体   繁体   English

如何将命令行属性传递给setup.exe

[英]how to pass command line properties to setup.exe

I want to pass parameters to msi when calling setup.exe as following : 我想在调用setup.exe时将参数传递给msi,如下所示:

setup.exe /l* log.txt EXEPATH="C:\Program Files (x86)\MySetup\MyApplication.exe"

I have the following msbuild file : 我有以下msbuild文件:

<Project ToolsVersion="4.0"
   xmlns="http://schemas.microsoft.com/developer/msbuild/2003">

    <PropertyGroup>
        <exeD Condition="'$(EXEPATH)'!=''">$(EXEPATH.substring(0,$([MSBuild]::Add($(EXEPATH.lastIndexOf("\")),1))))</exeD>
        <exeFile Condition="'$(EXEPATH)'!=''">$(EXEPATH.substring($([MSBuild]::Add($(EXEPATH.lastIndexOf("\")),1))))</exeFile>

    </PropertyGroup>

    <ItemGroup>
        <BootstrapperFile Include="Microsoft.Windows.Installer.4.5" >
            <ProductName>Windows Installer 4.5</ProductName>
        </BootstrapperFile>
    </ItemGroup>

    <Target Name="Bootstrapper">
      <Message Text="$(exeD)"/>
      <Message Text="$(exeFile)"/>
      <Message Text="$(EXEPATH)"/>
      <Exec Command="msiexec /i MySetup.msi  /L log2.txt EXEDIR=&quot;$(exeD)&quot; EXEFILENAME=&quot;$(exeFile)&quot;" Condition="'$(EXEPATH)'!=''" />
    </Target>
</Project>

As you can see I calculate two variables exeFile and exeD which I'll use in the Exec command which are supposed to be passed then to MSI file which wix file is : 如您所见,我计算了两个变量exeFile和exeD,我将在Exec命令中使用这两个变量,应该将它们传递给MIX文件,该wix文件为:

<?xml version="1.0" encoding="UTF-8"?>
<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi">
  <Product Id="*" Name="MySetup" Language="1033" Version="1.0.0.0" Manufacturer="Sofiane" UpgradeCode="c151e7ab-b83a-445f-93b2-2ab7122ea34b">
    <Package InstallerVersion="200" Compressed="yes" InstallScope="perMachine" />

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

    <Property Id="EXEDIR" Secure="yes" Value="{}"/>
    <Property Id="EXEFILENAME" Secure="yes" Value="{}"/>


    <Feature Id="ProductFeature" Title="MySetup" Level="1">
      <ComponentGroupRef Id="ProductComponents" />
    </Feature>
    <Binary Id="InstallTools" SourceFile="$(var.SolutionDir)InstallTools\bin\$(var.Configuration)\InstallTools.dll"/>
    <Binary Id="NotepadPlus" SourceFile="C:\Program Files (x86)\Notepad++\notepad++.exe"/>
    <!--<CustomAction Id="OpenExe" BinaryKey="InstallTools" DllEntry="OpenExeUrl" Execute="immediate" Impersonate="yes" Return="check" />-->
    <CustomAction Id="OpenExe" Return="ignore" Directory="exeDirectory"  ExeCommand="&quot;[EXEDIR]\[EXEFILENAME]&quot;" Impersonate="yes" Execute="deferred"/>
    <InstallExecuteSequence>
      <Custom Action="OpenExe" Before='InstallFinalize'/>
    </InstallExecuteSequence>
  </Product>

  <Fragment>
    <Directory Id="TARGETDIR" Name="SourceDir">
      <Directory Id="ProgramFilesFolder">
        <Directory Id="INSTALLFOLDER" Name="MySetup" />
      </Directory>
      <Directory Id="exeDirectory" FileSource="@(EXEDIR)" />
    </Directory>
  </Fragment>

  <Fragment>
    <DirectoryRef Id="INSTALLFOLDER">
      <Component Id="myAppFile">
        <File Source="$(var.MyApplication.TargetPath)" />
      </Component>
    </DirectoryRef>
    <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"> -->
      <ComponentRef Id="myAppFile" />
      <!-- </Component> -->
    </ComponentGroup>
  </Fragment>

</Wix>

What is strange is that when I test using, it works fine and the exe file is opened. 奇怪的是,当我测试使用时,它可以正常工作并打开exe文件。

MSBuild.exe bootstrapper.msbuild /p:EXEPATH="C:\Program Files (x86)\MySetup\MyApplication.exe"

The issue is that when I launch the setup.exe with the following command 问题是当我使用以下命令启动setup.exe时

setup.exe /l* log.txt EXEPATH="C:\Program Files (x86)\MySetup\MyApplication.exe"

The EXEPATH parameter seems not be used or I don't know why ? 似乎未使用EXEPATH参数,或者我不知道为什么?

Any advice please ? 有什么建议吗?

I resolve this issue by passing EXEPATH to MSI file and a custom action who will calculate EXEDIR and EXEFILENAME. 我通过将EXEPATH传递到MSI文件和一个将计算EXEDIR和EXEFILENAME的自定义操作来解决此问题。

Here is the custom action : 这是自定义操作:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Deployment.WindowsInstaller;
using System.Diagnostics;

namespace InstallTools
{
    public class CustomActions
    {
        [CustomAction]
        public static ActionResult OpenExeUrl(Session session)
        {
            try
            {
                session.Log("Inside custom action");

                var expath = session["EXEPATH"];
                session.Log("EXEPATH ==> " + expath);

                var exedir =expath.Substring(0, expath.LastIndexOf("\\")+1);
                session.Log("exedir ==> " + exedir);
                session["EXEDIR"] = exedir;

                var exefile = expath.Substring(expath.LastIndexOf("\\")+1);
                session.Log("exefile ==> " + exefile);
                session["EXEFILENAME"] = exefile;
            }
            catch (Exception e)
            {
                var errorMessage = "Cannot open exe file ! Error message: " + e.Message;
                session.Log(errorMessage);
            }

            return ActionResult.Success;
        }
    }
}

The Wix file : Wix文件:

<?xml version="1.0" encoding="UTF-8"?>
<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi">
  <Product Id="*" Name="MySetup" Language="1033" Version="1.0.0.0" Manufacturer="Sofiane" UpgradeCode="c151e7ab-b83a-445f-93b2-2ab7122ea34b">
    <Package InstallerVersion="200" Compressed="yes" InstallScope="perMachine" />

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

    <Property Id="EXEPATH" Secure="yes"/>

    <Feature Id="ProductFeature" Title="MySetup" Level="1">
      <ComponentGroupRef Id="ProductComponents" />
    </Feature>
    <Binary Id="InstallTools" SourceFile="$(var.SolutionDir)InstallTools\bin\$(var.Configuration)\InstallTools.CA.dll"/>
    <CustomAction Id="SetupProps" BinaryKey="InstallTools" DllEntry="OpenExeUrl" Execute="immediate" Impersonate="yes" Return="check" />
    <CustomAction Id="OpenExe" Return="ignore" Directory="exeDirectory"  ExeCommand="&quot;[EXEDIR]\[EXEFILENAME]&quot;" Impersonate="yes" Execute="deferred" />

    <InstallExecuteSequence>
      <Custom Action="SetupProps" Before="OpenExe"/>
      <Custom Action="OpenExe" Before="InstallFinalize"/>
    </InstallExecuteSequence>
  </Product>

  <Fragment>
    <Directory Id="TARGETDIR" Name="SourceDir">
      <Directory Id="ProgramFilesFolder">
        <Directory Id="INSTALLFOLDER" Name="MySetup" />
      </Directory>
      <Directory Id="exeDirectory" FileSource="@(EXEDIR)" />
    </Directory>
  </Fragment>

  <Fragment>
    <DirectoryRef Id="INSTALLFOLDER">
      <Component Id="myAppFile">
        <File Source="$(var.MyApplication.TargetPath)" />
      </Component>
    </DirectoryRef>
    <ComponentGroup Id="ProductComponents" Directory="INSTALLFOLDER">
      <ComponentRef Id="myAppFile" />
    </ComponentGroup>
  </Fragment>

</Wix>

and the msbuild script : 和msbuild脚本:

<Project ToolsVersion="4.0"
   xmlns="http://schemas.microsoft.com/developer/msbuild/2003">

    <ItemGroup>
        <BootstrapperFile Include="Microsoft.Windows.Installer.4.5" >
            <ProductName>Windows Installer 4.5</ProductName>
        </BootstrapperFile>
    </ItemGroup>

    <Target Name="Bootstrapper">
      <Message Text="EXEPATH = $(EXEPATH)"/>
      <Exec Command="msiexec /i MySetup.msi  /L log2.txt" Condition="'$(EXEPATH)'!=''"  />
    </Target>
</Project>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使用MSBuild从命令行为ClickOnce部署生成setup.exe - Generate setup.exe for ClickOnce deployment from command line using MSBuild 将msbuild属性传递给命令行上的devenv.exe - Pass msbuild properties to devenv.exe on the command line GenerateBootstrapper无法创建有效的setup.exe - GenerateBootstrapper fails to create a working setup.exe 如何在MSBuild中获取基本msi安装包(setup.exe)的文件版本 - How can I get File Version of basic msi installation package (setup.exe) in MSBuild 使用 msbuild 为 ClickOnce 应用程序生成 Setup.exe - Generate Setup.exe for ClickOnce application using msbuild 前提条件Setup.exe的错误URL单击VS 2008 - Error URL for Prerrequisites Setup.exe Click Once VS 2008 如何在MSBUILD(VS2005)中发布ClickOnce安装,该安装将转到正确的目录并且不创建setup.exe? - How do I publish a ClickOnce install in MSBUILD (VS2005) that goes to the proper directory and does NOT create a setup.exe? 带有MSBuild任务的MSBuild目标从命令行传递属性 - MSBuild target with MSBuild task pass in properties from command line 如何使用命令行构建 Visual Studio 安装项目? - How to build Visual studio Setup project using command-line? 如何通过命令行devenv.exe / msbuild.exe“立即发布”? - How to “publish now” via command line devenv.exe / msbuild.exe?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM