Solved

Accessing methods in different C# solutions

Posted on 2014-09-29
5
136 Views
Last Modified: 2014-10-03
We have a situation were we are developing an NT Service application in C# that will need to run various methods contained in a separate MVC 4.0 application.   These methods can be in a controller or simply in a C# class.

What is the best way for the separate C# program to call other C# program's methods but are not in the same solution?

We are looking at having the methods in their own .DLL or maybe adding a web service to the MVC application.

Any ideas on what would work best?
0
Comment
Question by:jkanisut
  • 3
  • 2
5 Comments
 
LVL 33

Expert Comment

by:it_saige
ID: 40351035
You hit it right on the head.

Having multiple projects simply requires a reference from Project B into Project A.

I.E. (Untested)
ProjectA
using System;
using ProjectB;

namespace ProjectA
{
	public class ProjectAClass
	{
		public void ShowProjectB()
		{
			ProjectBClass bClass = new ProjectBClass();
			Console.WriteLine(bClass.ShowProjectB());
		}
	}
}

Open in new window

ProjectB
using System;

namespace ProjectB
{
	public class ProjectBClass
	{
		public string ShowProjectB()
		{
			return "Saying hello from Project B";
		}
	}
}

Open in new window


-saige-
0
 
LVL 1

Author Comment

by:jkanisut
ID: 40351043
But these will be different / separate solutions...
0
 
LVL 33

Expert Comment

by:it_saige
ID: 40351051
Yes.  Here is a more complete example:

stackoverflow.com/questions/3554658/how-to-use-a-class-from-one-c-sharp-project-with-another-c-sharp-project

A solution is nothing more than a group of one or more projects.  Using multiple solutions does not prevent you from accessing members cross solution or even cross solution; cross project.

-saige-
0
 
LVL 33

Accepted Solution

by:
it_saige earned 500 total points
ID: 40351063
More information regarding referencing projects from other solutions:

stackoverflow.com/questions/9568094/how-should-i-reference-assemblies-from-another-solution

Quite simply, once you build one projects output.  You add a reference to the project output via browsing for the output file.  The rules with regards to assembly resolution apply:

http://msdn.microsoft.com/en-us/library/yx7xezcf(v=vs.110).aspx

-saige-
0
 
LVL 1

Author Closing Comment

by:jkanisut
ID: 40360779
Thanks for pointing me in the right direction.
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
C# Single Form 8 42
Video Player 11 23
What can cause the styling on a .NET site to not be found? 17 24
application restarter  - for an exe that hangs 9 25
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

813 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

16 Experts available now in Live!

Get 1:1 Help Now