Search code examples
c++visual-studio-2015propertysheet

create a Property-Sheet that can Add-Reference in Visual Studio 2015


Is it possible to Add Reference to a project in Visual Studio 2015 using Property Sheet?
How?

This below image (Add Reference) is what I want, but I want to do it using Property Sheet.

enter image description here

This feature probably doesn't exist anymore :-
https://msdn.microsoft.com/en-us/library/669zx6zc.aspx

The Common Properties configurations in earlier versions of Visual Studio have been removed. To add a reference to a project, you now use the Add Reference dialog in the same way as for managed languages. See Managing references in a project.

Is there still a workaround?
I want to create a magic property-sheet, then "just include a certain property-sheet, and everything will work!" (without need to Add References manually).

It can also reduce cost to maintain / refactor project.


Solution

  • The only thing Add Reference in VS does is adding something like this

    <ItemGroup>
      <ProjectReference Include="path\to\project.vcxproj">
        <Project>{e4abca85-42b0-4168-a628-e2287b9a8763}</Project>
      </ProjectReference>
    </ItemGroup>
    

    to the project file. That is just standard msbuild code so you can put it in a property sheet (which after all is just another name for an 'msbuild file') like this:

    <?xml version="1.0" encoding="utf-8"?> 
    <Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
      <ItemGroup>
        <ProjectReference Include="path\to\project.vcxproj">
          <Project>{e4abca85-42b0-4168-a628-e2287b9a8763}</Project>
        </ProjectReference>
      </ItemGroup>
    </Project>
    

    and it would have the same effect; when building, that is. It doesn't play well with the gui in VS though: it will see the reference but I don't think it is able to modify it (like setting CopyLocal) in the property sheet so adjustments liek that have to be done manually. Then again, seems like a small price to pay if you want the reusability a property sheet offers.