How do I setup configuration when I use command line to build C#/.NET?

一个人想着一个人 提交于 2019-12-23 08:11:31

问题


When my program tries to access the dll in the network drive, I got this error message.

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.

Following the link, I got this info I need to have this configuration.

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

How do I put this configuration info to what? I use Visual Studio 2010, but I don't use Visual Studio IDE, but just have one simple batch file to build the C# code.

ADDED

I found this site using App.config, and I think it may not be possible to use method with command line build.


回答1:


Given your output file is foo.exe. Create foo.exe.config, copy it right next to foo.exe and put this in it:

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



回答2:


Have you tried AllowPartiallyTrustedCallers?



来源:https://stackoverflow.com/questions/6469513/how-do-i-setup-configuration-when-i-use-command-line-to-build-c-net

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!