How to load a custom assembly automatically every time Visual Studio launched? - c#

I have a C# class library to make the works easier and I want to use it in my every project. So there must be an easy way to load it automatically as default on VS is opened and so I don't have to reference it again and again in my every project created. How can I do it?

If this project is stable version, you could add it to GAC like those .net framework dll. refer to below msdn article
https://learn.microsoft.com/en-us/dotnet/framework/app-domains/how-to-install-an-assembly-into-the-gac
Create a new project, add reference to above dll, and use File->Export Template --> Project to export a new project,
after that, restart Visual Studio, you should be able to see your own project template when you want to create new project.

Related

How do I reference an assembly in Visual Studio 2019? WPF on .NET Core

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?

How to share references to dlls across multiple projects in a visual studio solution?

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.

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.

How do I use RedditSharp in Visual Studio (2012)?

I am making a C# Web Form application and I want to use RedditSharp. https://github.com/SirCmpwn/RedditSharp
I've never used an API in C#, this would be my first time using something outside of the C# generics. Could someone help me understand how to import it to use it?
Create C# Web Forms project in Visual Studio
Download RedditSharp code from Github
Compile RedditSharp into DLL (build enclosed solution, grab DLL from the bin/release folder or wherever it builds to)
Add a reference from your project to RedditSharp DLL
Check examples at https://github.com/SirCmpwn/RedditSharp, add something like that to your code
Don't forget to add "using RedditSharp;" to the top of your code file.
Easiest thing to do in Visual Studio is to install the nuget package. Go to Tools...Nuget Package manager... Manage Packages for Solution. Search for RedditSharp, click install.
Now you can reference it from anywhere in your project by adding:
using RedditSharp;
This has the added benefit of Visual Studio alerting you to new updates anytime the official RedditSharp project is updated.

How to include source instead of a library in C# / Visual Studio?

I come from a long Java background and very new to C#. I was trying to run one of the starter kit applications from Windows phone and I am getting this error.
A first chance exception of type 'Newtonsoft.Json.JsonReaderException' occurred in Newtonsoft.Json.WindowsPhone.dll
I am finding it hard to debug this because I am directly referring to the dll file under References pointing to Newtonsoft.Json.WindowsPhone. In Java, I would have searched for the library and downloaded the source to step into the exact location during debugging.
If that is possible, how would I do it in C# (as in how would i refer the library source for my project to pick up at run-time)? I am using the Visual studio 2010 Express Edition as the IDE.
Download the third party library you are dealing with
Add this library's project into your solution
In your project, remove the reference to the 3rd party library
Add a project dependency into your project, make it depend on the 3rd party library project you have just added to your solution
Compile and run, happy debugging
My best guess is you should download last release of Json.NET, remove the compiled library from your project's references and add reference to the source code project. (Add Reference... > Projects > Browse...)
Once you have stopped your program in the debugger, you can use the modules window to load the symbols for Json.NET. Obviously, you need to have the symbols on your machine so you can browse to them.
Failing that, you can switch to a project reference and include Json.NET in your solution as Dan suggested.
The easiest way is to download their latest build then inside visual studio right click your solution and under add menu select existing project point to project file of the library and click open button. after that u will be able to set brakepoint wherever u want.

Categories

Resources