halcom中国吧 关注:11贴子:147
  • 0回复贴,共1

C# 如何 存储DLL的路径信息,并在应用程序启动时读取这些信息来

只看楼主收藏回复

方法1: 使用App.config或Web.config文件
你可以在App.config(对于控制台应用或Windows桌面应用)或Web.config(对于Web应用)文件中存储DLL的路径信息。这些文件是XML格式的,可以存储应用程序的配置信息。
App.config示例:
xml复制代码
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<appSettings>
<add key="MyDllPath" value="C:\Path\To\Your\Dll\MyDll.dll" />
</appSettings>
</configuration>
在代码中读取配置:
csharp复制代码
using System;
using System.Configuration;
class Program
{
static void Main()
{
// 从App.config读取DLL路径
string dllPath = ConfigurationManager.AppSettings["MyDllPath"];
// 动态加载DLL...
}
}


IP属地:广东1楼2024-03-31 12:20回复