i created a little application (win forms) thats create a solution, adds a project and some files to the project. By clicking a button, the new solution should open by the installed vs2010 express. Thats works fine, everything is ok. My question, is there a way to open a specific file in the solution when the hole solution was loaded? For a better understanding, the user (of my application) creates a sln with 3 files (a.cs, b.cs and c.cs). He selects b.cs (in my application), and opens the sln. In the editor in vs, the preselected b.cs should be open.
I've tried to create a sou - file, but i think thats not the right way...
Is there a way to do this?!
Thx and regards
Sascha
Visual Studio remembers the files you had open when you last closed the solution, along with other things like breakpoints, by using the SUO file. You can check this with a simple experiment: close your solution with just a single file opened inside it (a.cs, for example), manually delete the SUO file (don't worry, VS recreates it if it doesn't exists) and when you open the solution again you'll see you won't have any file opened, and you'd lost any breakpoints you had.
So the obvious thing to do here would be to manipulate the SUO, storing on it the file selected by the user and then opening VS from your tool. The only thing I've found on the documentation is the IVsPersistSolutionOpts but I don't have any direct experience with it.
Also check this CodeProject article: while its main focus is to add a Tool Window to Visual Studio, it also uses IVsPersistSolutionOpts.
Related
Visual Studio 2017.
I have a project that have been working on for some months. Now all of a sudden whenever I open the solution, Solution Explorer will show it in Folders view. I have to click the following button and select the other option to show it in Solution view:
How do I restore it to the usual situation?
In My case,
I opened the folder where the actual files of the project are placed in file explorer.
And double click on the solution file(file with extention .sln).
It will be opened in the usual view(Solution View)
If you've copied a repo from github and created a solution, make sure you save once before switching to folder view. I forgot to save the newly created solution once, switched to folder view and as a result, could not get back to solution view. Very strange that my solution was somewhere in the void. I restarted VS 2017, recreated the solution and saved it.
By clicking on the same icon has worked for me though i found my whole solution got check out.So before clicking make a note which files are actually for checkout in TFs .
This was happening on one of my projects. I would change to Solution view, save/commit, but the next time I opened it, it was in Folder view again.
I don't know where the "last view" is stored, but apparently it's not in the .sln file.
I right-clicked on the solution and used Open in File Explorer, and opened the .sln file with VS Code and added a blank line at the bottom to "touch" the file. Then I reloaded and checked it in and it stuck.
I don't understand how it works. I'm new to Team Foundation Server and currently I have a small team. The co-worker can open my project file and run just fine (by double clicking the solution file right in the source control explorer window).
I can open my project file the same way but cannot open his project file. Clicking the solution file does load the solution but the files in there cannot be opened. It says something like this:
Cannot find the file "d:\....". It may have been moved or deleted.
The path "d:...." is actually the path on his machine. While in my machine it's mapped to a different path. But I don't understand why it cannot recognize it.
At first I thought the mapped path structure should be the same across all members' machines but if so my co-worker could have not opened my project file.
The status of the solution is Yes for Latest, meaning the files are loaded and copied to my local folder normally. Not sure if it matters but I'm using Visual Studio 2015 and my co-worker uses Visual Studio 2013.
I've tried searching around but could not find anything with the error message. It's so interesting that my co-worker does not have to do something special or self-aware so that he could tell me something to solve this. I hope you have some experience on this and give me some helpful suggestion. Thank you!
Edit:
To clarify it more, if I browse the file directly inside the source control explorer window, the file can be opened (but if it such as is some designer-supported file like .xaml - the designer then is not shown up). What I'm having trouble with is opening the file loaded in the solution (inside the Solution Explorer window). As I said clicking the solution file in Source Control Explorer window does load the solution, but because there is something wrong with the files path, I cannot open them as well as build and run the solution.
Right-clicking on the file in the loaded solution, select Properties, I can see that the Full Path is actually the path on his machine, so weird.
It sounds like your workspace is all messed up. Are you trying to share a workspace?
If so you should not. Each developer should have their own workspace local to their computer that is unique to them.
Try creating a new workspace and using that...
I'm using Visual Studio 2013 Pro, update 4, and TFS for version control. I'm not having a good time.
VS keeps insisting on checking out the solution file when I open my (multi-project) solution. It also gives an error "Unspecified Error" (thanks) for every project in the solution.
I had a hunch that the source control bindings were wrong, and indeed many of the posts online suggest unbinding and re-binding. However, the problem seems to re-appear every time I close and restart VS.
One thing that strikes me is that the solution file appears to be bound to the folder for one of my projects. If I un-bind and re-bind, then it gets re-bound to the top-level folder as I'd expect. But then when I re-start VS, it snaps back to the original binding.
Before I go chasing other potential problems, I'd just like to clear up whether it's normal for the solution file to be bound to one of the project folders (even though the file is physically located one level above all the project folders)?
Whenever I find messed up bindings I always follow the same process:
Close VS
Open the SLN file in Notepad.
Remove the GlobalSection (sometimes more than 1) that contains all the SCC elements
Check the csproj file has the 4 <Scc**> elements with a value SAK. If not update all 4 to be SAK (see below).
Open the SLN file in VS.
Select the Solution at the top of Solution Explorer
File, Source Control, Advanced, Change Source Control
Find the Solution in the list and select it.
Click the "Bind" button.
This usually sorts it for me when you re-open it, everything is OK.
The <Scc**> elements should look like this:
<SccProjectName>SAK</SccProjectName>
<SccLocalPath>SAK</SccLocalPath>
<SccAuxPath>SAK</SccAuxPath>
<SccProvider>SAK</SccProvider>
I've got two branches of code. 1 has a dialog box that the other doesn't, but because of politics the dialog box wasn't moved into the newest branch. Now they want it in...
So is it possible to copy a dialog box from one project to another.
There apears to be an export and import feature however it's greyed out.
.RC files are simple text files. You can simply copy/paste the DIALOG text from one .RC file to the other. Make sure that you copy the corresponding RESOURCE.H entries as well.
Alternatively, you might be able to open both .RC files and then simply drag-and-drop the dialog from one to the other.
Update for Visual Studio 2010 - 2013:
You can still drag-drop and copy-paste, but only outside of your project / solution.
Close solution, open both RC as files without any open solution, and go. For drag, "Hold down the CTRL key and drag the resource to the second .rc file. For example, drag IDD_DIALOG1 from Source1.rc to Source2.rc."
Microsoft - How to Copy Resources
Drag and drop doesn't work in Visual Studio 2010. Editing the .RC file does work but be careful. For me the ID for the dialog showed up with *ID_etc*. I copied it and removed the *'s and it seemed to fix the problem.
I finally figure it out how to copy a Dialog from one solution to another.
Steps:
Open both solutions in separte windows.
Add a new Blank Dialog -Add Resources-> add->newDialog
Open Both Dialogs Open Binary data.
Copy the Binary data from source solution dialog to Destination Dialog
This is just to add some visual detail to the accepted answer (by Roger Lipscombe) along with its steps.
In order to copy a resource such as a Dialog from one project another project, below steps can be followed.
Start a new instance of Visual Studio.
Open both source and destination .RC file as files, as shown in the picture.
From the source RC file, copy required dialog.
Switch to the destination RC file tab and simply paste it.
Please note that this operation would have updated the resource.h file. That is an excellent help by Visual Studio.
One will have to make sure that no duplicate resource IDs are present in the resource.h file. When working with some legacy projects, it is found that there came some duplicate resource Ids that had to be manually corrected. It looks like such an effort is worth considering the mammoth task required otherwise.
Is it possible to open a project in Visual Studio 2008 without opening all the files that were previously opened last time I had the project open. I have a habit of keeping many files open as I am working on them, so next time I open the project, it (very slowly) loads up a bunch of files into the editor that I may not even need open. I have searched through the settings and cannot find anything to stop this behavior.
Simply delete the .suo file.
It contains the list of open files.
A bit of research turns up the fact that you can do it with a macro:
Create a new macro (or use an existing one). You should see a module called EnvironmentEvents in Macro Explorer. (For details, see here.)
Open the EnvironmentEvents module.
Put in this code:
Public Sub CloseDocsOnExit() Handles SolutionEvents.BeforeClosing
DTE.ExecuteCommand("Window.CloseAllDocuments")
End Sub
Save and Build the macro.
Open a whole bunch of documents in your solution, then close Visual Studio.
Yay! No more open documents!
(Note: Despite that it says SolutionEvents, it also works if you're working on a project that doesn't have a solution.)
I never realized how much that annoyed me as well! I haven't been able to find a setting, but in Options > Environment > Keyboard you can bind a shortcut to Window.CloseAllDocuments. ALT+X was unbound for me so I just used that. I'm interested if there's some hidden setting to automatically do this on solution exit though (or load).
Edit: Totally read the question wrong at first - ignore my first (now gone) answer. :)
I changed the keyboard mapping for CTRL-SHIFT-C from bringing up the Class View to closing all document windows - something I use several orders of magnitude more often - and then I just clear my workspace before closing a solution.
Try the following:
Close the program after closing all files.
Make a copy of [whatever].suo
Open the solution again, open some files, and exit.
Copy (don't move) the old .suo file over the one that was just generated.
Make the .suo file read only.
If you have a repository you might want to check that file in.
I suggest this because I was having the reverse problem, where it wasn't opening my old files automatically, and the cause was a .suo file that had been checked into the repository and was (for some reason) not being overwritten by Studio. The file wasn't even write protected.
I was hoping for something a little more automatic. VS will create a new .suo file every time the project is saved. So I would have to delete that file every time I open the project. I also don't want to have to remember to close all the files before closing VS.
Other IDEs that I have used have similar functionality, but also make it rather simple to turn on/off.
Thanks for your help.
Or you can close all open document from the Window menu before closing VS.
In Visual Studio 6.0 (VC++), the procedure is slightly different.
Delete the .ncb file (located normally in the same place as your .dsp or .dsw files).
The only way works for me is : change the project location and again reopen the solutions form there. :)