Adding references to other projects in Visual Studio 2012 - c#

I have a solution with 4 projects in it.
Test.Common
Test.Controller (Controllers for the Web project)
Test.Data (EntityFramework)
Test.Web (MVC4)
When I go to add a reference to my Data layer to my Controller project and browse to my Data project's directory, should I be using the dll from the 'bin/Debug' directory or the 'obj' directory? And, does it make a difference?

Neither.
You should add a Project reference (from the Solution section)
This will make Visual Studio resolve the reference from the project system, making features like Go to Definition and automatic rebuild work.
Outside your solution, you should add from bin.

You should be adding a reference to the Project in question, not its output. There is a 'Projects' tab on the 'Add Reference' dialog.

If the project is in your current solution you can make a reference to the project (Class Library) itself. This will offload the responsibility of configuration management (Debug, Release, etc) to Visual Studio.

Related

Type or namespace name could not be found for a DLL in the bin folder

I have a third-party DLL. I have added this DLL to the bin folder of a Web Site project and can access it no problem. I then added it to the bin folder of a Web Application project, and when trying to access it I receive "The type or namespace name could not be found."
From my research, it could be an issue with .NET target version. The Web Application project is targeting a higher version of .NET than the Web Site project so this should not be an issue.
I also checked that the file is present in the bin folder in the file system and has the same permissions as other files in the bin folder.
I have been searching for a solution for a while but most things that come up are for other project types like WPF, or talk about project references but this is a DLL.
Anything else I can check as to why the DLL cannot be used by the Web Application project? I am using Visual Studio 2017.
Managing references in a project:
Before you write code against an external component or connected service, your project must first contain a reference to it. A reference is essentially an entry in a project file that contains the information that Visual Studio needs to locate the component or the service.
To add a reference, right click on the References or Dependencies node in Solution Explorer and choose Add Reference. You can also right-click on the project node and select Add > Reference. For more information, see How to: Add or remove references.
Web Site projects are an odd old beast which are different from every other project type. They're also no longer recommended
For new development, we recommend that you choose web application projects. This topic explains that web site projects have some advantages, but many developers who choose web site projects eventually find that the disadvantages outweigh any perceived advantages. In addition, as new ASP.NET features are developed, they won’t always be made available for web site projects. For example, the next Visual Studio release after Visual Studio 2012 will have new tooling for creating web projects, and this new tooling will work only with web application projects.
I'd note that that page doesn't mention that, yes, Web Site projects add references just by copying into the bin folder.

Unable to add project reference in Visual Studio 2015

I previously asked a similar question regarding Visual Studio 2013 but now I'm running into the same problem with Visual Studio 2015 but it seems to work differently, which makes the previous answer not applicable to this question. This is my previous question: Visual Studio 2013 - How to debug a project within a solution
I'm attempting to add a project reference. I have a library I'm working on in a separate solution/project and a console application I want to use to test and debug the library.
I tried: Add Reference > Projects > Solution > Browse
But the open file dialog does not contain .sln files in the filter list and if I force it to display them by typing *.sln and then select the Solution I get:
"Please make sure the file is accessible and that it is a valid assembly or COM component."
What am I doing wrong? How do I properly add a Solution/Project reference?
For me issue was due to difference in Target framework. One was .NET Framework 4.5 and other was .NET Framework 4.5.2
Verify if the Target framework is same for your project and the project reference that you are trying add reference.
(Right click on project -> properties -> Application Tab(Target frame work))
Right click on your solution file in Solution Explorer window, click Add and select Existing Project...
Once the project is a part of the solution, you will be able to add project reference.
In case anyone else runs into this here is something that I found. I had almost the exact same issue in VS 2015. I created a console app and then a class library project but could not add a reference to the class library.
It turns out I didn't create a class library project as I had thought, but rather a class library (package) project. These are different things and I was unaware of what the (package) part meant when I selected it. This is for creating Nuget packages, apparently.
I'm not sure if this is something new to VS 2015 but I had not run across it before and it caused me some grief. The error message ('A reference to ClassLibrary1 could not be added') was totally worthless in trying to debug it.
You should add project to your solution first; after adding project to your solution, you can reference it.
To add an existing project to your solution:
Add reference menu:
Add references dialog:
In order to add a project reference, the project has to be part of the solution.
For me issue was due to a difference in the types of projects. One was a C# Windows forms project and the other project was a C# Universal Windows project.
The Windows Forms project couldn't reference the Universal Windows project. The error was "Unable to add a reference to project "XYZ".
It appears you can have a library shared between both types of projects by folloing this answer: What kind of class library works with both Universal and Winform projects?
I ended up having a different solution. I had three projects in the solution which referenced a NuGet package which was no longer available. I had the library locally but I was unable to add it. I found that because of the BUILD ORDER and DEPENDENCY of my projects, I had to add it to the project that was built first, then I could add it to the projects that were dependent on that project.
I had this problem today and I looked at the configuration manager for the solution. The projects had different platform settings. I made them both Any CPU and rebuilt. Then I could reference the project.

Cannot build C# project in Visual Studio

I am an experienced developer who is completely new to C# and windows development.
I would like to contribute to Rocksmith custom song creator with a simple feature, but I don't even know how to build and run the project in Visual Studio 2012. I cloned the git repository, double clicked on devtools/devtools.csproj then Debug -> Start Debugging but I get an error about not being able to start a class directly.
You can browse the source code of the project at: https://code.google.com/p/rocksmith-custom-song-creator/source/browse/
From what I can tell, you have selected a sub-project in your solution to be the starting-project.
See, if there is project that defines a Window (WinForms or WPF), right-click this project and select it as starting project.
From MSDN
You can specify which project or projects within a multi-project solution Visual Studio will build and debug first.
To set a single startup project
In Solution Explorer, select the desired startup project within your solution.
On the Project menu, choose Set as StartUp Project.
The .csproj is just a project, you need to put that into a Solution (or open the solution included, if any)
Do you have a .sln file? Probably that's the one you must open.

DataTier Application

I have Visual studio project about dataTier application, I prepared a project and in the same solution I have windows from application project.
I want to add as a reference dataTier project to Windows from project.
How can I do it?
Data tier Project in visual studio has no .exe or .dll file so I can not add it as a reference.
The Data tier Project will produce a .exe or .dll file if it compiles successfully on build. Looking in the Project Folder, you'll usually find it in the \bin\Debug or bin\Release subfolder (depending on which build configuration you've used).
But usually you don't want to add a reference in this way. If you right-click on a Project name in Visual Studio, you'll be presented with a menu which has an 'Add Reference' menu item. Click on this, then choose 'Projects' as the type of reference you want to add. You should see all other Projects which are included in the Visual Studio Solution. Just choose the one you want to reference and that's it.
EDIT: Ah, I realise now you're probably talking about the SQL Server Data Tier project type, which contains SQL scripts rather than compiled code so therefore can't be referenced by a C# project.
So, what are you actually trying to achieve here?

Visual Studio 2010: How to enforce build order of projects in a solution?

I had no problem with this in Visual Studio 2008 but it seems that VS 2010 is having an issue, and I'm betting it's probably me.
I have a solution with an ASP.NET Web Site Project and a few C# projects (BLL, DAL, Tests in NUnit). I have configured the build process for the test project to automatically run NUnit to run the tests. I would like to ensure that the BLL and DAL projects build before the test project so that the tests will run against the latest compiled version (yes, I know I could do this all in one project, but I'm choosing not to -- please bear with me :) )
So, I set the dependencies of the Test project to include the BLL, DAL, and Web Application projects, and the build order shows BLL, DAL, Web Application, and then Tests. However, I noticed that the BLL doesn't actually build when I build the Test project.
Any idea what this could be or any option I might be missing to force the other projects to build when I build the Test project?
Nick Craver mentioned checking the Configuration Manager to ensure you have the project selected to build for a given configuration.
However, to set the build order for multiple projects in a solution right click the solution and choose "Project Build Order..." from the context menu.
I'll expound upon my comment a bit here, for those having a similar issue.
Open up the configuration manager by right clicking on the solution and choosing Configuration Manager, then make sure build is checked for the appropriate project (for your current configuration) in the right-hand column here:
Maybe instead of setting order manually you could use Project Dependencies which allows you to specify build order indirectly.
In Solution Explorer, select a project.
On the Project menu, choose Project Dependencies. The Project Dependencies dialog box opens.
The Project Dependencies option is only available in a solution with more than one project.
On the Dependencies tab, select a project from the Project drop-down menu.
In the Depends on field, select the check box of any other project that must build before this project does.
To correct the issue happening in my VS2012, I did the following:
Right click Project Properties --> Common Properties --> Framework and References
Now you will find some projects shown on the Dependence Tab are missing in the "References" list.
Click "Add New Reference" to add the missing the projects.

Categories

Resources