Skip to main content
 首页 » 编程设计

c#之创建骨架 WiX 扩展时失败

2024年02月20日21sharpest

我刚开始使用 WiX,对 C#/.NET 的了解为零

现在我正在尝试通过引用此页面创建一个简单的 WiX 扩展:WiX3 - Simple Example of Extension .

这是该页面中描述的步骤:

  • 在 Visual Studio 中,创建一个名为 SampleWixExtension 的新 C# 库 (.dll) 项目。

  • 将对 wix.dll 的引用添加到您的项目。

  • 添加引用 Microsoft.Tools.WindowsInstallerXml 命名空间的 using 语句。

    使用 Microsoft.Tools.WindowsInstallerXml;

  • 让您的 SampleWixExtension 类继承自 WixExtension。

    公共(public)类 SampleWixExtension : WixExtension {}

  • 将 AssemblyDefaultWixExtensionAttribute 添加到您的 AssemblyInfo.cs。

    [程序集:AssemblyDefaultWixExtension(typeof(SampleWixExtension.SampleWixExtension))]

  • 构建项目。

但是,当我完成这些步骤并构建这个项目时,我遇到了以下错误:

    ------ Build started: Project: SampleWixExtension, Configuration: Debug Any CPU ------ 
    D:\working\test\SampleWixExtension\SampleWixExtension\Properties\AssemblyInfo.cs(37,12): error CS0246: The type or namespace name 'AssemblyDefaultWixExtension' could not be found (are you missing a using directive or an assembly reference?) 
    D:\working\test\SampleWixExtension\SampleWixExtension\Properties\AssemblyInfo.cs(37,12): error CS0246: The type or namespace name 'AssemblyDefaultWixExtensionAttribute' could not be found (are you missing a using directive or an assembly reference?) 
 
    Compile complete -- 2 errors, 0 warnings 

有人知道为什么以及如何解决它吗?

顺便说一句,在解决方案资源管理器中,我可以看到 wix 已经在 References 中,其属性的路径为 C:\Program Files (x86)\Windows Installer XML v3.5\bin\wix.dll

请您参考如下方法:

通过添加

using Microsoft.Tools.WindowsInstallerXml; 

进入AssemblyInfo.cs,项目现已成功构建。