?
Solved

.NET Convert Console Application to referance Project

Posted on 2016-09-26
4
Medium Priority
?
79 Views
Last Modified: 2016-09-26
Hi Experts,
 I have a .NET soluation contain 2 project

first Console Application
second WEB application

How do I set the Console Application as refreance to the Web Application


Thanks
0
Comment
Question by:Jamil Muammar
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 53

Expert Comment

by:Ryan Chong
ID: 41816039
do you mean to create a class library and use it in your 2nd web application?
0
 

Author Comment

by:Jamil Muammar
ID: 41816044
yes
0
 
LVL 35

Expert Comment

by:ste5an
ID: 41816089
Don't do this.

Cause setting a reference means code reuse.

In this case create a new project, type class library.
Set a reference in your console application and your ASP.NET application to that class library.
Then you refactor your console application and move all code, you want to share, to that class library.
And when you want good, clean code, then you also create a UnitTest project for your class library.

Adding a reference:Capture.PNG
0
 
LVL 53

Accepted Solution

by:
Ryan Chong earned 2000 total points
ID: 41816150
try this:
1. start your visual studio, create a New Project
2. you can select Class Library from the options there.
snap.jpg3. so you can create a simple class with the methods you want, like this:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ClassLibrary1
{
    public class Class1
    {
        int myValue = 0;

        public Class1()
        {

        }
        public Class1(Int32 v)
        {
            myValue = v;
        }

        public Int32 getValue()
        {
            return myValue;
        }
    }
}

Open in new window

4. change the namespace and class name if you want to.
5. you can press F6 to build the solution
6. you should able to find something like: ClassLibrary1.dll in the bin\debug folder

next, add in another project by doing this:
7. right click the Solution, then select Add > New Project
snap1.jpg8. select a new ASP.NET Web Application project
snap2.jpg9. depend on the version of visual studio you are using, you may select the template you want.
snap3.jpg10. so now you should see 2 projects in your solution explorer.
11. under the ASP.NET web application project, find the References, right click and click Add reference
12. click the Project tab and try find your first class library, select and click Ok to proceed.
snap4.jpg13. now set your ASP.NET web application project to Startup project.
snap5.jpg14. now in your ASP.NET web application project, create a test page and enter the script below:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using ClassLibrary1;

namespace WebApplication1
{
    public partial class _Default : Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            Class1 myClass = new Class1(250);

            Response.Write("myClass value is " + myClass.getValue().ToString());
        }
    }
}

Open in new window

15. try to build your solution now by pressing F6
16 and it's running now!
snap6.jpghope this is clear enough
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses

764 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question