[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

.NET Convert Console Application to referance Project

Posted on 2016-09-26
4
Medium Priority
?
88 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

On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

Question has a verified solution.

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

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
This document covers how to connect to SQL Server and browse its contents.  It is meant for those new to Visual Studio and/or working with Microsoft SQL Server.  It is not a guide to building SQL Server database connections in your code.  This is mo…
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …

656 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