从C#.NET 4中的某些版本中删除库的所有痕迹 [英] Removing All Traces of a Library From Some Builds in C# .NET 4

查看:59
本文介绍了从C#.NET 4中的某些版本中删除库的所有痕迹的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



有谁知道在C#.NET 4项目的某些版本中是否有任何方法可以删除 all 对库的引用?我曾尝试使用部分类和方法以及条件编译符号等),但无法找到从主项目中删除 using 语句的方法,因此我最终仍然引用了我没有使用的程序集.

我希望能够将代码包含在库中(因此可以在项目之间共享),但是可以包含在主项目的Debug版本中,但完全可以从Release版本中删除.我来自使用C ++的许多年,在这方面非常容易,并且我很难相信C#不可能做到这一点.当Release可执行文件的速度和代码大小是重要的设计问题时,这对我来说似乎是一个合理的要求.

任何帮助或指向有用信息的指针将不胜感激.


亲切的祝福,帕特里克

Hi,

Does anyone know if there is any way to remove all the references to a library in some builds of a C# .NET 4 project? I have tried using partial classes and methods and conditional compilation symbols etc.), but I can''t figure out a way to remove the using statement from the main project, thus I end up still referencing an assembly I am not using.

I want to be able to have code which in a library (thus sharable between projects) but which can be included in the Debug build of the main project but completely removed from the Release build. I come from many years of using C++, where doing this was very easy, and I find it hard to believe the same thing is not possible in C#. It seems like a reasonable requirement to me when the speed and code size of the Release executable are important design issues.

Any help or pointers to useful information would be very much appreciated.


Kind wishes, Patrick

推荐答案

您可以使用"precompiler"指令:
You could use "precompiler" directives:
#if DEBUG
using your.library.assembly
#endif


您还可以根据汇编文件的物理可用性来后期绑定库.
您还可以使用依赖注入"为程序集提供存根"类型.

我认为您可以根据自己的需求使用几种方法.


You could also late bind with your library based on phisical availablity of assembly file.
You could also use Dependancy Injection to provide "stub" types for your assembly.

I think there are several approaches you could use based on your requirements.


这篇关于从C#.NET 4中的某些版本中删除库的所有痕迹的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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