gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-30 14:31:16 26 4
gpt4 key购买 nike

我在单独的类库项目中有电子邮件模板(和电子邮件发送器)。我正在获取 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/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com