VSCode: moving files out of appdata directory - windows

I'm on a company laptop and appdata has restricted storage space. An initial google showed there isn't really any settings to move directories. I was thinking of simply copying relevant directories i.e. \AppData\Roaming\Code to somewhere else, then creating a hard symbolic link (junction) with the same name and then point it to the same location
i.e. in command line:
mklink /J C:\Users\me\AppData\Roaming\Code C:\myFolder\Code
I played around with moving the whole appdata folder (right click on roaming/local/locallow then click on properties then location tab then change directory). I managed to only move half the files over. it seemed to work until i restarted and it caused chaos.
I don't want the same thing to happen again with vscode. (that said I haven't tried using a symbolic link for appdata
what is everyone's advice? can i create a symbolic link and have everything work fine? or will i cause more chaos again? if it works for vscode, i'd like to do the same for appdata too

Portable Mode in Visual Studio Code
You can use Portable Mode: After unzipping the VS Code download, simply create a data folder within Code's folder
After first launch 2 folders will be generated inside:
..data\extensions
..data\user-data
Then you can copy your company folders with files from
%APPDATA%\Code\User\
Then copy the extensions directory to data:
%USERPROFILE%\.vscode\extensions
Portable mode is not supported if you install VS Code. It is only supported if you get the ZIP download.

Symbolic links should work, but you can also tell VS Code to use a custom extension and user setting location with the --extensions-dir and --user-data-dir flags respectively
$ code --extensions-dir "/User/me/vscodeExtensions" --user-data-dir "/User/me/vscodeData"
There are some key limitations to this approach, such as extension updates not working. We are tracking support for a truly portable VS Code here: https://github.com/Microsoft/vscode/issues/329

Related

Restore deleted files in visual studio code in the code management menu

I am really devastated because I have accidentally deleted 3 of my files in Visual Studio Code. I did it through the Source Code Management menu on the left side. Now my question... Is there any possibility to restore the 3 files I deleted like this? I would appreciate any answer and maybe you want to know: I use Windows
:-(
I tried to look into the recycle bin of windows but it isn't there. :-(
vscode maintains a file-history using its latest TIMELINE view.
How to restore deleted git-untracked files in vscode:
Create the files with the same name at the same directory.
Go to TIMELINE on the File Explorer.
You can get the older versions of the files.
No, you cannot recover those files using VS Code or standard tools. They aren't put in the recycling bin (or your operating system's equivalent), they are removed using git cleanor git reset --hard. Condolences :-(
There are of course utilities for recovering deleted files that may or may not be successful, but that is outside the scope of this question.
I accidentally removed a file that wasn't even checked in to git. Google brought me here. The file wasn't in the Trash can either (Ubuntu 18.4 VS Code 1.31.1). Looking at the git output I can see that it used git clean -f to remove it by force).
Fortunately the file was still in the editor. Just press Ctrl+P and type the file name. It should show up in the list of files and if you open it, it says "FILE_NAME (deleted from disk)" on the tab. Just copy/paste the content to where it should be.
if you accidently click the delete menu option right below rename, as long as you don't panic and like restart your computer or something you can open that directory in the file explorer on your computer
and right click.
there should be options there to undo delete or whatever else you did to the directory.
Open VSCode's command menu, and type "Local History" and select "Local History: Find Entry to Restore." Then type the name of the file you deleted.
This has worked for me when "undo" in the file tree has not.
Super easy, and has saved me from despair.

Is there a way to transfer a VS project to another computer and keep all the same files open?

I frequently take projects between work and home on a flash drive. I zip up the project with 7zip, take it to the new computer, delete the old project, and extract the newer version. But after doing this the solution doesn't open the files I had open previously like it normally does when re-opening a solution without replacing it with a new version.
The 7z file does include the hidden .vs folder which I believe is where the list of open files is supposed to be saved.
My Task Canvas extension automatically saves open files on solution closing and restores them when you reopen the solution. It works with relative paths and information is saved to a .TaskCanvasSL file in the solution directory.
(But this is just one feature and doesn't justify purchase if you don't need the whole code fragments and tasks concept.)

Change Visual Studio Emulator for Android vhd install path

Is it possible to change the default path that the VS emulator is storing the .vhd files? By default it's set to store them under my %LOCALAPPDATA% folder, but that's on my C drive and I'm running out of space on C.
How can I set it to store them in D:\emulators?
#Ionian316
1/ Open regedit.
2/ Go to: HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\VisualStudioEmulator\Android\Configuration\
3/ Find file UserConfigurationPath
4/ Input your path in here:
Default path is: %LOCALAPPDATA%\Microsoft\VisualStudioEmulator\Android
New path example: D:\VisualStudioEmulator\Android
Of course, you should copy from default path to new path for not be error.
EDIT 1
There is a solution pointed in VS Emulator for Android troubleshooting (link):
Open Registry Editor by selecting Run from the Start buttons context menu, typing regedit in the dialog box, and choosing OK.
Navigate to HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Android SDK Tools in the folder tree on the left.
Modify the Path registry variable to match the path to your Android SDK.
However, this solution seems out-of-date for current available VS Emu 4 Android versions. I can not find the registry folder in the tree.
EDIT 2
Here is a simple way to do, by which I managed to change the root Path of vhd.
Situation 1: Already installed
Rename folder %USERPROFILE%\AppData\Local\Microsoft\VisualStudioEmulator\Android\Containers\Local\Devices\vhd\ to something else, for backup.
Create folder D:\emulators.
Open cmd command-line, type in MKLINK /J %USERPROFILE%\AppData\Local\Microsoft\VisualStudioEmulator\Android\Containers\Local\Devices\vhd\ D:\emulators, press Enter.
After junction made, move everything in backuped vhd folder to D:\emulators.
You've done.
Situation 2: Not installed yet
The steps are similar to those in Situation 1, but you do not need to rename for backup, nor move the backuped stuff to D:\emulators.
You just need to make the junction, and then install VSEmu4Android.
EDIT 3
NOTE:
For proper usage of vhd's in Hyper-V (which is used by VSEmu4Android), your D:\emulators folder and files inside should not be compressed.

How to create Explorer Shortcuts to specific TFS 2010 Source Control Paths

We are slowly moving projects from old file based storage (don't ask) to tfs. Our coders are still used to find the code in the file System.
Since we are talking about 100 Projects each with some sort of history, we have to move them carefully one by one. Resulting that we will have to live for some time with the already existing file structure mixed with the TFS managed files.
To make life easier for our coders, I would like to create a shortcut in the filesystem, for each project that we moved. So the developers can look up if the Project has already been moved, and if yes, go by double click to open up the TFS Source Control Explorer pointing directly to the correct Project.
Is this possible? Thanks for your Response.
I found a simple solution for my needs, which is based on a small batch script, that you'll have to click. It's not a shortcut so to say even though you can still create a shortcut of the batchfile.
Here's the script:
CALL "%VS100COMNTOOLS%\..\..\VC\vcvarsall.bat" x86
REG ADD "HKCU\Software\Microsoft\VisualStudio\10.0\TeamFoundation\SourceControl\Explorer\<GUIDofTFS>" /v "SceMostRecentPath" /d "$/<PathToTfsProject>" /f
devenv /Command View.TfsSourceControlExplorer
In fact I combined 2 ideas found in separate sources:
1. Start VS with Source Control Explorer
2. Manipulate Registry to open Source Control Explorer in a specific path
With the command devenv /Command View.TfsSourceControlExplorer you can actually start VS and automatically open Source Control Explorer. Unfortunately there is no way to give a parameter to point it directly to a location you wish. But I noticed that VS2010 seems to persist the last used path and reopens to that place on restarts. A quick research resulted in the registry entry
HKCU\Software\Microsoft\VisualStudio\10.0\TeamFoundation\SourceControl\Explorer\058104ed-f0e2-4126-9ccc-0e37e19c4f91\SceMostRecentPath
By manipulating the value of SceMostRecentPath you can trick VS2010 to open Source Control Explorer with the path in there.
Keep in mind: You will need to replace 058104ed-f0e2-4126-9ccc-0e37e19c4f91 with the GUID of your TFS Installation.
Since we are all using VS 2010 but the installation paths differ, I implemented the path dynamically by making use of the VS100COMNTOOLS variable. First we set up the TFS command line environment:
CALL "%VS100COMNTOOLS%\..\..\VC\vcvarsall.bat" x86`
Then we change the registry:
REG ADD "HKCU\Software\Microsoft\VisualStudio\10.0\TeamFoundation\SourceControl\Explorer\[PutYourTfsGUIDHere]" /v "SceMostRecentPath" /d "$/<YourTfsPath>" /f
Finally we do a simple call of devenv.exe with the source Explorer command:
devenv /Command View.TfsSourceControlExplorer
Until they're mapped to a local file path, I don't think this is possible. Though there might be an undocumented way to craft a vstfs:///VersionControl/LatestItemVersion/{itemid} link that might work, I haven't been able to craft one that does the trick.
You could create a powershell script that would check for the local mapping, otherwise ask them where they want to put it and setup the mapping, do a get-latest and go from there...
A bit of trickery with the tf commandline should get you pretty far.
tf workspaces /owner /collecion /computer to see whether there's a local workspace to the right team project.
tf workspace /new /collection to create one if needed
tf workfold /map to create a folder mapping, you could prompt them for a target location
tf get to fetch the latest sources.
Place the .ps1 file in the folder and when opened check for the workspace, if it's there open the local files in the mapped folder. if it isn't, go through the workspace mapping process by invoking the right commands.

Visual Studio Solutions Folder as real Folders

I have a Visual Studio Solution. Currently, it is an empty solution (=no projects) and I have added a few solution folders.
Solution Folders only seem to be "virtual folders", because they are not really created in the Filesystem and files inside solution folders are just sitting in the same folder as the .sln file.
Is there a setting that i've overlooked that tells Visual Studio to treat Solution Folders as "real" folders, that is to create them in the file system and move files into it when I move them inside the solution into one of those folders?
Edit: Thanks. Going to make a suggestion for VS2010 then :)
There is a workaround, that actually behaves as expected.
Add a New or Existing Web Site to the Solution. (I usually create a new one.)
Just make sure it's created inside your solution folder. (I sometimes even create a "link" to an external folder, e.g. 'Docs' or 'Marketing' on a network share. In that case it's ignored by Git of course.)
Make sure to go to the "Project" settings or Configuration Manager to exclude this "Web Site" from Build and Deploy!
Done. Now Solution Explorer will reflect any change in the file system and vice versa (including subfolders).
I (miss)use it for specs, docs, PM and some DevOps scripts that are shared within the team. It's easy to choose, what to include in source control or not, and (if set up correctly) it doesn't conflict with build.
I know the feature is not intended for that use case, but except for the maybe misleading "Project" icon I didn't find any shortages to that hack yet. And there still are use cases where the classical (virtual) Solution Folders that VS provides, fit in the picture. What do you think?
No special setting. I don't think it's supported.
You can create real folders in a "project" within the solution, but not in the solution itself.
In Visual Studio 2017, click on the "Solutions and Folders" icon in the Solution Explorer window. This button toggles from the virtual "solution" view into a "source view" that matches the layout of folders and files on the file system. When you add a new folder, the folder is physically created in the expected location.
.
The chosen answer suggests it would be possible to use actual projects instead of solution folders, but does not really explain how. I guess what I'm describing here is possibly the least awkward way of achieving that... :-P
The problem with regular project files is that they eventually will be compiled by MSBUILD. And if you want have a project which only contains non-compilable files, that will be an issue.
But some time ago Visual Studio introduced a new project type: Shared Project (.shproj extension). This project type does not get compiled by default, but only when (and only if) it is referenced by another project.
So one part of the trick here is to use shared projects instead of solution folders. It's obviously possible to add a shared project that is never referenced by any other project, meaning we can avoid the issue presented above.
Then, by using <None Include="**/*" /> clause in the .shproj file, we can make it automatically reflect any new files and/or subfolders.
So basically do this:
Create a new folder in your solution.
Add a new .shproj file at the root of this new folder.
Reference the new .shproj in your solution.
For instance, in my case, I've created a DockerDev.shproj, so I can group some docker-related scripts that we run only in our development machines:
<?xml version="1.0" encoding="utf-8"?>
<!-- DockerDev/DockerDev.shproj -->
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<None Include="**/*" />
</ItemGroup>
</Project>
This .shproj file will keep track of any file, in any subfolder of this new DockerDev folder in my solution.
As far as I could see, this solution works pretty much like what the OP requested: it will work as a non-compilable reference to a folder, and it will automatically reflect any changes made to it.
Sara Ford contributed a Macro to add do this. In Visual Studio 2010, if you open your Macro Explorer, you will see a macro called "GenerateSlnFolderOnDirStructure." This will automate the creation of the Solution Folders and add the files.
Folder To Solution Folder By Cecilia Wirén - CeciliaSHARP
Remove the hassle of adding several files to solution folder. Just use the context menu for the solution and just below the option of creating a new solution folder you now find 'Add Folder as Solution Folder'. This will create a solution folder with the same name as you selected and add the items inside of that folder to the solution folder. This will not move the files on disk.
You can just sync your new solution folder nesting level and also name with the actual filesystem folder and it works like a charm!
Existing project :
Create the actual folder
Create the solution folder with the exact same name
Copy your project folder into the new folder (Actual file system)
(in solution explorer) - Righ-click on same folder
Add => Existing project
Add new project :
Create your solution folders
(Right-click on solution) => Add new project
Change the Location address under the project name you want to add, to the exact same address in your solution folders
No, it's not supported. As you suspected, solution folders are simply virtual subentries in the .sln file, nothing to do with the file system.
For C# in Visual Studio 2019 I used this way (Seems to be similar to this answer, but that didn't work at least in C# solutions)
In solution explorer click on switch views
Choose folder view
You can add individual folders to the solution
To get back to the regular view of solution explorer just click switch views again and choose the solution.
There seems to be a limitation using this way (comment from #montonero):
... just open a solution with multiple projects and try to move the projects to some other real folders through the folder view. The issue is VS doesn't update paths to projects in a solution file
Visual studio has no support for this. I made an extension that does something similar for VS2013 though. It maps solution folders to physical folders on your hard drive, though the mapping is one way (from hard drive to solution). That means a solution folder's contents will reflect the hard drive folder's contents, and not the other way.
With that out of the way, the extension may still be useful.
It has support for mapping solution folders to physical folders, filtering files and directories based on regex, and remembering mappings in your .sln file. Properties are non-intrusive so developers without the extension can still open the sln and not be affected.
Hosted on visual studio gallery:
https://visualstudiogallery.msdn.microsoft.com/69e19ea6-4442-4cb6-b300-044dd21f02bd
Edit: Uploaded to bitbucket. Now open source. MIT license. https://bitbucket.org/LSS_NorthWind/physical-solution-folders
Create "Solution folder". This will create logical folder, but not physical one.
Right click to the solution folder and open a new project dialog. But before you click OK, you have to change a project location to your desired physical folder and VS will create it and place the project inside.
Create an empty solution then
open .sln file in an editor
and put these lines of code after MinimumVisualStudioVersion
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{9D8C3BB1-AEDB-4757-8559-995D12A4E6D0}"
open the solution in vs and you should add the same folder to it
now you can see the folder and add a project to it
you have a real folder in windows and a virtual one in vs
be sure that you
created the projects with that path
You can add real folders by choosing "Add new filter" for a Visual Studio project file. You can also do "Add new filter" under an existing folder. Once the folder is created, rename it and add source or header file or whichever suits your project. This is one way I know which lets us create real folders through the Visual Studio IDE.
I've wanted this feature a few times myself, but at the end of the day, you really do NOT want the ability to do this. Think of your Solution (file) as as the root of a web application and think of Solution folders as Virtual Directories (literally and functionally). The contents of a web virtual directory could be physically on a different server altogether. Where Visual Studio muddled up the solution folders concept is by allowing you to create new files inside the folder. You should always "Add Existing" when adding content. When you add existing, it creates a link to the source location of the file.
But as for the reason you do not want solution folders to behave like "physical" folders is because your solution layout may not necessarily use the same convention as your source control layout. Solution folders allow you to customize the hierarchy of your projects so that you can group projects and items together any way you like, and then decide you don't like it and change it again without having to go through the nightmare of moving source control items around and irritating the rest of your team.
Note: Yes this is possible you can create a folder on root but its lil bit tricky....
By giving some extra efforts you can do it How?
Lets follow the step--
1-Create Folder eg: "newfolder" on root (where your .sln file reside).
2.Copy and paste your projects inside the folder.
3.go to your sln file and find moved projects and append newfolder\ in moved project's address.
4.Save sln file.
5.Open your project and Commit the repository in git or so...
6.Take the repository on fresh location.
YOU are done...
if still you are not able to see your folder -----
1.Add a solution folder xyz.
2.Open sln file and change that folder name with your folder name.
Congrats you are done..
If you face any problem just write me for help..
The folder created underneath the solution will be virtual as said. Maybe this might be called a workaround but you can physically create the folder on disk either before or when you add new item/project and Robert should be a sibling of your dad.
ps- on closer look maybe i should explain "bob's your uncle" means your fine/sorted.
I have a bit of a workaround for this (it's not great, but it works).
Create a folder in your solution (i.e. "Contoso")
Right click on the solution and then click "Open Folder in Solution Explorer"
Create the physical folder (i.e. "Contoso") in the solution directory
Copy/Create files in the physical folder.
Drag the files into the virtual folder in the solution explorer.
It's not great because you will need to manually maintain the file references, but it works for me.
Yes, it is possible in Visual Studio 2019 for the project
Though this is an old topic, I will add my answer, because I had the same issue and searched for a solution but it seemed that everyone is 100% sure that there is no way to do it. So I started to experiment with VS 2019, tried a lot of settings, and eventually figured the way out.
1 Button :D
You only need to click 1 button - Show All Files, and you will see the physical structure of your Visual Studio Solution:
Now you can add files and folders to the project and they will be added to the file system (physically)
Right-click on your project → Add → New Folder
Note that the option changed from New Filter to New Folder
My recommendation for C++
Create a root folder inside your project's directory which will contain all the application related stuff (code, headers, data, libs... ). I name it Project
Add subfolders as you'd like to structure your code. I prefer the following layout: include, src, data, libs, etc
Now setup Visual Studio to recognize these folders as headers and sources directories.
Click on your project in the Solution Explorer. Note, in my case, it is CrazyDemo, not the Solution 'CreazyDemo' (1 of 1 project)
Go to the project properties menu: Project→Properties
Open Configuration Properties→VC++ Directories tab
Edit Include Directories and set to $(ProjectDir)/Project/include;$(IncludePath)
Edit Library Directories and set to $(ProjectDir)/Project/libs;$(LibraryPath)
Edit Source Directories and set to $(ProjectDir)/Project/src;$(SourcePath)
You may use the Scope to This option if you want to focus on 1 project. Just right-click on the Project folder and press Scope to This
Note that after this action, in order to open Project Properties you need to click on any of your project files (like main.cpp in the example) and then click on the editable client area (like when you want to change the code) and only after that you'll be able to see the Project→CrazyDemo Properties option. [Visual Studio is Insane 🤦‍♂️]
Finally, you may have a project like this

Resources