“ReferencePath” does not define a value for metadata “CopyLocal”

After upgrading Visual Studio 2017 to 15.8.5 I ran into an error while building an existing WPF project:

The item "C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\MSBuild\Microsoft\Microsoft.NET.Build.Extensions\net461\lib\Microsoft.Win32.Primitives.dll" in item list "ReferencePath" does not define a value for metadata "CopyLocal". In order to use this metadata, either qualify it by specifying %(ReferencePath.CopyLocal), or ensure that all items in this list define a value for this metadata.

Google didn’t really help that time and since it was happening on building while working fine before I just tried replacing the Microsoft.Common.CurrentVersion.targets file in C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\MSBuild\15.0\Bin and C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\MSBuild\15.0\Bin\amd64 with an version before the upgrade. I basically had to copy it from a different installation.

So this is an annoying solution and with the latest upgrade, it doesn’t seem fixed. It also works fine with existing WPF projects. You could remove the project and create a new one and just copy all old code over, but that is annoying too especially if you have a ton of references.

So I decided to compare the target files to see what actually changed and to be fair, you only have to change one single thing in the file:

Line 3961: Change …Include=”@(ReferencePath)” to …Include=”@(ReferencePath.CopyLocal)”

That’s all you have to do, like the error said itself, by specifying %(ReferencePath.CopyLocal).

Happy Days.

4 thoughts on ““ReferencePath” does not define a value for metadata “CopyLocal””

  1. Your solution helped me solve a similar problem. I’m using VS 2017. The project would not build on my computer but it would on a co-workers computer. So I used DiffMerge to compare the two folders and there was ONE difference in the same file you mention (“Microsoft.Common.CurrentVersion.targets”). So I made the change on my computer and re-opened the project and it compiled without the error. Note that my change is different from your change so I’m posting this in hopes that it helps someone else in a similar situation. Very odd that my computer was missing this text. Thanks for your post!
    The BROKEN line is:

    The FIXED line is:

    The important bit is that the Condition= has the text “ReferencePath.” before “CopyLocal”
    Cheers!

  2. Your website stripped out the tags from my previous comment so I’m reposting WITHOUT the beginning and ending HTML tags.
    The BROKEN line is:
    _CopyLocalFalseRefPaths Include=”@(ReferencePath)” Condition=”‘%(CopyLocal)’ == ‘false'”
    The FIXED line is:
    _CopyLocalFalseRefPaths Include=”@(ReferencePath)” Condition=”‘%(ReferencePath.CopyLocal)’ == ‘false'”
    Cheers!
    Kris

Leave a Reply

Your email address will not be published. Required fields are marked *