Click here to Skip to main content
16,018,637 members
Articles / Visual Studio
Tip/Trick

Saving Visual Studio Settings for All Your Projects

Rate me:
Please Sign up or sign in to vote.
5.00/5 (5 votes)
17 Apr 2024CPOL2 min read 8.5K   13   2
How to use a .props file for your custom user settings across all your projects
This tip shows how to use a custom *.props file to save custom settings across all your Visual Studio projects. This method works for C++ projects and the technique should also work for C# and other projects although it is untested with them.

Introduction

I have some custom settings that I use in all my projects. Resetting them every time I start a new project, especially test projects, can be a real pain. The solution is a custom user *.props file. I only do C++ projects so your mileage may vary.

How it works

All settings that are set via the project properties wizard in visual studio are saved in a <project_name>.vcxproj file in the project folder. 

That file will have a section like as follows, one section for each possible build configuration:

<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
    <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
  </ImportGroup>

This instruction is telling visual studio to import a user.props file. 

UserRootDir is C:\Users\<name>\AppData\Local\Microsoft\MSBuild\v4.0\

Platform is either Win32 or x64

So the files it is looking for, if they exist, are:

C:\Users\<name>\AppData\Local\Microsoft\MSBuild\v4.0\Microsoft.Cpp.Win32.user.props

and/or

C:\Users\<name>\AppData\Local\Microsoft\MSBuild\v4.0\Microsoft.Cpp.x64.user.props

You can create these files if they are not there already.

I got both these files and they are identical. The contents are:

<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
    <ImportGroup Label="PropertySheets">
    <Import Project="G:\pja\Property Sheets\PJA.props" />
  </ImportGroup>
</Project>

In my case all they do is import my own custom PJA.props file that I have saved in my own working folder.

The contents of which is:

<?xml version="1.0" encoding="utf-8"?>
<!-- PJA.props -->
<!-- contains my own custom project settings -->
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<!-- Add my include and lib folders to the default include and lib paths -->
  <PropertyGroup>
    <IncludePath>G:\pja\include;G:\Boost\boost_1_72_0;G:\elmax-0.9.5b\PortableElmax\PortableElmax;$(IncludePath)</IncludePath>
    <LibraryPath>G:\pja\lib;G:\Boost\boost_1_72_0\stage\lib;G:\elmax-0.9.5b\PortableElmax;$(LibraryPath)</LibraryPath>
  </PropertyGroup>
<!-- Set the default C++ language version to C++20 and C language version to C17 -->
  <ItemDefinitionGroup>
    <ClCompile>
      <LanguageStandard>stdcpp20</LanguageStandard>
      <LanguageStandard_C>stdc17</LanguageStandard_C>
    </ClCompile>
  </ItemDefinitionGroup>
</Project>

Now anytime I start a new project, it automagically has my own include and library folders specified. I also have the C and C++ language settings set to use C17 and C++20.

Now if I need to change or add something I can just simply edit my own props file and have it all work.

To find out which settings I need to enter, and the proper syntax of the entry, I would make the change in the Visual Studio property wizard and then search the *.vcxproj file for the changed setting. Then copy that setting to my PJA.props file.

Other Languages

I am sure this technique would work with other languages in Visual Studio. C# uses a *.csproj file which where you should be able to do the same thing. I have not tried it though as I do not use any other language.

Point of Interest

Figuring this out was kind of fun. It involved reading the vcxproj file. Lots of frustrating googling with most results saying this could not be done. And lots of trial and error with Visual Studio refusing to run properly if a mistake was made. I wrote this tip for myself as a reminder on how I did this, and maybe someone else may find it useful.

History

April 4, 2024 - Posted.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
President
Canada Canada
Father of two, brother of two, child of two.
Spouse to one, uncle to many, friend to lots.
Farmer, carpenter, mechanic, electrician, but definitely not a plumber.
Likes walks with the wife, board games, card games, travel, and camping in the summer.
High school graduate, college drop-out.
Hobby programmer who knows C++ with MFC and the STL.
Has dabbled with BASIC, Pascal, Fortran, COBOL, C#, SQL, ASM, and HTML.
Realized long ago that programming is fun when there is nobody pressuring you with schedules and timelines.

Comments and Discussions

 
PraiseWell written Pin
Midnight48924-Apr-24 2:38
Midnight48924-Apr-24 2:38 
GeneralMy vote of 5 Pin
Ștefan-Mihai MOGA19-Apr-24 10:29
professionalȘtefan-Mihai MOGA19-Apr-24 10:29 
This is a great inspiring article. I am pretty much pleased with your good work. You put really very helpful information. Keep it up once again.

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.