c# - AppDomain.CurrentDomain.RelativeSearchPath 在单元测试中为空

标签 c# unit-testing relative-path

我在单独的类库项目中有电子邮件模板(和电子邮件发送器)。我正在获取 View 路径(复制到输出目录 = true),如下所示:

var basePath = AppDomain.CurrentDomain.RelativeSearchPath;
var path = Path.Combine(basePath, "Views", viewname + ".cshtml");

当我尝试在单元测试项目中运行此代码时,basePath 为空。但它不应该为空!

谁能解释一下-

  1. 为什么 basepath 为空?
  2. 如何解决?

最佳答案

根据 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/

相关文章:

php - 无法在 laravel 的 Controller 中使用数据库事务(DB::beginTransaction)

c# - SQLite 作为 SQL Server 的内存数据库

c - Unity 框架单元测试对 "setUp"和 "tearDown"的 undefined reference

unix - crontab - 在目录中运行

php - PHP 中来自另一个目录的 zip 文件,没有路径结构

c# - Func<MyType> 隐式转换为 MyType

c# - 我如何使用反射处理数组

c# - angularjs传递数据有列表数据

c# - 字段初始化后无法从主线程访问对象

python - 在python项目中使用相对路径读取文件