Peter
Peter

Reputation: 48958

How to use external projects in an ASP.NET project

UPDATE : It turned out that the project I was referring to was a console app. Rebuilding it as a class library was the solution.

I guess this should be an easy one :

I have only just started ASP.NET and for now need it only as a tool for some quick intranet reporting. I have an existing project that supplies the data, but I am not able to refer to it from within my web project.

The library is called (for example sake) 'Lib' and I want to test the static method "HelloWorld()" in Utils. I have included the Lib project in the References. The compiler knows it's there cause Intellisense is working and the project dependencies indicate that the webproject is depdendant on Lib.

<div>
        <% Response.Write(Lib.Utils.HelloWorld()); %>         
</div>

Compiler Error Message: CS0103: The name 'Lib' does not exist in the current context

Of course I am very newbee, but in the examples and tutorials for beginners, I haven't fount how to refer to external projects.

Thanks!

Upvotes: 0

Views: 115

Answers (2)

Anton Gogolev
Anton Gogolev

Reputation: 115751

Either fully qualify type name, or @Import appropriate namespace into a web page.

And make sure your site references appropriate assembly.

Upvotes: 2

Klaus Byskov Pedersen
Klaus Byskov Pedersen

Reputation: 120937

First of all you add a reference to Lib in your web project. Then in your page you add the following:

<%@ Import Namespace="Lib.NameSpace" %>

where Lib.NameSpace is the actual namespace of your Utils class.

And that should be it.

Upvotes: 2

Related Questions