C#dll创建并使其不可编辑 [英] C# dll creation and make it not editable

查看:78
本文介绍了C#dll创建并使其不可编辑的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,



i创建一个Dll文件并使用它c#project。但是在c#项目中我的dll类可以编辑但我不希望有人编辑我的dll file.How我可以修复吗?

Hi everybody,

i create a Dll file and i use it c# project.However in c# project my dll class can editable but i dont want o someone edit my dll file.How can i fix?

推荐答案

.NET DLL文件是程序集 - 这意味着它们不是可编辑的。它们是可读的(即使你混淆内容使其变得更难)也是如此,因为系统需要能够读取它们才能执行它们包含的代码。

但它们不是在任何有用的意义上都是可编辑的 - 没有程序集编辑器允许我直接对你的DLL进行更改。这并不意味着我不能使用十六进制编辑器编辑它们,如果我确切地知道我在做什么 - 但是它们不能改变你的代码,因为C#和DLL神奇地反映了那。为了更改DLL,需要重新编译。



因此,如果你改变DLL文件中的行那么这意味着你已经添加了DLL Project到您的解决方案 - 这很好,并且允许,因为您经常希望同时开发EXE和一个或多个DLL程序集。但这不是唯一的方法。首先备份,然后从解决方案中删除项目,以及从其他项目中删除引用。然后创建一个新的解决方案,并将DLL程序集包含为其项目。构建适用于Release。

返回原始解决方案,并使用Browse按钮在其Release文件夹中添加对新创建的DLL的引用。



现在您的应用程序将构建,并且将能够使用DLL内容,但它将无法更改它。
.NET DLL files are Assemblies - and that means they aren't "editable". They are readable (and always will be, even if you obfuscate the content to make it harder) because the system needs to be able to read them in order to execute the code they contain.
But they aren't "editable" in any useful sense - there is no "Assembly editor" which allows me to make changes directly to your DLL. That doesn't mean I can't edit them using a hex editor, if I know exactly what I'm doing - but they can't be changed in in teh sense of altering your code as C# and the DLL "magically" reflects that. In order for teh DLL to change, it would need to be recompiled.

So if you are "changing lines in DLL files" then that implies that you have added the DLL Project to your solution - which is fine, and allowed because you often want to develop the EXE and one or more DLL Assemblies at the same time. But it's not the only way. Backup first, then remove the Project from the Solution, and the references from the other projects. Then create a new Solution, and include the DLL Assembly as its Project. Build that for Release.
Go back to your original Solution, and add a Reference to the newly created DLL in it's Release folder using the Browse button.

Now your app will build, and will be able to use the DLL content, but it won't be able to change it.


如果您不希望有人编辑您的cs文件,然后不要让他们访问它。 cs文件被设计为可编辑的,所以如果你有不想开发的人,你需要实现某种代码库,如SVN或GIT,它们具有相关的访问控制。
If you don't want someone to edit your cs file then don't give them access to it. cs files are designed to be editable so if you have people you don't want developing you need to implement some kind of code repository like SVN or GIT that has relevant access controls.


一个DLL不能(轻松)编辑。您可能已将源项目包含在解决方案中,这就是您可以编辑源代码的原因。如果您(或其他人)只是将该DLL添加为项目的引用,那么它就不可编辑。
A DLL can't be (easily) edited. You probably included the source project into your solution and that's why you can edit the source of it. If you (or someone else) just add that DLL as a reference to a project then it's not editable.


这篇关于C#dll创建并使其不可编辑的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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