reusing app_code dll from website in another app - c#

I have a project which was done in a website. moving to a web app will be a real pain.
It does get published, and thats how it gets moved to production.
as a result of the publishing, all the classes inside the app_code folder get compiled into an app_code.dll file.
I want to import this dll into another project.
it imports fine. but when i try to deckare an object from inside, my new project cant get a reference to the object.
Can this be done?

Just don't do it. Create a class library project and encapsulate the functionality into a named dynamic link library, which is the output, that can be shared and versioned properly (as opposed to its history being mixed with the nature the website that uses it) in its own right.

Related

Referencing App_Code Class From DLL

I'm working on a web site project. I have inherited a C# class file that I would like to put in a DLL, but the class references classes that reside in the App_Code folder. Is is possible to access App_Code classes from a DLL?
Thanks
ASP.NET websites - as opposed to ASP.NET web projects - are compiled when executed. So when you build them you won't see a .dll output in a bin folder that you could reference from anywhere.
But it wouldn't make sense to use a website as class library anyway. If it contains classes that you need, it would make sense to pull them out of the webiste. That means
create a new class library project
move the class files from the website into the new project
make whatever adjustments are needed to for it to compile.
How well this works may depend on how tightly the code is coupled with the website project in which it lives. For example, a class might look for values in HttpContext.Current. If that's the case, the class won't work outside of a website as-is. You'd need to modify it to get inputs differently. (Without seeing the code, it's hard to know whether this will be trivially easy or tedious and frustrating.)
Hopefully if the classes aren't too coupled to the ASP.NET environment you can remove them from your existing website and even that website can use your new class library.

How to read the properties of an .resx file in a Web site project of asp. Net from a dll assembly

I'm new in .Net and working with two projects in c# a class library project(dll) and a website asp project.
I need to read some properties from a file .resx that is in the App_GlobalResources folder of the website.
Is there a way to read these properties in the .resx website file from a dll assembly more specifically in the method onPreRender??
Thanks for you attention
It sounds to me that you are having some problems with structuring and dependencies in your solution. (Trying to reference the website from a DLL)
Generally speaking, your DLL should not need to access the resources of the website on its own - you should only pass them in through as parameters when calling various methods that are contained in the DLL itself.
Have you thought about migrating the resource file to the DLL?
That would allow both DLL and the website to read from it.
Another option would be to migrate the setting you need to the .config file which you can read by using the ConfigurationManager class ( MSND Link )
You should be able to use it like this, even from your Code repository project:
string settingValue = ConfigurationManager.AppSettings["YouSettingNameHere"].ToString();
However, if you really want to keep your current solution structure you can follow the answer that Pavel Chuchuva gave on a similar question here.

Create dll of ClassLibrary and WebForms Code behind ASP.NET 4.0

I have a project contains a classLibrary and webapplication now what I want is to use this project in another project means I want to add this entire project to another project as dll so developer of newer project cant use, update and see my code they just add in their project and simply use them without knowing whats going on in these dll. I am new to this can someone help me on this. I just to reuse code of webform's code behind and classlibrary .cs files code class which are used and called in webform's code behind.
When you add a class library,
it compiles into a dll.
you can explore the file-system's BIN folder of your project,
and see the dll there after a project build.
What you want to do is take that dll,
and add it as a reference to another project.
Note: You may need to include a using [dll namespace] statement if you want to access
the dll objects / functions without explicitly writing it every time.
I created a mini sample,
here are some screen shots that should guide you through the process.
I'm using VS 2010, but it should be similar 2012 / 2013.

VS2008 how do I find the exact location of a class definition (from metadata)

I am using VS2008 and an AddIn to create a web service.
The tool also creates code to access remote procedures (in fact this is another web service).
In the created code some classes are used which will contain the response. So it is a very nice solution.
Now to my problem: When I use 'Goto definition' function, it shows me the class 'extracted from metadata'. So I guess it compiled the class into some library.
Now I would like to know the DLL where the class is defined.
How can this be achieved? To be honest, I manually checked the DLL and either I am getting old or there is some magic in how VS locates classes.
Could someone please give me a kick/hint in the right direction?
Thanks
Ok. I found out myself. It is too easy:
First, I hover the cursor over the tab header and it gives me the location of the DLL. Although this DLL is not part of the project, within the .svc file, the class is known as the declaring DLL is in the bin folder of the web service project.
I find this very strange as I thought that only files being part of the project (i.e. included) or libaries in the GAC are used for name resolving.
Anyway, I learned something new today, which is not part as all.

Reusing code in .NET website (app_code folder)

I need to use some classes inside the app_code folder of a website project in visual studio 2008. I need to access this code from a class library project in the same solution. I cannot add a reference to the website, and I'm not sure of the easiest way to use the classes that already exist here. Do I need to move it to a class library?
What other options do I have?
Yes, create a class library and move any types you need into that library. This library can be referenced in as many places as you would like.
The best way to do this is to put those classes in their own library.
However, if you really don't want to do that, you could add a link to the files in the library project. To do that, right-click the Class Library project or a folder within it, Add, Existing Item, navigate to the code files, click the down arrow near the Add button, Add As Link. This will add the same file to both projects. You can even use the #if preprocessor directive to limit portions of the file to specific projects.
However, it is vastly preferable to put the code in a library and reference it in the web project.

Categories