获取.NET考虑特定网络共享进行完全信任 [英] Get .NET to consider a specific network share to be fully trusted

查看:187
本文介绍了获取.NET考虑特定网络共享进行完全信任的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

安装我有(只),Visual Studio 2010中。我试图运行构建系统的命令行我的单元测试。我所有的开发工作是在该联系人的共享了使用Samba Linux服务器上我的主目录。当我试图运行NUnit的,我得到一个错误这样的:

I have (only) Visual Studio 2010 installed. I'm trying to run my unit tests from a command-line build-system. All my development work is in my home directory on a Linux server that's shared out using Samba. When I try to run NUnit I get an error like this:

Unhandled Exception: System.TypeInitializationException: The type initializer for 'NUnit.ConsoleRunner.Runner' threw an exception. ---> System.Security.Security
Exception: That assembly does not allow partially trusted callers.
   at NUnit.ConsoleRunner.Runner..cctor()
The action that failed was:
LinkDemand
The assembly or AppDomain that failed was:
nunit-console-runner, Version=2.5.9.10305, Culture=neutral, PublicKeyToken=96d09a1eb7f44a77
The method that caused the failure was:
NUnit.Core.Logger GetLogger(System.Type)
The Zone of the assembly that failed was:
Intranet
The Url of the assembly that failed was:
file:///Z:/gitrepos/smarties/dependencies/Windows-x86/NUnit-2.5.9.10305/bin/net-2.0/lib/nunit-console-runner.DLL
   --- End of inner exception stack trace ---
   at NUnit.ConsoleRunner.Runner.Main(String[] args)
   at NUnit.ConsoleRunner.Class1.Main(String[] args)

我使用的Caspol.exe曾尝试如下所述:编辑和运行网络共享.NET项目

>caspol -addgroup 1.2 -url file:///Z:/* FullTrust -name MyZShare
Microsoft (R) .NET Framework CasPol 4.0.30319.1
Copyright (c) Microsoft Corporation.  All rights reserved.

WARNING: The .NET Framework does not apply CAS policy by default. Any settings shown or modified by CasPol will only affect applications that opt into using
CAS policy.

Please see http://go.microsoft.com/fwlink/?LinkId=131738 for more information.


The operation you are performing will alter security policy.
Are you sure you want to perform this operation? (yes/no)
yes
Added union code group with "-url" membership condition to the Machine level.
Success

它没有明显的效果。

It has no obvious effect.

其它指令告诉我找到管理工具在控制面板中的某些Microsoft .NET安全策略工具,但我没有这样的工具。 (这是因为我只有Visual Studio 2010中,没有早期版本的?我运行的是Windows 7专业版64位,如果它的确与众不同。)

Other instructions tell me to find some Microsoft .NET Security Policy tool in Administrative Tools in the Control Panel, but I have no such tool available. (Is this because I only have Visual Studio 2010, not earlier versions? I'm running Windows 7 Pro 64-bit, if it makes a difference.)

我真的只是想.NET相信,这个目录是我自己的机器,而不是内联网的一部分。我不希望任何这code从网络共享部署时,只是作为发展的一部分来运行。我也不想盲目地相信所有的网络股,但即使这将是一个更可口的解决方法不是每次我想运行测试将所有内容复制到本地驱动器。

I really just want .NET to believe that this directory is on my own machine and not part of the intranet. I don't want any of this code to run from a network share when deployed, only as part of development. I also don't want to blindly trust all network shares, although even that would be a more palatable workaround than copying everything onto a local drive every time I want to run a test.

我宁可不要这一点在发展签署一切与强名称。 (我甚至不知道是否会有所帮助,因为NUnit的显然是失败之前它甚至加载我的程序集。)

I would rather not have to sign everything with strong names at this point in development. (And I'm not even sure if it would help, since NUnit is apparently failing before it has even loaded my assembly.)

编辑 - 最终事实证明,我试图解决错误的问题。虽然搞清楚如何让NUnit的为无子进程运行.NET 4.0的测试中,我发现这一点:

EDIT - In the end it turned out I was trying to solve the wrong problem. While figuring out how to get NUnit to run .NET 4.0 tests without a subprocess, I found this:

http://frater.word$p$pss.com/2010/05/04/debugging-nunit-tests-under-visual-studio-2010/

它说:

根据此页面你也应该在加入这一行运行时的元素[在NUnit的-console.exe.config]:

According to this page you should also add this line under the runtime element [in nunit-console.exe.config]:

<启用=真/&GT loadFromRemoteSources;

这使得从远程站点下载库(如网站)加载完全信任。我不知道为什么,这是必要的,事实上,我的应用程序调试NUnit的就好了,没有它。但是,如果你有问题,你可能想尝试一下。

This allows libraries downloaded from a remote site (such as a website) to be loaded with full trust. I’m not sure why this would be necessary and indeed, my application debugged NUnit just fine without it. However, if you have problems, you might want to give it a try.

这固定我的问题,我无需渣土约与caspol。

This fixed my problem for me without having to muck about with caspol.

推荐答案

这是因为在.NET 3.5及以下,位于网络共享的所有库都被视为部分信任。它可以解决此通过使用框架的版本来运行NUnit的。

This is because in .NET 3.5 and below, all libraries located on network shares are treated as partial trust. It is possible to work around this by using a later version of the framework to run NUnit.

NUnit的亚军针对v3.5版本的框架,presumably的传统支持。您可以检查此与corflags工具随Visual Studio的

The NUnit runners target the v3.5 framework, presumably for legacy support. You can check this with the corflags tool that comes with Visual Studio

> corflags nunit-console.exe
Version   : v2.0.50727

这意味着,如果你运行的NUnit-console.exe在命令行,你有.NET 3.5和安装了.NET 4中,3.5版运行时将用于运行可执行文件。你可以看到在控制台输出。

This means if you run nunit-console.exe from the from command line and you have .NET 3.5 and .NET 4 installed, the v3.5 runtime will be used to run the executable. You can see this in the console output.

> nunit-console.exe
CLR Version: 2.0.50727.7905 ( Net 3.5 )

的配置包含了 < loadFromRemoteSources启用=真/> 元素,这将导致.NET V4忽略的部分信任调用者的错误,但这种设置是在旧版本的忽视框架。

The config contains the <loadFromRemoteSources enabled="true"/> element, which causes .NET v4 to ignore the partially trusted caller error, but this setting is ignored in the older versions of the framework.

要强制应用程序在.NET 4运行或以上,添加以下行启动应用程序配置文件的部分。

To force the application to run under .NET 4 or above, add the following line to the startup section of the application config file.

<supportedRuntime version="v4.0"/>

在我的情况,我不得不增加一个步骤,构建服务器自动化持续集成环境中运行测试之前,使这个配置的变化。

In my case, I had to add a step to the build server automation to make this config change before running the tests in a continuous integration environment.

desc 'run unit tests'
task :tests => :compile do
  runner_dir = FileList["packages/NUnit.Runners*/tools"].first
  runner_config = File.join(runner_dir, "nunit-console.exe.config")

  # running the tests from a network share fails due to code access policy if the 
  # runner is on framework v3.5 or lower. force the runner to use v4.0 or above 
  comment = %<!-- Comment out the next line to force use of .NET 4.0 -->
  runtime_version = %<supportedRuntime version="v4.0.30319"/>
  File.write(runner_config, File.read(runner_config).sub(comment, runtime_version))

  nunit! :actually_run_tests do |nunit|
    nunit.command = File.join(runner_dir, "nunit-console.exe")
    nunit.assemblies = FileList["out/**/*.Tests.dll"]
    nunit.log_level = :verbose
  end
end

这篇关于获取.NET考虑特定网络共享进行完全信任的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆