Solved

.NET Convert Console Application to referance Project

Posted on 2016-09-26
4
50 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
  • 2
4 Comments
 
LVL 49

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 32

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 49

Accepted Solution

by:
Ryan Chong earned 500 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

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

760 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now