我在单独的类库项目中有电子邮件模板(和电子邮件发送器)。我正在获取 View 路径(复制到输出目录 = true),如下所示:
var basePath = AppDomain.CurrentDomain.RelativeSearchPath;
var path = Path.Combine(basePath, "Views", viewname + ".cshtml");
当我尝试在单元测试项目中运行此代码时,basePath 为空。但它不应该为空!
谁能解释一下-
- 为什么 basepath 为空?
- 如何解决?
最佳答案
根据 MSDN :
Private assemblies are deployed in the same directory structure as the application. If the path specified by the RelativeSearchPath property is not under AppDomainSetup.ApplicationBase, it is ignored.
This property returns the value set using AppDomainSetup.PrivateBinPath.
你应该设置AppDomainSetup.PrivateBinPath首先。
关于c# - AppDomain.CurrentDomain.RelativeSearchPath 在单元测试中为空,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20772353/