行。DeploymentItem 是解决此问题的一种方法。但是,DeploymentItem 有点脆弱。
这是我修复它的方法。
“当前目录”必须与 DeploymentItem 对齐。我发现的最佳折衷方案是将当前目录设置为 .sln 文件所在的位置。
这是我的文件夹结构。
C:\SomeRootFolder\
C:\SomeRootFolder\MySolution.sln
C:\SomeRootFolder\packages\
C:\SomeRootFolder\packages\MyNugetPackage.1.2.3.4\lib\net45\SomeThirdPartyDll.dll
C:\SomeRootFolder\MyTestProject\MyTestProject.csproj
C:\SomeRootFolder\MyTestProject\MyTestClass.cs
我的TestClass.cs
[TestClass]
public class MyTestClass
{
[TestMethod]
/* The DeploymentItem item below is for error ::: Warning: Test Run deployment issue: The assembly or module 'SomeDll' directly or indirectly referenced by the test container 'C:\SomeRootFolder\MyTestProject\bin\debug\MyTestProject.dll' was not found. */
/* There must be a CD (to the .sln folder) command... before the MsTest.exe command is executed */
[DeploymentItem(@".\packages\MyNugetPackage.1.2.3.4\lib\net45\SomeDll.dll")]
public void MyTest()
{
}
}
“诀窍”是对包含 .sln 的文件夹进行 CD(更改目录)。
REM Now the normal restore,build lines
nuget.exe restore "C:\SomeRootFolder\MySolution.sln"
REM the above nuget restore would create "C:\SomeRootFolder\packages\MyNugetPackage.1.2.3.4\lib\net45\SomeThirdPartyDll.dll"
MSBuild.exe "C:\SomeRootFolder\MySolution.sln" /p:Configuration=Debug;FavoriteFood=Popeyes /l:FileLogger,Microsoft.Build.Engine;logfile=MySolution.Debug.Build.log
REM (the below line is the trick to line up the 'current folder' with the relative path of the DeploymentItem)
cd "C:\SomeRootFolder\"
REM now the below will work without the annoying message, note that C:\SomeRootFolder\MyTestProject\bin\Debug\SomeThirdPartyDll.dll exists
MsTest.exe /testcontainer:"C:\SomeRootFolder\MyTestProject\bin\Debug\MyTestProject.dll" /resultsfile:MyTestProject.Dll.Results.trx
现在因为“当前目录”(CD 的结果)位于“C:\SomeRootFolder\”,所以 DeploymentItem 相对路径可以正常工作。
吉米蟋蟀.......这有点疯狂。
请注意,保罗泰勒在这里回答
使用自定义程序集基目录从命令行运行 MsTest
对我不起作用。