How to edit .sln file in TFS 2010? - visual-studio-2010

I need to delete several lines from the solution file (.sln). When changing .csproj files I can use "Unload project". But what is the proper way to edit .sln file in TFS?

Your best bet is to close the solution and use a text editor (Notepad or equivalent) instead.

You can use the TFS Powertools for that purpose. It enables you to make tfs-"operations" from the windows explorer (and edit the .sln file with an txteditor).

Another option is to copy the sln in Visual Studio as a temporary text file, and edit there. I used this to handle some changes like regex updates to the sln file, without having to use the VS UI to adjust tons of build processor changes (and without having to do it using a public online web tool).
Once the text was updated, paste the new text back into the original sln file and save, using a tool like notepad, etc. VS will then tell you it needs to reload the new sln, and the changes will be loaded.

Related

How to copy and rename a solution under source control in Visual Studio 2013

I have a VS2013 solution called ShoppingService.sln with 7 projects under TFS source control.
Now I want to make a copy of the solution, rename it to 'BasketService.sln' and have it under source control again.
I don't want to make branches of the original solution, since both solutions should co-exist separate from each other.
What's the quickest or best way to do this?
Ok, here's what I ended up doing:
Copy entire solution folder to new location.
Remove any source control files. They begin with *.vs.
Remove any read-only attributes on folders and files.
Open solution from new folder and rename solution and each project.
Open properties for each project and edit assembly name and default namespace.
Close solution.
Rename folders on disk.
Edit solution file in a texteditor. Replace all references with new folder names, and remove team foundation section in .sln.
Open solution again in VS and fix any leftover issues. I use Resharper to fix new namespaces.
Search through all files for your old solution/folder name and update with new name
Consider deleting the obj and bin folders to force Visual Studio to regenerate all of those files during a build
Add solution to source control again.
And you're done.
Step 8a. Open all Project files (e.g. .CSPROJ, .projitems) in a text editor and edit folder pathnames to point to the new solution's folders.
Quickest
File --> save solution As. 'BasketService.sln'
Right Click Solution --> Add to source control.
Right click Solution --> Check In

When I unload projects in visual studio, where does VS save this setting?

I checked the solution file and the project file, and can not find anything related to this setting. When people get latest version from TFS source control, they always see the 'loaded' status, which is not really what I want.
This information is stored in the solution user options file (.suo) which you can find in the same directory as the solution file. As the name implies this is user specific information which means sharing this across the team will be difficult because then everyone will need to live with the same options and store files in the exact location because the .suo file contains full paths.
For anyone else coming here with Visual Studio 2019, the unloading of projects is no longer saved in the SUO (at least in my experience). To save your unloaded project settings, you want to create a solution filter file (.slnf) which is the same as your solution file (.sln) except that it stores which projects you want loaded or not when opening the solution. Once created, you will double-click the .snlf file instead of the .sln file in order to load your filtered projects.
To create the solution filter file you can follow the instructions at this link or follow the summary below:
Open your solution (.sln)
Unload the projects that you want filtered out
Right-click on the solution from within the Solution Explorer
Choose Save As Solution Filter
Choose a location to save the file (I saved it right next my .sln file)
This will add the .slnf to your recently opened solutions list so you can either open from there going forward or navigate to the .slnf file and double-click it.
If you still want to see your unloaded projects after opening the .slnf, highlight the solution from within the Solution Explorer and click the Show All Files icon.
Base on this if you want to share your load/unload setting via source control you can use solution filter file which is .slnf extension.
So when you open the .slnf file instead of .sln file you will see the filtered project are loaded.
On MacOS with Visual Studio 2022 for Mac (i.e. v17.0 Preview, "Visual Studio Community 2022 for Mac Preview") I do not see either .sln nor .slnf files.
I observe that unloaded projects are saved in folder /.vs/[SolutionName]/xs/UserPrefs.xml. And when I close Visual Studio 2022 for Mac, I see that UserPrefs.xml is saved.
UserPrefs.xml Snippet:
<DisabledProjects>
<String>...</String>
</DisabledProjects>

Create a physical copy of a source file in Visual Studio

In Visual Studio, if I try to copy a file from one project to another (by using Copy and Paste or by dragging the file to the new project while holding the Ctrl key) it creates a reference to the source file in the original location. Is there a way to create a physical copy of the source file and place that in the target project source direction without having to resort to using Windows Explorer to copy the file manually?
It's not pretty, but when I want to do what you're suggesting, I double-click on the file in Visual Studio, which opens it. Then I do a File->Save As, choose the right directory and save it. All from within Visual Studio. This is usually followed by adding the new file to the other project.
Was just doing this and realized I should mention a side-effect. Depending on your source control (in my case, TFS 2010), doing this from within Visual Studio may modify the location of the file in the project. For me, this means making sure that neither the file nor its project have any pending changes, doing the save as, then doing an undo of the change this causes in TFS 2010 (project change, file add and delete).
From http://msdn.microsoft.com/en-us/library/0fb6xxhb.aspx:
If you are working with solution items, Visual C++ projects, or other similar projects, you are always working with links in Solution Explorer. If you are working with Visual Basic projects, Visual C# projects, and other projects, you might be working with links or files.
Essentially, the answer to my question is 'No'. In most cases, I must use Windows Explorer.

Visual Studio 2010 - .Sln file when clicking on .csproj

I can open my project by double clicking on the .csproj file. It opens fine and it doesn’t generate a .sln. If I copy the same project to a virtual machine and do the same it opens but creates a .sln file.
I really don’t need a solution I would prefer to only work on a single project.
Am I missing something here?
Visual Studio always creates a solution. If it cannot find one in the same folder as the .csproj file then it will create one itself, based on what it can reverse-engineer from the project file content.
The solution is hidden by default if the solution only contains one project. Fixing this is recommended: Tools + Options, Projects and Solutions, General, "Always show solution" checkbox.
There is always a solution, even if you don't see it. There's a setting that determines whether the solution is visible when there is only one project.

Visual Studio 2008 always saves SLN file on exit

Got a bit of a weird problem. I'm checking a solution out of TFS source control, and not making any changes to it; just opening it using the SLN file. If I then close Visual Studio (or do a Save All), Visual Studio prompts me to save the SLN file. Even if I do (by overwriting it, it's a read-only file), it continues to do this every time I open and close the solution, as if I'd added a project or something. Why would Visual Studio do this? What's causing it to think the solution has changed and needs saving?
OK, problem solved. As we're using TFS for source control, you're meant to check in the SLN file's corresponding .vssscc file. As we'd checked in the .vspscc for the various projects the SLN file pointed to but not the SLN's .vssscc file, Visual studio didn't consider the solution to be bound. :-)
Fixed it by going to File | Source Control | Change Source Control, then binding the SLN file to the solution's root dir on the TFS server. This created the solution's .vssscc file, which we've checked into source control. Subsequent checkouts now don't cause the problem.
I would start by letting it save the solution and then doing a visual diff of the version that it saved vs the one held in source control to see what the problem is. It could just be white space formatting. Also, are you the only person suffering this (if others are using the same solution?)

Resources