How can I get the value of %vsspv_visualstudio_dir

2019-07-23 09:03发布

VS2015 Update 3

In my external application I need to get the User project templates location and User item templates location settings values for VS2015. Then I will add my templates into that directories.

enter image description here

The HKEY_CURRENT_USER\SOFTWARE\Microsoft\VisualStudio\14.0\Profile\AutoSaveFile parameter contains the %vsspv_visualstudio_dir%\settings\CurrentSettings.vssettings value.

enter image description here

Inside of that file the necessary values also contains the %vsspv_visualstudio_dir% variable:

<PropertyValue name="ProjectTemplatesLocation">%vsspv_visualstudio_dir%\Templates\ProjectTemplates</PropertyValue>  
<PropertyValue name="ProjectItemTemplatesLocation">%vsspv_visualstudio_dir%\Templates\ItemTemplates</PropertyValue>

How can I expand the %vsspv_visualstudio_dir% variable? The Environment.ExpandEnvironmentVariables(String) method can't expand it:

var str = Environment.ExpandEnvironmentVariables(
    "%vsspv_visualstudio_dir%"); // I get the same string

2条回答
淡お忘
2楼-- · 2019-07-23 09:30

A other problem and his solution. This post was the tipp for to solution - thanks.

The variable %vsspv_visualstudio_dir% is associated by default with the default directory "Documents".

Problem: If the default directory "Documents" does not exists (because it was removed via registry, wasn't a good idea), so the settings are not accepted or saved in MS VS Setting, Projects and Solutions, Locations. Next new start of MS VS lost this setting.

Solution: Restore default directory "Documents".

Test: MS VS reseting section "General" to default setting without fault.

It was a long way to find out why the MS VS Setting is not saved.

查看更多
forever°为你锁心
3楼-- · 2019-07-23 09:53

The locations of project and item templates folder for current VS2015 user profile can also be found in the following registry keys:

HKEY_CURRENT_USER\SOFTWARE\Microsoft\VisualStudio\14.0\UserProjectTemplatesLocation
HKEY_CURRENT_USER\SOFTWARE\Microsoft\VisualStudio\14.0\UserItemTemplatesLocation

Those values do not contain any variables and so can be used as is.

查看更多
登录 后发表回答