How to achieve that properties set in Myprops.props override those set for the project?

Fred Verhoeckx 0 Reputation points
2024-05-06T13:21:32.1466667+00:00

I want to reuse Visual Studio 2022 project settings, but have trouble to understand the docs. There is said: "Properties in a property sheet are overriden if the same property is set directly in the .vcxproj file.

I assume that before adding a new project property sheet, all properties are set in .vcxproj. Do I have to remove a specific setting manually from there? What would e.g. be the workload when I wanted to reuse the Additional Include Directories set for a certain project that has no added property sheet yet?

If I take the docs literally, I have to start from scratch with defining properties in added property sheets.

A walkthrough example would be very helpful.

Visual Studio
Visual Studio
A family of Microsoft suites of integrated development tools for building applications for Windows, the web and mobile devices.
4,675 questions
0 comments No comments
{count} votes

4 answers

Sort by: Most helpful
  1. Michael Taylor 49,076 Reputation points
    2024-05-06T14:55:46.8133333+00:00

    I'm not sure the title of your post matches what you're asking so I'm a little confused as to what you're trying to accomplish. In general the project file is loaded and then additional .props files can override it. However it depends on when the .props file is loaded. For example the common .props files are loaded after the property sheet values. Open a project file in an editor and you can see where all the property sheet values are set first and then the common C++ files are loaded next. The inheritance is defined here.

    If you want to "append" to an existing property then you can do that by using the variable as part of your assignment. For example if there is a property called $(IncludePath) then you can append to it by setting the value to $(IncludePath);C:\somenewpath. The existing files do the same thing so if you change the include path in the property sheet then the common files will append to that.

    If you need to share stuff across projects then consider using the directory.build.props. This is the recommended approach. If you need this across solutions then put it into the environment variables for the system/user instead.


  2. Fred Verhoeckx 0 Reputation points
    2024-05-06T16:43:06.09+00:00

    I found this: https://www.youtube.com/watch?v=Mi30QBxhjZU

    will have a look there, to see if it helps...

    EDIT: this probably helps to understand the principles. However, it is not one of the methods described in Microsoft's docs. I'll skip this approach for now.

    0 comments No comments

  3. Anna Xiu-MSFT 26,481 Reputation points Microsoft Vendor
    2024-05-07T07:18:15.7333333+00:00

    Hi @Fred Verhoeckx

    Welcome to Microsoft Q&A! 

    I suppose you can export the existing project as a template and import it into Visual Studio. It will export the properties of this project.

    Then, you can select the project template to create a new project. 

    For more details, please refer to: Create project templates

    Sincerely,

    Anna


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".  Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

     


  4. Fred Verhoeckx 0 Reputation points
    2024-05-14T08:22:26.31+00:00

    Hi Anna,

    I recieved a notification for a message by you. Unfortunately I don't see the full message appearing in the thread. That is despite the fact that I am logged in....

    Maybe you can send it a again as a response to this message.

    The last part that I can read in the notification is: Please update them to point to the ....

    My guess is that I have to prevent that there are absolute paths to the original project (the one that I clone). Please specify what you mean with the previous project's file. Which file? Which extension?

    Thanks Fred

    0 comments No comments