Automatic References for new projects in VisualStudio - c#

I have a Visual Studio solution, for which I'm trying to keep the code fairly well separated, so I'm using quite a lot of projects.
I've got a handful of projects that use all the other projects (Unit-tests, a Bench-marker, a "Main" project). And a couple of the existing projects are going to be used by all the projects (core dependencies, utility projects, etc.)
The upshot is that each time I create a project, I have to give each project in the first group a reference pointing to that new project, and I have give the new project a reference pointing to each project in the second group.
I also have to add any common nuget packages I want (e.g. MoreLinq)
Is there any way to tell VS about these things and get it to do them automatically when I add a new project?
(Running VS2013 if it's relevant)
================================================
Note: It's entirely possible that the correct answer is "you're using too many projects". If you think so, thank you, but please don't feel the need to comment - that's not the question I'm interested in answering at the moment.

You could create a project template new projects in your solution.
See http://msdn.microsoft.com/en-us/library/xkh1wxd8(v=vs.120).aspx for more details.

Related

Self-built C# Library not found

I have an issue including a self-built library to a C#-project. I have created an own class library called ClassLibrary1 just to learn how to add libraries on Visual Studio 2019.
So I have written some simple code in a newly created .NET-class library project and have clicked on "create new solution" (directly translated from my german IDE-language. Maybe it's called slightly different) after writing the code. Back in the C#-project, I have selected the dll-file from bin/Debug/ of the class library's project folder.
After I have set the checkmark, the dll-file was shown in the solution-explorer under Assemblys like expected. But the issue I now have is that I still cannot use the ClassLibrary1.dll-file in the cs-file in this very project as I expected via the command "using ClassLibrary1;". It only shows me the error message "type- or namespacename "ClassLibrary1" not found" when trying to compile the C#-project and I don't get, why this is the case.
It seems like it has to be a very obvious problem but after some research on the internet and trying some things by myself still nothing has changed.
Thanks in advance for helpful replies.
The by far easiest way to manage a library is to use project references. Ensure that your library and the project that uses the library is in the same solution. Then right click the "references" and select "add Reference", go to the project tab and add a checkbox for the library. Read more about managing references.
You might also need to add namespaces for the classes you wish to use in the source files.
I would not recommend managing using file-references to lose dll-files, since it can easily become a hassle to manage. I.e. if you create a new version of the library you would need to build, and explicitly replace this file in all other projects and update all the references.
If you want to share libraries between multiple solutions the more popular solution would be to setup a nuget server. This solves some of the updating problems by maintaining multiple versions of the same library, and provides a nice interface to update references in all projects. But this is a somewhat more complicated solution, so I would not recommend this for new developers.

Trying to better understand Shared Projects and using them in different solutions

Even though Shared Projects have been around since Visual Studio 2015 (maybe as early as VS 2013 update2), I've only recently learned about them. Today I spent time trying to learn how to use them following a tutorial I found Shared Project: An Impressive Feature of Visual Studio 2015 Preview. However, the one thing the author did in that tutorial, which won't work for us, is he created the Shared Project and 3 other projects, all within the same solution. Of course, you can do that, but in practice we're likely to want to create a Shared Project in some solution, and then as time goes by, include that Shared Project in other solutions.
So what I did is instead of putting the Windows Forms application into the same solution as the author of that C# Corner post did, I created a new solution with a Windows Forms project in it, then I tried to add the Shared Project from the first solution. First, I tried adding the .sln file. That failed miserably. Then I tried adding the .shproj file to the second solution. That failed miserably as well.
Next I shared here on SO for ways of addressing this. I found 2 posts: Adding references in a shared (.shproj) project and How do I add a reference to a Shared Code project (.shproj) from another project. The second one gave me an idea. I decided I would simply add the Shared Project, from the first solution, to the second solution by clicking on the second solution within Solution Explorer, then doing a "Add Existing Project". That worked.
But I wonder, is that the way you're supposed to use Shared Projects? If so, it seems to me as though I could just as well created a simple class library in the first solution and then added that class library project to the second solution. Is there something about Shared Projects that make them inherently better to use, if you add the Shared Project to a different solution, instead of just adding a regular class library project to a solution?
A class library compiles into its own DLL and your original project references that DLL, whereas a project using a Shared Project will compile into a single assembly. One scenario I could think of with shared projects is that you can have single code base but has platform specific code sections marked by directives.
There is a good video on this subject even though it's being explained in the context of xamarin they do a good job i think.
https://www.youtube.com/watch?v=G5ov0gLZWgQ
Personally I I would always go with PCL (portable class lib) rather than SAP (shared project). I use shared code projects as documentation container in my projects. The project green icon stands out really well. I keep everything there from markeddown doc files to stored procedures and etc.

Teamwork problem writing the code with colleagues in bitbucket

I am writing the code with my team by usin0 the Bitbucket service. The problem is the following:
Since yesterday, when I downloaded the last commit from our public repository I see all projects (folders) but in visual studio where I want to run the application the compiler tells me that some libraries, projects or references are missing. At the same time I see only one of four projects in visual studio(while it must be four). I've tried to rebuild the solution but this does not help.
When I asked one of my colleagues about the problem, he told me that this is a standard procedure and he will give me the access to all libraries and projects when the work will be finished.
My question is: Can I do something to got the access to all missing files?
P.S. I am the owner of Bitbucket repository
Check with your colleague their solution build before pushing new changes and all the dependencies / changes to packages.config and project files are pushed in.
Usually a clean and rebuild and a compare between project files will tell you what are the differences.
P.S. if you have a .gitignore file check that too, in case someone added something that is required to your project.

C# Project with either ProjectReference or Reference

we are working on many different applications where each application has its own VS solution (and of course a CS project). Additionally there are many libraries (also CS projects) that are shared between the applications and are included in the VS solution so that you can debug during startup phase of the development.
We also have a "master" solution that contains all projects in one big solution for refactoring issues. Because VS does not support "solutions in solutions" we have to maintain also this master solution. We are talking about 300 assemblies.
Now a point is reached where it's helpful anymore to have all CS projects as ProjectReference in the application solution anymore. For example we have a library that does the CUDA support which can be compiled once and then used as a regular Reference.
The only problem here is that there are occasions where you need the ProjectReference back again when you need to debug into a problem that can only be verified when it runs in conjunction with the main application and cannot be verified in a normal test case.
One option would be to maintain two projects, one for debugging and one for working. The only problem is that once you debug and you need to use the ProjectReference the dependencies cascade down the whole project tree.
For me it feels like that I need two CS projects for each project. One that only contains References and another one that only contains ProjectReferences. Mixing could be a problem. The question is, if there is something automatic where a Referency-only project can be created from a ProjectReference-only project?
How do you solve something like this?

Adding projects with dependencies to solution (Visual Studio 2015)

So currently we are in a situation where we have acquired quite a large code base. Every once in a while we start new projects (new Visual Studio Solutions) that require parts of our already existing code base.
Now the tedious part begins once you add one of these projects to the new Solution because this project requires other project files that it depends on (which in-tern again require different other projects).
So my question is:
Is there an easy way in visual studio to tell it to crawl a certain folder for these missing dependencies? So that it loads all the respective .proj files into my solution that it requires?
This sounds like such an obvious thing to me that I am certain there must be a better way?
Thanks a lot in advance
Oli

Categories