WiX 错误构建目标

WiX error build target

我正在尝试使用 WiX 和 MSBuild 命令创建我的 MSI 设置,这些命令将我的 img.png 部署到一个目录中,但我遇到了这个错误:

"MSB4019: project imported "C:\Program Files\MSBuild\Microsoft\WiX\v[[Version.M ajor]].x\Wix.targets" was not found. " Make sure that path of declaration are correct

这一行:

<Import Project="$(WixTargetPath)" />

这是我的 2 个文件(test.wixproj 和 test.wxs):

test.wixproj

<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
        <PropertyGroup>
                <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
                <Platform Condition=" '$(Platform)' == '' ">x86</Platform>
                <ProductVersion>3.0</ProductVersion>
                <ProjectGuid>{}</ProjectGuid>
                <SchemaVersion>2.0</SchemaVersion>
                <OutputName>WixProject1</OutputName>
                <OutputType>Package</OutputType>
                <WixTargetsPath Condition=" '$(WixTargetsPath)' == '' ">$(MSBuildExtensionsPath)\Microsoft\WiX\v[[Version.Major]].x\Wix.targets</WixTargetsPath>
        </PropertyGroup>
        <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x86' ">
                <OutputPath>bin$(Configuration)\</OutputPath>
                <IntermediateOutputPath>obj$(Configuration)\</IntermediateOutputPath>
                <DefineConstants>Debug</DefineConstants>
        </PropertyGroup>
        <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|x86' ">
                <OutputPath>bin$(Configuration)\</OutputPath>
                <IntermediateOutputPath>obj$(Configuration)\</IntermediateOutputPath>
        </PropertyGroup>
        <ItemGroup>
                <Compile Include="C:\testW2.wxs" />
        </ItemGroup>
        <Import Project="$(WixTargetsPath)" />
    </Project>

test.wxs

<?xml version="1.0" encoding="UTF-8"?>
<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi">
    <Product Id="*" UpgradeCode="" Version="1.0.0.0" Language="1033" Name="My Application Name" Manufacturer="My Manufacturer Name">
        <Package InstallerVersion="300" Compressed="yes"/>
        <Media Id="1" Cabinet="myapplication.cab" EmbedCab="yes" />


        <Directory Id="TARGETDIR" Name="SourceDir">
            <Directory Id="ProgramFilesFolder">
                <Directory Id="APPLICATIONROOTDIRECTORY" Name="Application test"/>
            </Directory>
        </Directory>


        <DirectoryRef Id="APPLICATIONROOTDIRECTORY">
            <Component Id="myimg" Guid="">
                <File Id="myimg" Source="C:\img.png" KeyPath="yes" Checksum="yes"/>
            </Component>

        </DirectoryRef>


        <Feature Id="MainApplication" Title="Main Application" Level="1">
            <ComponentRef Id="myimg" />
        </Feature>
    </Product>
</Wix>

我不明白问题出在哪里,而且我找不到没有 VisualStudio 的关于 WiX 的简单教程。

你能帮帮我吗?

您的项目文件有两个问题:

  1. <WixTargetPath ...> 行 [[MajorVersion]] 应替换为“3”,
  2. <Compile...> 行应该引用正确的文件 'Test.wxs'。

试试这个项目文件:

<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
    <PropertyGroup>
            <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
            <Platform Condition=" '$(Platform)' == '' ">x86</Platform>
            <ProductVersion>3.0</ProductVersion>
            <ProjectGuid>{}</ProjectGuid>
            <SchemaVersion>2.0</SchemaVersion>
            <OutputName>WixProject1</OutputName>
            <OutputType>Package</OutputType>
            <WixTargetsPath Condition=" '$(WixTargetsPath)' == '' ">$(MSBuildExtensionsPath)\Microsoft\WiX\v3.x\Wix.targets</WixTargetsPath>
    </PropertyGroup>
    <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x86' ">
            <OutputPath>bin$(Configuration)\</OutputPath>
            <IntermediateOutputPath>obj$(Configuration)\</IntermediateOutputPath>
            <DefineConstants>Debug</DefineConstants>
    </PropertyGroup>
    <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|x86' ">
            <OutputPath>bin$(Configuration)\</OutputPath>
            <IntermediateOutputPath>obj$(Configuration)\</IntermediateOutputPath>
    </PropertyGroup>
    <ItemGroup>
            <Compile Include="test.wxs" />
    </ItemGroup>
    <Import Project="$(WixTargetsPath)" />
</Project>

您还需要确保 test.wxsUpgradeCode 属性中有一个 GUID。