Problem in making .vcxproj file shareable in source control RRS feed

  • Question

  • I provide a project template in my VSIX extension. I want to make the .vcxproj file created based on the template be shareable, namely user environment neutral. So all user specific properties are put in .user file. However, some properties in .vcxproj file refers to/depends on a property (with value of an absolute path) in .user file, but .vcxproj file is evaluated before the .user file, which in turn means the depending properties won't have proper value. I tried including (import) the .user file in the .vcxproj file. It works but it causes various other problems. 

    So is there a way to make it work for a property in .vcxproj file to refer to a property in .user file ?

    Monday, March 18, 2019 4:56 AM

All replies

  • .user file is automatically imported in Microsoft.Common.CurrentVersion.targets, i.e. as a part of Microsoft.Cpp.targets import, so properties defined in .user can be used in Properties defined after that (i.e. in targets, but not vcxproj) and all ItemDefinitionGroups, ItemGroups and Targets as they are evaluated in a different msbuild evaluation passes.

    If you ever need to know the order of msbuild definitions, use

    msbuild /pp:out.xml <project>

    and keep in mind that msbuild has the following evaluation passes:

    1. PropertyGroups and Import

    2. ItemDefinitionGroups

    3. ItemGroups

    4. Targets

    Tuesday, April 2, 2019 6:52 PM
  • Thanks for the answer, Olga !

    Yeah, I noticed that the .user file is imported near the end of the .vcxproj via the Microsoft.Common.CurrentVersion.targets file. 

    Here's my issue. Our project is actually built by our own build system (something like an in-house makefile system), and we pass a build command to msbuild via property <NMakeBuildCommandLine> in .vcxproj file.  The command line refers to the full path of our SDK, which is machine-specific and thus defined as a property in .user file.  Also, properties such as <NMakeIncludeSearchPath> also depend on that SDK_Path property.

    So is there a way to make the .vcxproj file shareable without breaking the functionality of the project ?

    Thanks again for any pointer.

    Tuesday, April 2, 2019 9:52 PM
  • I'd suggest defining your SDK_PATH property not in .user, but in a .props file which you'd install as a part of VSIX in one of the ImportBefore/After folders under VCTargetsPath so it will be automatically imported to all vc projects (see  https://docs.microsoft.com/en-us/visualstudio/extensibility/visual-cpp-project-extensibility?view=vs-2017#the-vcxproj-import-tree)

    Please make sure that property names are unique enough so they don't affect projects, which don't use your extension. 

    Saturday, April 6, 2019 6:47 AM
  • Hi Olga,

    That sounds interesting. But before I dive into it, I have some questions. Is that only supposed to provide default value ? As the property is user changeable (via UI), is it possible to persist the value in a file other than the .vcxproj and .user file ?

    Thanks !

    • Edited by LingW_2008 Monday, April 8, 2019 2:47 PM
    Monday, April 8, 2019 2:46 PM
  • The ,props files installed under VCTargetsPath are useful for defining pproperties for user/machine specific locations and no, user will not be able to change them.

    But users can create their own .props files to share between projects using PropertyManager UI https://manski.net/2012/01/sharing-project-properties-in-visual-c/. Note that these .props files will be imported after Microsoft.cpp.props so they cannot define properties which saved in vcxproj before Microsoft.cpp.props import.

    Users can also create Directory.Build.props https://docs.microsoft.com/en-us/visualstudio/msbuild/customize-your-build?view=vs-2019

    Monday, April 8, 2019 5:28 PM