MSTest运行失败,因为源程序集不受信任

时间:2021-05-17 03:10:28

I just added xUnit to our test project (for the Asserts, we're still using MSTest as the framework) and immediately the test runs refused to execute any of the tests. This is the error message:

我刚刚将xUnit添加到我们的测试项目中(对于Asserts,我们仍然使用MSTest作为框架)并且测试运行立即拒绝执行任何测试。这是错误消息:

Failed to queue test run '{ .... }' Test run deployment issue: The location of the file or directory '...xUnit.dll' is not trusted.

无法排队测试运行'{....}'测试运行部署问题:文件或目录'... xUnit.dll'的位置不受信任。

10 个解决方案

#1


98  

It took me a few tries to find the answer in Google, so I'm putting it here in case anyone else runs into the same problem. A detailed description can be found at this blog posting.

我花了几次尝试在谷歌找到答案,所以我把它放在这里以防万一其他人遇到同样的问题。可以在此博客文章中找到详细说明。

Basically, the fix invovles right-clicking on the dll file (xunit.dll for example) in Windows Explorer, going to Properties, and clicking "Unblock" at the bottom of the tab next to the 'Security' text. It seems that Vista / Windows 2008 will automatically mark assemblies that come from other machines or the internet as unsafe.

基本上,修复程序会在Windows资源管理器中右键单击dll文件(例如xunit.dll),转到“属性”,然后单击“安全”文本旁边选项卡底部的“取消阻止”。似乎Vista / Windows 2008会自动将来自其他机器或互联网的程序集标记为不安全。

As a couple commenters have mentioned, you may also need to restart Visual Studio for this to take effect.

正如一些评论者所提到的,您可能还需要重新启动Visual Studio才能使其生效。

#2


17  

In my team we had the same problem.

在我的团队中,我们遇到了同样的问题。

Your solution didn't work, but this post by Charles Sterling did help.

你的解决方案不起作用,但Charles Sterling的这篇文章确实有所帮助。

We used the following line:

我们使用以下行:

caspol -machine -addgroup 1 -url file://\\server/share/* FullTrust -name DevShare

#3


10  

After having this issue and burning hours trying to get "Unblock" to stick longer than a few minutes and/or figuring out caspol to no avail, I finally found a little tidbit via Google that the assemblies will be blocked again the next time you build or rebuild the project, since they're re-copied from their original source location. (I guess I never noticed that this happened before with references assemblies, but anyway...)

在遇到这个问题并且燃烧时间试图让“解锁”持续时间超过几分钟和/或搞清楚caspol无济于事之后,我终于通过谷歌发现了一些小故事,下次你建立时会再次阻止程序集或者重建项目,因为它们是从原始源位置重新复制的。 (我想我从来没有注意到这发生在引用程序集之前,但无论如何......)

My fix for this was the following:

我对此的解决方法如下:

  1. Copy all the needed DLLs to another spot for safe-keeping

    将所有需要的DLL复制到另一个位置以便安全保存

  2. Remove the references in Visual Studio

    删除Visual Studio中的引用

  3. Physically delete the DLLs in the bin folder

    物理删除bin文件夹中的DLL

  4. Unblock the DLLs individually in the spot where they were copied off

    在复制它们的位置单独解锁DLL

  5. Add the references back in Visual Studio from the holding spot

    从保留点在Visual Studio中添加引用

Every subsequent build or rebuild worked fine afterward.

之后的每个后续构建或重建都运行良好。

#4


8  

Running on an XP machine (even with .NET 3.5 SP1 installed) I was not able to get any of the other solutions listed here to work.

在XP机器上运行(即使安装了.NET 3.5 SP1)我也无法获得此处列出的任何其他解决方案。

However working from the same post by Charles Sterling that Davy Landman references, I finally succeeded with this variation:

然而,在戴维·兰德曼引用的查尔斯·斯特林的同一篇文章中,我终于成功了这个变化:

  1. Run the .NET 2.0 Configuration tool (Settings... Control Panel... Administrative Tools... .NET Framework 2.0 Configuration)
  2. 运行.NET 2.0配置工具(设置...控制面板...管理工具... .NET Framework 2.0配置)

  3. Click down to "My Computer ... Runtime Security Policy ... Machine ... Code Groups ... All_Code"
  4. 单击“我的电脑...运行时安全策略...机器......代码组... All_Code”

  5. Create a new code group with membership condition of "Zone"="Local Intranet" and assign the permission set "FullTrust"
  6. 创建一个成员条件为“Zone”=“Local Intranet”的新代码组,并分配权限集“FullTrust”

  7. Restart Visual Studio
  8. 重新启动Visual Studio

After these steps I am able to run tests, including after restarts and rebuilds.

完成这些步骤后,我可以运行测试,包括重启和重建后。

EDIT: as described in this answer, you may need to install the .NET SDK (which is different from the .NET framework) in order to have the .NET 2.0 Configuration tool on your system.

编辑:如本回答所述,您可能需要安装.NET SDK(与.NET框架不同)才能在您的系统上安装.NET 2.0配置工具。

#5


4  

I had the same problem with moq. But would not 'unblock'. Every time I unblocked it, it was still blocked!?!?

我和moq有同样的问题。但不会“解锁”。每次我解锁它,它仍然被阻止!?!?

I had to unblock the original zip file I downloaded. Then copy the DLL from the zip file again. It work after that.

我不得不解锁我下载的原始zip文件。然后再次从zip文件中复制DLL。它之后工作。

#6


3  

It may seem really obvious now, but when I was clicking unblock the file was set as read-only.

现在看起来很明显,但是当我点击取消阻止时,文件被设置为只读。

Only after un-checking that attribute, applying, then selecting unblock did I actually get this working.

只有在取消检查该属性,应用,然后选择取消阻止后,我才能真正实现这一点。

Give that a go.

放手一搏。

:)

PS: I also deleted all the old dll's in my bin folder, just to make sure Visual Studio wasn't picking up the old one.

PS:我还删除了我的bin文件夹中的所有旧dll,只是为了确保Visual Studio没有拿起旧的。

#7


1  

I had the same problem with downloaded DLLs blocked by Vista. You need Administrator rights to get the "Unblock" button on the file's Properties. I simply replaced the DLLs with the latest version from source control (TFS) where I had committed them before.

我遇到了与Vista阻止的下载DLL相同的问题。您需要管理员权限才能获取文件属性上的“取消阻止”按钮。我只是用源代码控制(TFS)中的最新版本替换了DLL,之前我已经提交了它们。

#8


1  

  • Go to file
  • 转到文件

  • Right click and select Properties
  • 右键单击并选择“属性”

  • On the first Register click on Allow
  • 在第一个注册表上单击“允许”

#9


0  

I also tried opening the file in notepad++ and renaming it. Slightly different approach, but it worked for me. The local file system then think it comes from the same machine.

我也尝试在notepad ++中打开文件并重命名。略有不同的方法,但它对我有用。然后本地文件系统认为它来自同一台机器。

#10


0  

It's not just the moq.dll that needs to be unblocked. The latest zip file includes an moq.xml and moq.pdb file - referencing the dll copies these other two files to the bin folders as well. If all three have not been unblocked the tests won't run, I found.

这不仅仅是需要解除阻止的moq.dll。最新的zip文件包含moq.xml和moq.pdb文件 - 引用dll也会将这两个其他文件复制到bin文件夹中。如果所有这三个都没有被解锁,测试将无法运行,我发现。

#1


98  

It took me a few tries to find the answer in Google, so I'm putting it here in case anyone else runs into the same problem. A detailed description can be found at this blog posting.

我花了几次尝试在谷歌找到答案,所以我把它放在这里以防万一其他人遇到同样的问题。可以在此博客文章中找到详细说明。

Basically, the fix invovles right-clicking on the dll file (xunit.dll for example) in Windows Explorer, going to Properties, and clicking "Unblock" at the bottom of the tab next to the 'Security' text. It seems that Vista / Windows 2008 will automatically mark assemblies that come from other machines or the internet as unsafe.

基本上,修复程序会在Windows资源管理器中右键单击dll文件(例如xunit.dll),转到“属性”,然后单击“安全”文本旁边选项卡底部的“取消阻止”。似乎Vista / Windows 2008会自动将来自其他机器或互联网的程序集标记为不安全。

As a couple commenters have mentioned, you may also need to restart Visual Studio for this to take effect.

正如一些评论者所提到的,您可能还需要重新启动Visual Studio才能使其生效。

#2


17  

In my team we had the same problem.

在我的团队中,我们遇到了同样的问题。

Your solution didn't work, but this post by Charles Sterling did help.

你的解决方案不起作用,但Charles Sterling的这篇文章确实有所帮助。

We used the following line:

我们使用以下行:

caspol -machine -addgroup 1 -url file://\\server/share/* FullTrust -name DevShare

#3


10  

After having this issue and burning hours trying to get "Unblock" to stick longer than a few minutes and/or figuring out caspol to no avail, I finally found a little tidbit via Google that the assemblies will be blocked again the next time you build or rebuild the project, since they're re-copied from their original source location. (I guess I never noticed that this happened before with references assemblies, but anyway...)

在遇到这个问题并且燃烧时间试图让“解锁”持续时间超过几分钟和/或搞清楚caspol无济于事之后,我终于通过谷歌发现了一些小故事,下次你建立时会再次阻止程序集或者重建项目,因为它们是从原始源位置重新复制的。 (我想我从来没有注意到这发生在引用程序集之前,但无论如何......)

My fix for this was the following:

我对此的解决方法如下:

  1. Copy all the needed DLLs to another spot for safe-keeping

    将所有需要的DLL复制到另一个位置以便安全保存

  2. Remove the references in Visual Studio

    删除Visual Studio中的引用

  3. Physically delete the DLLs in the bin folder

    物理删除bin文件夹中的DLL

  4. Unblock the DLLs individually in the spot where they were copied off

    在复制它们的位置单独解锁DLL

  5. Add the references back in Visual Studio from the holding spot

    从保留点在Visual Studio中添加引用

Every subsequent build or rebuild worked fine afterward.

之后的每个后续构建或重建都运行良好。

#4


8  

Running on an XP machine (even with .NET 3.5 SP1 installed) I was not able to get any of the other solutions listed here to work.

在XP机器上运行(即使安装了.NET 3.5 SP1)我也无法获得此处列出的任何其他解决方案。

However working from the same post by Charles Sterling that Davy Landman references, I finally succeeded with this variation:

然而,在戴维·兰德曼引用的查尔斯·斯特林的同一篇文章中,我终于成功了这个变化:

  1. Run the .NET 2.0 Configuration tool (Settings... Control Panel... Administrative Tools... .NET Framework 2.0 Configuration)
  2. 运行.NET 2.0配置工具(设置...控制面板...管理工具... .NET Framework 2.0配置)

  3. Click down to "My Computer ... Runtime Security Policy ... Machine ... Code Groups ... All_Code"
  4. 单击“我的电脑...运行时安全策略...机器......代码组... All_Code”

  5. Create a new code group with membership condition of "Zone"="Local Intranet" and assign the permission set "FullTrust"
  6. 创建一个成员条件为“Zone”=“Local Intranet”的新代码组,并分配权限集“FullTrust”

  7. Restart Visual Studio
  8. 重新启动Visual Studio

After these steps I am able to run tests, including after restarts and rebuilds.

完成这些步骤后,我可以运行测试,包括重启和重建后。

EDIT: as described in this answer, you may need to install the .NET SDK (which is different from the .NET framework) in order to have the .NET 2.0 Configuration tool on your system.

编辑:如本回答所述,您可能需要安装.NET SDK(与.NET框架不同)才能在您的系统上安装.NET 2.0配置工具。

#5


4  

I had the same problem with moq. But would not 'unblock'. Every time I unblocked it, it was still blocked!?!?

我和moq有同样的问题。但不会“解锁”。每次我解锁它,它仍然被阻止!?!?

I had to unblock the original zip file I downloaded. Then copy the DLL from the zip file again. It work after that.

我不得不解锁我下载的原始zip文件。然后再次从zip文件中复制DLL。它之后工作。

#6


3  

It may seem really obvious now, but when I was clicking unblock the file was set as read-only.

现在看起来很明显,但是当我点击取消阻止时,文件被设置为只读。

Only after un-checking that attribute, applying, then selecting unblock did I actually get this working.

只有在取消检查该属性,应用,然后选择取消阻止后,我才能真正实现这一点。

Give that a go.

放手一搏。

:)

PS: I also deleted all the old dll's in my bin folder, just to make sure Visual Studio wasn't picking up the old one.

PS:我还删除了我的bin文件夹中的所有旧dll,只是为了确保Visual Studio没有拿起旧的。

#7


1  

I had the same problem with downloaded DLLs blocked by Vista. You need Administrator rights to get the "Unblock" button on the file's Properties. I simply replaced the DLLs with the latest version from source control (TFS) where I had committed them before.

我遇到了与Vista阻止的下载DLL相同的问题。您需要管理员权限才能获取文件属性上的“取消阻止”按钮。我只是用源代码控制(TFS)中的最新版本替换了DLL,之前我已经提交了它们。

#8


1  

  • Go to file
  • 转到文件

  • Right click and select Properties
  • 右键单击并选择“属性”

  • On the first Register click on Allow
  • 在第一个注册表上单击“允许”

#9


0  

I also tried opening the file in notepad++ and renaming it. Slightly different approach, but it worked for me. The local file system then think it comes from the same machine.

我也尝试在notepad ++中打开文件并重命名。略有不同的方法,但它对我有用。然后本地文件系统认为它来自同一台机器。

#10


0  

It's not just the moq.dll that needs to be unblocked. The latest zip file includes an moq.xml and moq.pdb file - referencing the dll copies these other two files to the bin folders as well. If all three have not been unblocked the tests won't run, I found.

这不仅仅是需要解除阻止的moq.dll。最新的zip文件包含moq.xml和moq.pdb文件 - 引用dll也会将这两个其他文件复制到bin文件夹中。如果所有这三个都没有被解锁,测试将无法运行,我发现。