Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/wix/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Msbuild 如何将命令行属性传递给setup.exe_Msbuild_Wix - Fatal编程技术网

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

Msbuild 如何将命令行属性传递给setup.exe,msbuild,wix,Msbuild,Wix,我想在调用setup.exe时将参数传递给msi,如下所示: setup.exe /l* log.txt EXEPATH="C:\Program Files (x86)\MySetup\MyApplication.exe" 我有以下msbuild文件: <Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> <PropertyGroup&g

我想在调用setup.exe时将参数传递给msi,如下所示:

setup.exe /l* log.txt EXEPATH="C:\Program Files (x86)\MySetup\MyApplication.exe"
我有以下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>
问题是,当我使用以下命令启动setup.exe时

setup.exe /l* log.txt EXEPATH="C:\Program Files (x86)\MySetup\MyApplication.exe"
EXEPATH参数似乎没有被使用,或者我不知道为什么


有什么建议吗?

我通过将EXEPATH传递给MSI文件和一个将计算EXEDIR和EXEFILNAME的自定义操作来解决这个问题

以下是自定义操作:

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;
        }
    }
}
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>

以及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>

Windows Installer 4.5

我在你的帖子中没有看到任何问题。试着复习和编辑,因为如果我不知道你在说什么,我就无法回答。亲爱的@jdlugosz我已经编辑了我的帖子。请检查一下。
<?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>
<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>