How to silently provide initial settings for Visual Studio - visual-studio

I'm looking for a way to provide initial settings for Visual Studio 2017 through a script. Copying a *.vssettings file to the %USERPROFILE%\Documents\Visual Studio 2017\Settings path doesn't work since Visual Studio will rewrite the file on startup while creating a user profile.
There is the /resetsetting switch vor devenv.exe which can be used to reset the settings to a specified .vssettings file, but this will also open Visual Studio IDE.
Is there a way to silently provide initial settings for Visual Studio from a PowerShell script? Or any safe way to detect at which time Visual Studio has created the profile and imported the settings when using /resetsetting, so that the devenv process can be killed?

When using /resetsettings, you could:
Check whether default settings file exists. Get modified date if it does.
Run devenv.exe /resetsettings <filepath> The modified date on the default settings file will be changed to match the file specified.
Check modified date has changed, or file now exists.
Close devenv.exe
I've given this a go; the settings file after step 3 isn't identical to the one specified in /resetsettings, although it's clearly different from the previous default one. I don't know the criteria for which tags are kept.
Related, not a PowerShell solution: A team settings file can be specified by going to Tools > Options > Environment > Import and Export Settings. More info on Enviornment Options.
Note from link: "When applied, these team settings would not override any category not specified in the .vssettings file"

Related

Reset Visual Studio 2022 Extension to its default settings

I am the user (not the developer) of a Visual Studio 2022 extension which correctly uses the built-in WritableSettingsStore to store its settings (I verified this by looking at the extension's source code).
After extensively playing around with the extension's settings, I would like to restore it to its original state. Uninstalling and reinstalling didn't help, my modified settings were retained. I also don't want to reset all my Visual Studio settings or remove my complete user profile, I just want to reset this one extension.
Hence my question:
Where does the WritableSettingsStore physically store a Visual Studio Extensions's settings?
It's stored in the same place where Visual Studio stores its own settings: in Visual Studio's private registry hive.
Open the private registry hive with regedit.exe as described in the following question. Note: The correct path for Visual Studio 2022 is %LocalAppData%\Microsoft\VisualStudio\17.0_71c0f998\privateregistry.bin.
Access Visual Studio 2017's private registry hive
The extension's settings are stored in the subkey Software\Microsoft\VisualStudio\17.0_71c0f998\NameOfTheExtension. Remove that key to reset the extension to its default settings.
Don't forget to unload the hive as explained in the link in step 1.

VS2013 create new class from template

Hi is this possible to create some template for Visual studio, that when I create new class it will contains some description in header ?
On Visual Studio 2012 you could do something like this:
Find the files
C:\\Microsoft Visual Studio 11.0\Common7\IDE\ItemTemplates\CSharp\Code\1033
The file you want is in an appropriately named folder. If you open the Class folder you will find the following 2 files:
Class.cs
Class.vstemplate
Backup the original files
Change the Class.cs template file
Save your changes
Tell Visual Studio about the changes
Your new changes will not be loaded unless you explicitly tell Visual Studio to reload all templates.
Close Visual Studio (or the change swill not show until next time you run it)
Open a command prompt (you should run this as Administrator if you are not an admin of the machine).
Change to the IDE folder a few levels above the template folder (e.g. to C:\\Microsoft Visual Studio 10.0\Common7\IDE)
Run the following command:
devenv.exe /installvstemplates

Visual Studio 2010 - How to enable prompt to delete file from disk when removed from project?

In Visual Studio 2005, when you remove a file from a C++ project (by right-clicking in the Solution Explorer and selecting "Remove"), it asks you whether you just want to delete the reference, or also delete the file itself from disk.
In Visual Studio 2010, this prompt seems to have disappeared (or I have accidentally turned it off). This means that every time I delete a file in the Solution Explorer, I have to immediately hunt it down and delete it with Windows Explorer (otherwise I'll forget and it will stay around forever). How do I get the prompt back?
I found some documentation (http://msdn.microsoft.com/en-us/library/0ebzhwsk%28v=vs.100%29.aspx) explaining the difference between "Remove" and "Delete", and that "Delete" doesn't exist for C++ projects (but no reason is given). Maybe it's really just not possible? If so, what an annoying regression.
You get the remove or delete file dialog only if the selected file is stored in the project folder. If the file is stored outside of the project folder the file reference is removed without dialog.
This behaviour is still the same for e.g. VS2013. I created a user voice request to change this behaviour here. IMHO your file hierarchy should not make any difference.
You can vote for the change here:
http://visualstudio.uservoice.com/forums/121579-visual-studio/suggestions/9146353-remove-delete-dialog-should-show-up-when-deleting
Assuming one is using Sourcegear Vault as the source control system, you can enable the prompt by going to Tools -> Options -> Source Control -> Integration Options -> and check on "Show warning before deleting items from source control"

How to debug Visual Studio extensions

I'm just writing a VSIX extension for Visual Studio 2010 and can't figure out how to debug it.
One obvious method is to output messages. Extension template uses Trace.WriteLine(). But where to find it's output?
Visual Studio Extensions can be debugged like any other application. You just need to setup the debug experience to launch devenv with the loaded extension. Try the following
Right click on the project and select Properties
Go to the Debug Tab
Click on the radio button for Start External Program. Point it to the devenv.exe binary. On my machine it's located at
C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE\devenv.exe
On a non x64 machine though you can remove the " (x86)" portion.
Then set the command line arguments to /rootsuffix Exp. This tells Visual Studio to use the experimental hive instead of the normal configuration hive. By default VSIX extensions when built will register themselves in the experimental hive.
Now you can F5 and it will start Visual Studio with your VSIX as an available extension.
The accepted answer by #JaredPar is technically correct, but suffers from the fact that you need to redo it for every developer, every time you get a fresh copy of the code, and any time the csproj.user file is deleted. When you do it that way, the settings are saved in the csproj.user file.
A better option is to put the settings in the csproj file so they are not lost. Unfortunately, Visual Studio does not allow you to do this automatically, so you need to manually add the settings. Luckily, the settings are the same for any project.
Right-click and unload the project, then right click again and edit the csproj project file file. In the XML, add the following to the first PropertyGroup, for example right after TargetFramework.
<StartAction>Program</StartAction>
<StartProgram>$(DevEnvDir)\devenv.exe</StartProgram>
<StartArguments>/rootsuffix Exp</StartArguments>
This has the following advantages;
It sets it up for debug and release
It runs whatever version of Visual Studio you are currently running
It is checked into source control, so every developer doesn't have to remember how to do it :)
As #MBulli states in the comments, if you have made the changes in the accepted answer, delete your *.csproj.user file because the settings in it will override the ones you added to the main csproj file.
The OutputWindowHelper.OutputString method writes to the 'General' output window pane (Ctrl Alt o). I added this line in my .csproj references to get this in VS 2013
<Reference Include="Microsoft.VisualStudio.Services.Integration, Version=12.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL" />
Also see this answer.
If you try to debug a UnitTestExtension, you should also attach the debugger to the vstest.*.exe processes like descibed here. Otherwise you might see the activate breakpoint but the debugger will never hit it.

Resetting a Visual Studio C++ project's settings

I changed some parameters in a Visual Studio C++ project, and now I don't remember how to "go back". Is it possible to reset the build settings?
I don't mean the IDE settings (menu Tools -> Import and Export Settings).
Am I the only person that can read?!
The only way I know how to reset a "Parameter in a Project's Settings",,,
Is to open the Project file(csproj, vcxproj) with a text editor, and remove the block defining that parameter.
If you wanted to reset the Allow Isolation value, you would delete this text.
<AllowIsolation>true</AllowIsolation>
When project files are loaded by visual Studio, values which are not explicitly defined in the file, are assumed to be using the default. This will only work if the property has a default value(can't change some).
NOTE: This is NOT the same as Deleting the value from the Project Properties Dialog in VS. That method writes a blank value to your project file.
The command "devenv /resetsettings" will restore Visual Studio back to its original factory state.
You can find list of devenv switches here.
You may be able to get the previous/saved version of your Visual Studio project (*.vcproj) from your software version control system.
As many wrote here before, there is a need to reset your visual studio to default settings. Just follow this: https://msdn.microsoft.com/en-us/library/ms247075(v=vs.90).aspx
Here is the awful method I used in Visual Studio 2022.
In "Property" pages, expand the individual configuration you want.
Click "All Options" and find the bold options you had changed.
To restore the defaults, click the options and select "<inherit from parent or project defaults>".
Click "Apply", then it will recover its original value.
Otherwise, you can compare the *.vcxproj with the project templates.

Resources