我正在运行mstest,并在app.config
中设置必要的localdb路径,如下所示:
<add name="DATABASE"
connectionString="Data Source=(LocalDB)\v11.0;AttachDbFilename=C:\mcs\Mcs.App\Mcs.ControlMaster.UT\bin\Debug\MCS_DB.mdf;Integrated Security=True"/>
我想在配置文件中使用相关路径。所以我将字符串更改为
<add name="DATABASE"
connectionString="Data Source=(LocalDB)\v11.0;AttachDbFilename=|DataDirectory|MCS_DB.mdf;Integrated Security=True"/>
但是DataDirectory
将是C:\PROGRAM FILES (X86)\MICROSOFT VISUAL STUDIO\2017\ENTERPRISE\COMMON7\IDE\EXTENSIONS\TESTPLATFORM\
即使我设置了DataDirectory
:
[AssemblyInitialize]
public static void Init(TestContext testContext)
{
AppDomain.CurrentDomain.SetData("DataDirectory", System.IO.Directory.GetCurrentDirectory());
}
结果仍然相同。如何在配置文件中设置localdb连接字符串?