MSTest 找不到程序集

发布于 2024-10-29 02:39:58 字数 498 浏览 7 评论 0原文

我正在使用 MSTest

并使用命令 mstest /testsettings:local.Testsetting /testcontainer:folder\obj\Debug\test.dll

这是输出,

运行存在以下问题: 警告:测试运行部署问题: 组件或模块 '微软.实践。直接棱镜 或由测试间接引用 找不到容器“test.dll”。 警告:测试运行部署问题: 组件或模块 直接“Project.Common.dll”或 测试间接引用 找不到容器“test.dll”。 警告:测试运行部署问题: 组件或模块 直接“Project.Infrastruct.dll” 或由测试间接引用 找不到容器“test.dll”。 警告:测试运行部署问题: 组件或模块 '微软.实践。直接棱镜 或由测试间接引用 找不到容器“test.dll”。

我该怎么做才能让 MSTest 运行良好。

I was using MSTest

and i use command mstest /testsettings:local.Testsetting /testcontainer:folder\obj\Debug\test.dll

and this is the output,

Run has the following issue(s):
Warning: Test Run deployment issue:
The assembly or module
'Microsoft.Practices. Prism' directly
or indirectly referenced by the test
container 'test.dll' was not found.
Warning: Test Run deployment issue:
The assembly or module
'Project.Common.dll' directly or
indirectly referenced by the test
container 'test.dll' was not found.
Warning: Test Run deployment issue:
The assembly or module
'Project.Infrastructure.dll' directly
or indirectly referenced by the test
container 'test.dll' was not found.
Warning: Test Run deployment issue:
The assembly or module
'Microsoft.Practices. Prism' directly
or indirectly referenced by the test
container 'test.dll' was not found.

What can i do so MSTest can run well.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

北笙凉宸 2024-11-05 02:39:58

您可以将 Prism 文件安装在构建服务器的 GAC 中。

You can install the Prism file in the GAC of your build server.

能怎样 2024-11-05 02:39:58

所有未直接在测试中使用的程序集都不会复制到测试文件夹中。因此,这些测试方法应该用如下属性修饰:

[DeploymentItem("Microsoft.Practices.Prism.dll")]

这可以解决问题,而无需将程序集添加到 GAC。

All assemblies that are not used directly in test will not be copied to test folder. Therefor, those test methods should be decorated with attribute like:

[DeploymentItem("Microsoft.Practices.Prism.dll")]

This solves the problem without adding the assembly to the GAC.

各自安好 2024-11-05 02:39:58

好的。 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

MyTestClass.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()
    {
    }
}

“技巧”是制作 CD(更改目录)到包含 .sln 的文件夹。

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 相对路径可以正常工作。

吉米尼蟋蟀……这有点疯狂。

请注意,Paul Taylor 在这里回答

正在运行使用自定义程序集基目录的命令行的 MsTest

对我不起作用。

Ok. The DeploymentItem is a way to fix this. However, DeploymentItem is a little fragile.

Here is how I fixed it.

The "current directory" has to line up with the DeploymentItem. The best compromise I found would be to set the current directory to where the .sln file is.

Here is my folder structure.

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

MyTestClass.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()
    {
    }
}

The "trick" is to do a CD (change directory) to the folder that houses the .sln.

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

Now because the "current directory" (the result of the CD) is at "C:\SomeRootFolder\", the DeploymentItem relative path works correctly.

Jimminy Crickets.......that is a little nutsy.

Note, the Paul Taylor answer here

Running MsTest from the command line with a custom assembly base directory

did not work for me.

疾风者 2024-11-05 02:39:58

最简单的方法。
只需添加

 string value = AppDomain.CurrentDomain.BaseDirectory;

到您的代码(在测试方法的起点)
在新添加的代码中添加断点,查看value变量的路径是什么。

继续测试过程,一切成功后导航到 values 变量的文件夹。

您可能会看到该文件夹​​内的所有 dll。
只需复制它们和过去的软件,然后使用 mstest 命令行工具执行项目 dll 即可。

set mstestPath="C:\Program Files (x86)\Microsoft Visual Studio 11.0\Common7\IDE"

%mstestpath%\mstest /testcontainer:CodedUITestProject1.dll

easiest way.
Just add

 string value = AppDomain.CurrentDomain.BaseDirectory;

to your code (at the start point of your test method)
Add a breakpoint to the newly added code and check what is the path of value variable.

continue the test process and after everything get success navigate to the folder of values variable.

You might see all the dlls inside the folder.
Just copy them and past ware ever you want and execute the project dll using mstest command line tool.

set mstestPath="C:\Program Files (x86)\Microsoft Visual Studio 11.0\Common7\IDE"

%mstestpath%\mstest /testcontainer:CodedUITestProject1.dll
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文