How to reference TFS item within multiple projects - visual-studio-2010

I have a C# solution I created within Visual Studio 2010 Ultimate that contains multiple projects that make use of the same structures, classes, and enumerated types. I have created a .cs file that contains all of these items, but at the moment I have to make a duplicate of this file for each project. This is obviously less than ideal because I have to remember to update each copy of the file should I make a change or addition.
Is there are way I can have all of the projects reference just one actual copy of this file, so that I only have to update it once and all of the other projects can see this update? A colleague of mine told me it was possible to make some sort of "symbolic" reference in TFS, but since I don't really know what the name of this feature is I don't know how to research it further.
This question has answers that suggest either creating a class library or using "Add as link" when adding an existing item. I suppose I can do this in Visual Studio when not using TFS, but I have posed this as a TFS-specific question. Will this "add as link" option work when TFS is in use or do I have to do something in TFS to get it to honor the link reference?

"Add link" option would definitely work with TFS. You dont have to do anything specific for that. "Add Link" is project specific and it will add a new entry to your project file specifying the location of your .CS file. As long as the file is available in the particular location during server build, there is nothing to worry. Make sure that the Add link makes a relative path to the file and not absolute.
In my company, we have multiple projects within a solution and we share a single "Assemblyversion.cs" for all the projects so that I dont need to write version info in multiple files. We have made use of Add Link and it works great!

Related

How do I see all of the "missing" files in a Visual Studio solution that need to be included in the projects?

I have a Visual Studio 2019 (16.4.2) solution with several projects and hundreds of subfolders that sometimes have files on disk that need to be "Included" in the projects. This most often occurs after Nuget upgrades of 3rd party CSS and JS libraries, but this may also include image and icon libraries that have been imported.
The most common occurrence is when a 3rd party library is upgraded via Nuget, it'll add new css, js, images, or other content files to disk (sometimes more than 100 new files in a single upgrade). But since I don't know they're there, after I deploy the upgrade via Devops, none of those new files will get deployed, which causes all sorts of obvious problems. Then I have to go back and open every folder and subfolder, manually locate the missing files, click "Include in Project" for each one, then re-deploy.
There has to be a better way.
I don't necessarily want to include all missing files, because there are some files--especially source control-related files--that should not be included in the projects and need to just be left on disk. So what I need is a way to see a list of all of the files that are on disk but not included in the projects, so I can choose which ones to include.
Also nice would be a warning by Nuget about new files being added, which is probably asking too much (even though this is a very obvious feature that Nuget should include without asking for it).
How do I see all of the “missing” files in a Visual Studio solution
that need to be included in the projects?
Usually, you can click the menu Show All Files from the solution explorer(Before that, you need to click on the specific item to see the hidden file). In this way, you should check every project and select which part to import based on your need.
So what I need is a way to see a list of all of the files that are on
disk but not included in the projects, so I can choose which ones to
include.
I am afraid that you cannot get what you want so far.
In VS IDE, there is no such function to obtain a list of all exclude files in your solution and then select which to import by default.
Also, there is no such vs extension to implement it.
So you should check every project and manually select the file to import by Show All Files Button.
Suggestion
If you still want this feature in VS IDE, you could suggest a feature on our User Voice Forum.
After that, you can share the link here with us and anyone who is interested in it including us will vote it to get more Microsoft's attention.

Purpose of linked file vs class project?

What is the purpose of "Linked" Files in visual studio, and when I would use them versus simply including the class project that contains the file to my current project.
Project + Add Existing Item, arrow on the Add button, select "Add as Link".
Visual Studio strongly favors copying the item you select in this dialog into your project directory. This will keep you out of trouble, like accidentally modifying a source code file or resource that's also used in another project. Or forgetting to check-in the file into source control, by far the most dangerous mishap. Something you'll discover only a year or more from now, far too late to do anything about it.
The Add as Link option overrides that behavior, the file stays in its original location and the project file records the relative path of the file.
Good reasons to use this feature are very hard to come by. Trying to come up with some:
You may want to maintain a single source code file that's included in multiple projects, using Add as Link ensures you'll only ever edit that one single source file.
You may have a project that uses the same source code files as another project but with very different build settings, in which case you'd make all of the project items a link.
You may have a humongous resource that you don't want to have copied repeatedly in multiple projects
You may have a deployable item, like an unmanaged DLL, that you keep in a single directory but is used in multiple unrelated projects.
Digging yourself a deep source control hole is a high risk, be sure to think this through before you commit to using the feature.
Linked files are for when you want the code to be included in that project assembly.
"Wow Jimmy, thanks for pointing out the obvious. But why would I want to do this?"
Well, there can be several reasons, but for now I'll just list one example. Consider the scenario that your company|team requires every assembly to have certain constants or assembly attributes defined. Instead of creating a duplicate class in every single project, you could just have one copy of the file and link it into each project. Update the file once, and every assembly gets the changes.

Is there a good way to create and use a 'Template' in Visual Studio 2010

Our projects in our company are all built based off a thing we call a 'Project Scaffold'. It's got all the base required code for all sites, basic folder structure and all other things similar to that.
At the moment, we have a repository for this 'Project Scaffold' and each time we want to create a new project, we copy this project into a new folder, and rename all occurrences of the name 'ProjectScaffold' within the project. As you can tell, this is quite time consuming and can sometimes cause errors if we miss out a single occurrence of 'ProjectScaffold'.
This project will need to have all the default dependencies which is why having a full project that we copy is working for us at the moment.
I have looked into the possibility of creating a visual studio template but I can't seem to find a good way of accomplishing it.
We have been thinking if there was a way to possibly implement it through a NuGet Package, however I feel as if this would be either extremely difficult or impossible.
If possible, it would also be something that would be usable in Visual Studio 2011
Simply File-->Export Template :)
You can then customize the generated zip file to suit your needs.
More on this on the Creating Project and Item templates on msdn

Anhksvn + Visual Studio - working with linked files

I could use some advice.
I'm in the process of adopting subversion, and I'm trying to put some existing Visual Studio 2010 projects into a repository. I have the current version of AhnkSvn.
The projects I have are organised as;
VS2010_projects\Project_A
VS2010_projects\Project_B
VS2010_projects\Project_C
VS2010_projects\Common_code
Where Project_A, Project_B and Project_C may all refer to one or more files in "Common_Code"
In visual studio, these files will have been added using "add as link".
There is no actual project in "Common_code" just a collection of useful code files, which we're likely to re-use in different projects.
(If we have a module or class which is re-used in various projects, then we often keep a single master copy in 'common-code', and link to it.)
Visual Studio has no problem with this.
When I add any of the actual projects to subversion, all of their own files are added just fine, but the linked files are ignored.
(And as a consequence, if I then get a working copy of those files, then it's just the project files which get handled, I won't get a copy of the linked files.)
If I right click on any of the linked files, I the only subversion options I get are to refresh their status or to select the working folder.
I was wondering what the correct way to handle this situation was ?
Any advice would be much appreciated
Thanks !
Robert
if I understand your question correctly then I think SVN is acting in the desired way. A linked file is merely a reference to another file. That reference exists only in the .csproj file which is checked in. It would not make sense to have two copies of the same file in source control, and it could lead to versioning issues. The first time you checkout your repository doing a build on your projects should copy the files from Common_code to the places that they're linked.
As an aside we've had alot of random issues with .csproj linked files and SVN, and so try to avoid linked files where possible. A better way to re-use files across projects is obviously just to embed them in a library and then reference that library. This should work fine with the exception of certain files like Javascript/CSS.
Also you may want to check out SVN externals, a workmate mentioned this can be used to share common libraries between multiple projects, although as a disclaimer I haven't tried this myself and can't comment on the merits or drawbacks of the approach.
Thanks for the advice, I actually did something similar to your suggestion.
I didn't want to make a full blown library, but I did make up a dummy project, and put my shared files into that.
Then I added the dummy project to the repository.
AhnkSvn now seems to be satisfied that the linked files are under subversion control, and seems to handle them just fine.
(I haven't added any reference to the dummy project to my existing projects - they just use the linked files as before - but now AhnkSvn shows me their status, and allows me to get the latest version, and commit changes.)
I can see the case for having a proper library - but that would have meant modifying a large body of existing projects. This approach lets me get up and running with Subversion without requiring those changes first.

Visual Studio Extension to map Solution Folders to Real Folders

In an earlier question, I've found out that sadly Solution Folders are not real folders inside a directory.
I wonder if there is an AddOn or Macro that adds this functionality? i.e. when I create a Solution Folder, it created a real folder. When I Create a new Item (Right Click => Add => New Item) it automatically moves them into that folder, removing causes it to delete it from disk (after asking) etc.
This is for Visual Studio 2005, although we might upgrade to 2008 in a few months.
As of now, this doesn't seem to be possible in either VS 2005, 2008 and 2010 and there is no AddIn for this.
I too thought it was a strange idea. However it can be a useful tool to logically group projects in solutions without necessarily moving around folders in the file system.
I suspect you need this for revision control tool. In that case Look at AnkhSVN.
Maybe what you want is to add files to a solution folder as «links», i.e., keeping the files where they are but giving them a different organization inside the solution.
(when you add an existing file to a solution folder or to a normal project folder, if it is in a different corresponding physical folder, the file is copied).
It usually stays unnoticed, an option in the «Add > Existing Item ...» dialog where you can choose "Add As Link", instead of the "Add".
This allows to share files amongst projects, or, simply, organize them differently.
What I oftem miss is the possibility to add "virtual" folders inside a project, for organizational purposes, without breaking the namespace/folder best-practice.
Can't really get the point you want to add this function.
Sometimes you want to know if it can do this , however, the answer may be no. But it is not necessary means you can't achieve your original goal, there still a few ways to work around it without this.
Additionally, VS solution suppose to be the shortcut of your project settings and should not been included in any hard-code, the solutions may be various between the PCs and IDE envrionment.
I didn't really use VS2005 much, but have been using VS2008 for the past year.
It has a tick box for creating a solution folder when you create a new solution/project.
If you then use the "Solution Explorer" window you can create and manipulate folders and class files within them. This will actually create new directories that match.
Deletion of files from within the Solution Explorer will also delete the actual files from disk.

Resources