I have been wrestling with this for a few days and after tons of searching I can\'t find the path I should be on.
What I want to do is set up an MSBUILD project that
Starting with msbuild v 15 you can copy a single file called Directory.Build.props in the root folder that contains your source.
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemDefinitionGroup>
<Reference>
<Private>False</Private>
</Reference>
</ItemDefinitionGroup>
</Project>
This works well with Visual Studio 2017 and the vNext Build. May you have to close Visual Studio and than open your solution again to take the file effect.
https://docs.microsoft.com/en-us/visualstudio/msbuild/customize-your-build#directorybuildprops-and-directorybuildtargets
In a file like filter.targets add a target:
<Target Name="BeforeBuild">
<ItemGroup>
<ReferenceNew Include="@(Reference)">
<Private>False</Private>
</ReferenceNew>
<Reference Remove="@(Reference)"/>
<Reference Include="@(ReferenceNew)"/>
</ItemGroup>
</Target>
This will recreate the @(Reference) list to have the metadata 'Private' set to false, which will ensure that the reference doesn't get copied. Then run build your solution or project with the property $(CustomAfterMicrosoftCommonTargets) set to the path to this filter.targets file.
msbuild foo.sln /p:CustomAfterMicrosoftCommonTargets=c:\foo\filter.targets
This way, the BeforeBuild target will get invoked before building the project, and all references will be set accordingly. If you want more control over when or whether Private should be false or true, you can alter the BeforeBuild target and control that via properties.
Edit: There might be a better way to set the metadata in the BeforeBuild target.
Try this:
Set the CustomAfterMicrosoftCommonTargets to C:\foo\filter.targets (or whatever you name the file) and have filter.targets to be:
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemDefinitionGroup>
<Reference>
<Private>False</Private>
</Reference>
</ItemDefinitionGroup>
</Project>