我一直在寻找,但我还没有找到解决这个问题的方法:我想创建一个类库,它在名为Configuration的子目录下有一个配置文件。我希望将该类库部署到任何地方,我希望它通过了解自己的位置来查找其配置文件。
以前使用Assembly.GetExecutingAssembly().Location
的尝试都不起作用。
它会返回临时位置,例如
C:\Windows\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files\root\7c00e0a3\38789d63\assembly\dl3\9c0a23ff\18fb5feb_6ac3c901
而不是期望的
bin/Configuration
路径。
所以:
这应该工作 -
string assemblyFile = (
new System.Uri(Assembly.GetExecutingAssembly().CodeBase)
).AbsolutePath;