1

I have a class library lets call it UtilityLibrary.

I have a console application. So I right clicked on my solution and added an existing project (UtilityLibrary). I noticed that I can change the code of UtilityLibrary from within my console application.

The issue is if I had added UtilityLibrary to another application and the code had been changed it could causes issues. I was trying to avoid adding a dll reference so thought I would add a reference to my project however I am worried about the code being edited.

Have I added the reference to my project incorrectly?

2 Answers 2

1

If you where to check the Debug or Release folder if your console application you should see a UtlityLibrary.dll file, which would still mean that you are, in the end, adding a DLL reference (visual studio will do it for you).

Since you do not want to allow external entities to change your application, simply add a DLL reference instead.

Just to clarify, you can only change the source of one DLL from another application becuase visual studio can find the source files and makes them available to you.

Sign up to request clarification or add additional context in comments.

4 Comments

So if I add a dll reference instead people will not be able to change the code from within my console application? If down the road I need to make changes to my class library I do I just have to recompile it & any project that references it will automatically start using it? Or will the projects using it have made a copy of the dll so will need to re-add the reference?
That will work indeed. If you reference the assembly, and the assembly gets updated, it will automatically take the newer version if you compile the other project.
Ok thanks. Why would you want to ever add a reference as a project? Doesn't seem to safe to me
What isn't safe? The end result is an assembly. You don't send a code project to the customer, you send a set of assemblies. If you are spanning multiple projects in one solution, it is useful since it has more information for you when debugging.
1

No. You have done nothing wrong. And you can't just change the code of the compiled assembly. You are utilizing a feature from Visual Studio. Since you've build on this machine, and the PDB's are included, it can tell the assembly originated from that source code on your machine. So it allows you to edit it.

These edits don't come in the compiled assembly immediately, you have to compile it again in order to be in the assembly. (Note that you can extract the source code from any .NET assembly by using Refactor for example)

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.