locked
Define macros per soluton (not per project) RRS feed

  • Question

  • I want to reuse some visual studio projects from an existing solution but with variable reference paths. For example I have a SlnA.sln having foo.vcxproj. Say this foo.vcxproj has reference to bar.vcxproj. I need to create a SlnB.sln and to add foo.vcxproj, but instead of referencing bar.vcxproj, it needs to reference bar2.vcxproj.

    If there is a way to include a macro or a propsheet based on solution, I think I can make the name and GUID of the project bar as variables such that it loads the appropriate project based on solution. Any suggestions/help will be very helpful.

    Thanks.


    Monday, July 27, 2020 7:17 PM

All replies

  • Hi BlackholeBrain,

    >>If there is a way to include a macro or a propsheet based on solution

    I am afraid that you can't get the results you want at this stage. We suggest you could create a property sheet to save macros, and then add this existing property sheet into the project you want.

    Please refer more here: Create user-defined environment variables (macros) 

    Best Regards,

    Dylan


    MSDN Community Support Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com

    Tuesday, July 28, 2020 5:40 AM
  • Thanks Dylan. But let's say I add a propsheet to foo.vcxproj. How can I make foo.vcxproj know such that when it is loaded under SlnA it should use bar.vcxproj whereas when it loaded under SlnB it should use bar2.vcxproj? You need some kind of input from the solution to tell to the vcxproj which reference to use?

    One solution is through making a copy of foo (like foo2.vcxproj). But my whole intent is to avoid making a copy of foo so that I maintain only one copy in the repository (purely for long term maintenance purpose).

    Other solution is to rely on system environment variables such that setting them a different value before the build will use specific reference. But as this product has to work across the team by other people, it is not a viable solution either.
    Tuesday, July 28, 2020 8:30 PM
  • Hi BlackholeBrain.

    Sorry for delay in reply.

    >>How can I make foo.vcxproj know such that when it is loaded under SlnA it should use bar.vcxproj whereas when it loaded under SlnB it should use bar2.vcxproj?

    You can use existing macro[$(SolutionName)] to judge what the current solution is. Please follow steps below:

    #1. Open foo.vcxproj file as text

    #2. Add a condition for your reference, for example:

    Please refer to other common macros if you need them:List of common macros 

    Best Regards,

    Dylan


    MSDN Community Support Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com


    Thursday, July 30, 2020 7:26 AM
  • Thanks! That's a great idea. It should work for me.

    Really appreciate your help. Cheers.


    Friday, July 31, 2020 5:05 PM
  • Hi BlackholeBrain,

    Could this solution meet your requirement? If there are any update, please feel free to contact us.

    Best Regards,

    Dylan


    MSDN Community Support Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com

    Tuesday, August 4, 2020 9:55 AM