Visual Studio 2012 Reference to dll in Library App - c#

I have a such solution hierarchy:
Solution "App"
project App
project Lib
For example, if i want to use somedll.dll in App and in Lib project, i must add references to both projects, but as i understand there must be a way to add .dll only to Lib project, so classes from it would be reachable in App project. Is there a way to do it? Thank you.

If you have, let say, a logging library that will be used along the whole project, then that library must be referenced everywhere it's members are called.

Related

Remove DLL from solution and create a new project to implement that dll functionality

We have a project, and it uses 4 DLL's from Nuget Package(Coming from another team within our project). Now, our project no longer wants to use these DLL's.
I just wanted to understand, if its possible to remove those DLL's and write a new project all together, with same functionality of those DLL's? or any other way possible.
Please sugest

C# Using references/class library in a shared project

I have just learned and created a shared project in visual studio 2017. I have noticed that the shared project did not have the "Reference" to refer to other resources (other projects, class library, …). I even take a look at the .shproj file and saw that it only Import the class I have created inside the shared project.
My problem is that if I want to create an add-in app, I need use the class library to call the necessary API that is exposed by the origin software.
How can I reference/add other project/ class library (or resources in general) to my shared project? Or is that even possible at all?
Part of my problem is also described here reference to a shared project from other shared project
But I need a more general solution. Thank you all for your help.
Long story short: shared projects don't, and realistically can't work that way.
In Visual Studio a shared project is just a container for files - source code, resources, etc - that you can add into other projects. This can be useful in some cases when you want to have the same code (and so on) in multiple projects without putting that code into a library.
Shared projects do not have references, do not have NuGet packages or anything, just the files that they contain. They don't even have the configuration data required to compile any source files they contain, and the compiler won't do much validation of the contents if the shared project isn't included into a full project of some sort.
And since the shared project doesn't have any way of specifying references or packages then you will need to add those references and packages to every project that links to the shared project. The compiler will tell you pretty quick if you miss one.
While it would be nice to have references in shared projects, it turns out to be much less simple than you might think. The same shared project can be included in projects that target different frameworks, platforms and architectures. Let's say you're building some code that will run on iOS, Mono, Windows .NET Framework and .NET Core, with specific code for each target and some shared code. If you try to add a NuGet dependency to the shared project it's going to blow up in your face on at least one of those. Same with most of the references. Add all the references you need for .NET Core and suddenly the other projects don't compile.
You need to add the reference in the project which consumes the shared project.
As an example, let's say you have "Project A" which references "Shared Project B", and you need to use Newtonsoft.Json in "Shared Project B". Since you can't add a reference to the shared project, you install the Newtonsoft Nuget package to Project A and your code in "Shared Project B" will automagically compile.

Why does a reference to a C/C++ DLL project from a C# class library project break in Visual Studio when building the solution?

I am in the process of creating a library to be used in Windows desktop applications. The core part of the library will be a C/C++ DLL that can be used in Win32 applications or other C/C++-based apps. I'll just call it libtest.dll for easy referencing here. I also want to make it available to Windows Forms applications (C#), so I am creating a C# class library (DLL) as a wrapper around the C/C++ library using P/invoke (DllImport) to call into the C/C++ code. I'll refer to this library as Test.dll.
Additionally, I have a Windows Forms project set up in Visual Studio for testing that depends on the C# class library project. The C# class library depends on the C/C++ library project. However, for Test.dll to find libtest.dll (in the DllImport statements), libtest.dll needs to either be in the same directory as Test.dll or in one of the DLL search paths in the system.
To make this easy when debugging in Visual Studio, I thought adding the libtest.dll project as a reference to the Test.dll project would automatically copy libtest.dll into the output directory of the Test.dll project. When I add the reference and then build the solution, the reference ends up broken and the libtest.dll file is not copied into the output directory of Test.dll.
When I add the reference to the Test.dll project in Visual Studio, the properties of the reference look fine:
"Copy Local" is set to True
The path is correct
"Resolved" is True
After building, however, the reference itself has a warning icon on it, and the path is now empty and "Resolved" is False. Any idea why, or how to fix this? How do I set up the project reference between these two library projects so the C/C++ DLL gets copied into the output directory of the C# class library project? I have verified that the build order of the two projects is correct: first libtest then Test.

Visual Studio 2015 Class Library (I'm using C#)

I am working on a Windows Service Application. I have several classes in the project and I am trying to put these classes into a ClassLibrary so I can use those classes in the Service App Project, and also in a Console Application Project, so I can run the console version and step through the code. I don't want to re-invent the wheel here...
I have created a Class Library project, and I am having trouble updating the projects in this Solution to use these classes. In fact, when I moved all my classes into the Class Library project, they are all now throwing errors saying, "System" has no member "Data"! My A$$ it doesn't! Pulling my hair out.
Obviously, I have done something wrong. I've been programming since before there WAS a Visual Studio IDE, but this is SEEMING way more complicated than it should be.
Now my Service project cannot reference my Class Library project because the library doesn't have a .dll or .exe extension? I actually have to specify this somewhere, WhereTF do I do this? Isn't this the default behavior of a ClassLibrary? OMG! I just finished an iOS application, and NEVER thought that would be EASIER than a C# app! I did this in VS2010 easily, is 2015 really different?
It should take me no more than 30 minutes to move files from one project in a solution to it's own project, and then add a reference to that new project in the old one. Giving MS a MegaMindWedgie right now..
Don't need portability with RT hardware, just want 32-bit/64-bit computer apps.
All 3 projects are using the same namespace. I can't seem to add any references to the ClassLibrary project like I can in the Service project. It's blank. The only reference available to the Class Library project is .NETStandard,Version=v1.6
HELP...
It looks like you have created .NET Core class library. You can determine this based on the extension of the project file: *.csproj has been used with classic .NET framework projects, and *.xproj was introduced for .NET Core. Most probably, you don't need a .NET Core class library. So, your problem will go away if you create .NET Framework Class Library project.

add a c# library project to my project and how to use it

i have c# library project. i add it(library.sln) as a existing project to my project. so it comes to my solution explorer.
but in my forms when i try to access it, it seems it dose not exist using library; is noting !
where am i wrong, and what i need to do ?
it can not be build itself in visual studio when i try to debug project, the error is :
a project with an output type of class library can not be started directly
you can see the library project here http://www.codeproject.com/KB/selection/FarsiLibrary.aspx?msg=4043318#xx4043318xx and it have 4 namespace.
You need to use the "Set as StartUp Project" option in your context menu to set a runnable project. The project "library" you created is probably a class library which is not runnable.
Create some runnable project e.g. Condole application to use your library and set that as startup project. Then run your project.
Do not add an .sln to another solution. Add the Project (.csproj) instead.
When 2 projects are in the same solution there still is no link by default. Use Add Reference in the importing project.
Set an executable project as the Startup project.
A library is just a collection of classes, interfaces, enums etc.. In order to debug it, you'll probably want to create a console application that calls methods on your classes that you want to debug.
In addition, just adding the library to the solution is not enough for other libraries to be able to see them. In order to do this, you have to add it as a reference. You can do this by right clicking on the References item in your project, then Add Reference.
Rightclick on your references folder, press "add reference", switch to "projects" and add the reference to your library project.
Even if you add the project to your solution, you have to add a reference to that project for the WinForms project. This has nothing to do with the library.
If your WinForms uses .NET 4 Client Profile and the library requires .NET Full, then you can't access it and need to change the WinForms project to use the full .NET 4 runtime.
There are already good answers, but I would also suggest creating a Test project as a more efficient way of debugging the library.

Categories

Resources