当我使用命令行构建C#/ .NET时,如何设置配置?

时间:2011-06-24 14:49:20

标签: c# .net configuration exception-handling

当我的程序试图访问网络驱动器中的dll时,我收到此错误消息。

Unhandled Exception:
System.IO.FileLoadException: Could not load file or assembly 'file:///Z:\smcho\works\tasks\2011\ni\ng_fpgabackend\myclass.dll' or one of its dependencies. Operation is not supported. (Exception from HRESULT: 0x80131515)
---> System.NotSupportedException: An attempt was made to load an assembly from a network location which would have caused the assembly to be sandboxed in previous versions of the .NET Framework. This release of the .NET Framework does not enable CAS policy by default, so this load maybe dangerous. If this load is not intended to sandbox the assembly, please enable the loadFromRemoteSources switch.
See http://go.microsoft.com/fwlink/?LinkId=155569 for more information.

link之后,我得到了这个信息,我需要进行此配置。

<configuration>
   <runtime>
      <loadFromRemoteSources enabled="true"/>
   </runtime>
</configuration>

如何将此配置信息用于什么? 我使用Visual Studio 2010,但我没有使用Visual Studio IDE,只是有一个简单的批处理文件来构建C#代码。

ADDED

我发现使用App.config this site,我认为可能无法使用命令行构建方法。

2 个答案:

答案 0 :(得分:3)

鉴于您的输出文件是foo.exe。创建foo.exe.config,将其复制到foo.exe旁边并将其放入其中:

<configuration>
   <runtime>
      <loadFromRemoteSources enabled="true"/>
   </runtime>
</configuration>

答案 1 :(得分:1)

您是否尝试过AllowPartiallyTrustedCallers