我正在将 scitersharp 与 WinForms 一起使用,并尝试构建一个独立的编译 c# 可执行文件。这是一个加载 HTML 文件的简单“Hello World”应用程序。最初编译后,bin\Debug 文件夹中生成了 3 个 DLL(sciter.dll、sciter64.dll 和 SciterSharpWindows.dll)。所以,我用谷歌搜索并试图找到将这些 dll 文件嵌入到可执行文件中的解决方案。这是我尝试过的:
在 Visual Studio 的项目窗口中加载 DLL 并将构建选项设置为“嵌入式资源”
添加对资源的引用,但此方法不起作用,它给了我以下错误:
`A reference to resource 'pathto\sciter.dll' could not be added. Please make sure the file is accesible and that it is a valid assembly or COM component`
安装 Cosutra.Fody 包并重建项目。这次我设法只嵌入了 SciterSharpWindows.dll
这是我的代码:
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 Sciter;
using SciterSharp;
using SciterSharp.WinForms;
namespace WindowsFormsApp1
{
public partial class Form1 : Form
{
// Create a class-accesible sciter control
private SciterControl SciterElement;
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
// Create a new instance of the sciter control
SciterElement = new SciterControl();
// Set the callback once the element is ready to be used
SciterElement.HandleCreated += SciterControl1_HandleCreated;
// Add the Sciter Control to the Form and fill it
this.Controls.Add(SciterElement);
SciterElement.Dock = DockStyle.Fill;
}
private void SciterControl1_HandleCreated(object sender, EventArgs e)
{
// Initialize with some HTML
SciterElement.SciterWnd.LoadHtml(@"
<div style='padding: 0px 8px;'>
<h1>
Hello World
</h1>
</div>
");
}
}
}
有没有办法将这些资源嵌入到可执行文件中?另外,如果我遗漏了什么,请告诉我?先感谢您。