I have created a solution file consisting of these 2 projects: ProjectA and ProjectB (main). How can I get Visual Studio's Intellisense to work across the two projects?
For example:
ProjectA has ClassA with MethodA. While working on ProjectB, how do I get Intellisense to detect MethodA and any documentation on it without a build/rebuild of ProjectA?
You need to add a Project A as a project reference in Project B using the projects tab of the Add Reference dialog.
This will cause Visual Studio to read Project from the project system rather than the compiled DLL.
This offers a number of advantages:
You won't need to rebuild it
Visual Studio will realize that there is a dependency and automatically build project A when building project B
Editor features like Go to definition will work.
In the event that you already have a reference (and the Intellisense is still not showing up), this probably means you are referring to a dll already. You will have to remove the reference and add it again via the Add Reference dialog as mentioned above, or it will tell you that it already has that reference.
Related
I'm trying to create a WPF application using FolderBrowserDialog and I know I need to add a reference to System.Windows.Forms. The only problem being is that there are no sources anywhere on how to do that in Visual Studio 2019.
The main differences are in my Solution explorer the place to reference is called Dependencies whereas on every single person's VS it's called references? What's up with that? And when I try to add references to the window for it I don't have the assembly tab, here's what I mean:
This is what it's supposed to look like:
,
and this is what I sadly have:
I'm very surprised that this is how it is, is there any reason that this is like this?
I am porting a .Net Framework 4.7.2 project to .NET 5 and have Excel.Interop build errors that Intellisense has no problem with. I have:
Created a new .NET WPF project
Update the TargetFramework property in the .csproj file from .netcore3.1 to net5.0-windows
Copied my classes over into the new project
Added a reference to the Excel 16.0 Object Library
Changed the Copy Local property of the Interop.Microsoft.Office.Interop.Excel dependency to Yes and changed the Embed Interop Types property to Yes as well
Started a build
The build fails with Interop errors like "'object' does not contain a definition for 'Value'" even though those errors in Intellisense go away after I update the Copy Local and Embed Interop Types properties.
Following the build, if I double-click on each of the build errors, the class file opens and Intellisense considers the error resolved: it disappears from the list and the red line under the code disappears as well.
I see Interop.Microsoft.Office.Interop.Excel in the project Dependencies --> COM expandable items in the Solution Explorer, but when I right click on the Solution, do Properties, and look at Project Dependencies for my project, nothing is listed. Is this a problem? Would a COM reference be listed in Solution Properties --> Project Dependencies?
I was under the impression that the Office Interop libraries would be compatible with .NET 5 and that I am setting things up correctly. Why is does Intellisense think things are fine but build errors result?
Things I've tried
Restarting Visual Studio and my computer
Removing the reference and re-adding it
Cleaning and rebuilding the solution
Deleting the bin and obj folders in the project
I have multiple base console projects nested within a single solution in Visual Studio. Each project creates a reference to the same base dlls.
How can I create a centralized references or lib section so that all projects within the solution can reference that centralized location without having to duplicate the same base references to the same dlls over and over again for each project?
From your screenshot, most of your References appear to be .Net Framework Class Libraries. You don't have to worry about those.
If you are re-referencing the same custom libraries, it is better to include the Library's source as a Project within your Visual Studio Solution and add Project References to that Project in every other Project where it is needed.
Example: Adding a Project Reference
If you don't have access to the source code of some of the custom libraries, then what I usually do is, create a \Libraries folder at the root folder of the Solution Source folder, and add file references to the individual DLLs from the other Projects within the solution. This way, if 1 or more of your DLLs gets updated / upgraded, you just replace the copy in the \Libraries folder and all your referencing projects will point to the latest version.
You cannot avoid having to reference those libraries from each individual project. But if you are looking to do the same references for a large number of projects - or if you just have some favourite references you want added to each new project you add - then Visual Studio has that capability - it's called a template project.
Create your project the way you want it (it will most likely be a class library, although you can do a UI based one as well), then click File->Export Template, which brings up the following wizard:
Then the next time you go File -> Add -> New Project your new template will be listed just like my example on here:
If you already have a whole lot of established projects that you want to add the same reference to (and it isn't available as a nuget package so you can't use the nuget package manager), then there is a more hardcore way. Visual Studio project files are XML, so you can right click on a project in your Solution Explorer, select Unload Project, then right click again on the project and select Edit to open the project file as XML. You can then copy paste the Reference nodes containing the references you want to propagate. Do be careful to adjust any relative paths where necessary.
If you need to do this in a bulk way then open the project files in Notepad++ and do your copy paste operations.
You can't escape it. You need references in your project, you will have to reference them. If you have third party dlls then you can put them in a single folder and reference them in desired projects from there.
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.
I tried to created a .dll in TFS using VS2010 and use the .dll in a new project.
However, it keep on returning an error message saying the entity point for the method cannot be found.
To see if there is some error in the code of the class library, I created another class library project but not in TFS this time. This totally works well. This one can be referenced by C# using "using".
However, the one created in TFS cannot be referenced.
I would like to ask, what's the difference between these two .dll I created and what can I do so that I can successfully reference the .dll I created in TFS.
Many thanks!
Are you sure the error didn't say "Entry Point Not Found"? I have seen this many times when a project is set to build in x86 format when it should be building in x64 or AnyCPU. Right-click on the solution and go to Properties. Click Configuration Properties. Find your project and look at the Platform column. AnyCPU is usually your safest bet.