通过 WIX 安装程序安装带有 CLI 项目 EXE 的 C# 不起作用
C# with CLI project EXE installed through WIX installer doesnt work
我有一个通过DLL调用C++ CLI的C#项目。它将一个字符串返回到 C#,该字符串显示在按钮事件的文本框中。我通过在 C# 项目属性中添加此 dll(名为 MyDll.dll)作为引用来添加它。我正在尝试使用 wix 工具集创建安装程序。这是源代码。
C# 代码
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using MyDll;
namespace MyProject
{
public partial class Form1 : Form
{
public Class1 obj = new Class1();
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
string str = "";
string str_new = obj.MyFunc(str);
textBox1.Text = str_new;
}
}
}
C++ 命令行代码
#include "stdafx.h"
#include "MyDll.h"
namespace MyDll
{
Class1::Class1(){}
Class1::~Class1(){}
Class1::!Class1(){}
String^ Class1::MyFunc([Out] String^ str)
{
str = "My C++/Cli DLL";
return outVal = str;
}
}
C++ CLI 标头
// MyDll.h
#pragma once
using namespace System;
using namespace System::Runtime::InteropServices;
namespace MyDll {
public ref class Class1
{
// TODO: Add your methods for this class here.
public:
Class1::Class1();
Class1::~Class1();
Class1::!Class1();
String^ MyFunc([Out] String^ str);
String^ outVal;
};
}
我的 WXS 文件
<?xml version="1.0" encoding="UTF-8"?>
<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi">
<Product Id="*" Name="installer_test" Language="1033" Version="1.0.0.0" Manufacturer="Company" UpgradeCode="a928c48a-8e5b-4038-b871-939ff8a9349f">
<Package InstallerVersion="200" Compressed="yes" InstallScope="perMachine" />
<MajorUpgrade DowngradeErrorMessage="A newer version of [ProductName] is already installed." />
<MediaTemplate />
<Feature Id="ProductFeature" Title="installer_test" Level="1">
<ComponentGroupRef Id="ProductComponents" />
</Feature>
</Product>
<Fragment>
<Property Id="ROOTDRIVE">
<![CDATA[E:]]>
</Property>
<Directory Id="TARGETDIR" Name="SourceDir">
<Directory Id="ProgramFiles" Name="ProgramFiles">
<Directory Id="TopFolder" Name="EXE3">
<Directory Id="INSTALLFOLDER" Name="Main folder">
<Component Id="cmpMain" Guid="{0509AAED-64A8-43F6-8935-70FB12305189}" KeyPath="yes" Feature="ProductFeature">
<File Source="$(var.MyProject.TargetPath)" />
<File Source="$(var.MyProject.TargetPath)" Name="MyDll.dll" ShortName="AF" />
</Component>
</Directory>
</Directory>
</Directory>
</Directory>
<Property Id="WIXUI_INSTALLDIR" Value="INSTALLFOLDER"></Property>
<UIRef Id="WixUI_InstallDir"/>
</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"> -->
<!-- <File Source="$(var.MyProject.TargetPath)"/>-->
<!-- TODO: Insert files, registry keys, and other resources here. -->
<!-- </Component> -->
</ComponentGroup>
</Fragment>
</Wix>
我的安装程序工作正常。它在指定的路径上安装一个exe和一个dll(MyDll.dll)。但是当我运行 exe 时,它什么也没做。如果我将已安装的 exe 替换为在我的 C# 项目的 bin 文件夹中创建的 exe,那么它可以正常工作。如何解决此问题?
谢谢
错误在于这 2 行:
<File Source="$(var.MyProject.TargetPath)" />
<File Source="$(var.MyProject.TargetPath)" Name="MyDll.dll" ShortName="AF" />
如果$(var.MyProject.TargetPath)
是你的exe文件,那么你要安装它两次,第二次只是命名为MyDll.dll。没有安装原始 dll。
让它像
<File Source="$(var.MyProject.TargetPathExe)" />
<File Source="$(var.MyProject.TargetPathDll)" />
其中变量包含源 exe 和 dll 文件的路径。
相关文章:
- 在Ubuntu 16.04上安装Cilk时出现问题
- 为cl.exe(Visual Studio代码)指定命令行C++版本
- 在CMakeLists.txt的安装功能中使用.cmake文件有什么用
- 如何在 windowsservercore Docker 映像上安装执行本机C++ DLL/EXE 所需的所有依赖二进制
- 安装生成工具后找不到Visual Studio代码MSVC cl.exe
- 如何安装Visual C++组件"VCBuild.exe"?
- 检查日志文件以找出 vcredist.exe 安装失败的原因
- 分发原始 msvcp.dll 或安装vc_redist.exe
- 通过 WIX 安装程序安装带有 CLI 项目 EXE 的 C# 不起作用
- .CAB中的.EXE无法从Win7、IE8安装
- 如何确定在C#DotNet中创建安装程序exe的先决条件
- 如何列出/处理C++中安装在 Windows 计算机上的所有软件和相关.exe
- 我尝试运行我在 eclipse 中创建的 c++ 应用程序(它的.exe),它说"libgcc_s_dw2-1.dll丢失并尝试重新安装
- CD 上的.exe是否会在没有操作系统的计算机上安装
- 无法在Windows 10 collect2.exe上使用Python27 MingGW安装leven软件包错误
- 为我的游戏创建一个安装程序(.exe)
- 为什么安装vcredist_x86.exe不能修复 SideBySide 错误,当我在一台机器上开发 EXE 并在另一台机器上运行它时?
- 是否可以通过调用assemblyInstaller来安装用c++编写的windows服务(EXE)(使用CreateSe
- 我如何使exe可以在没有其他安装的windows上运行
- 安装MinGW的gdb.exe用于代码块