Reputation: 1634
I'm trying to automatically add (nuget) references to my (C++) visual studio 2017 project using CMake.
In this question, VS_PACKAGE_REFERENCES
is suggested, available from CMAKE 3.15. So, I've added the following to my CMAKE code:
set_property(TARGET MyApplication
PROPERTY VS_PACKAGE_REFERENCES "BaseUtils.Native.Dynamic_0.4.0.38060"
)
And the following is nicely added to my project:
<ItemGroup>
<PackageReference Include="BaseUtils.Native.Dynamic" Version="0.4.0.38060" />
</ItemGroup>
However, the reference is not show in the solution explorer, nor are any include folders added to the project. It seems that the PackageReference
element is in no way taken into account.
Anyone any idea how to solve this? I'm using CMake 3.15.3, which doesn't give any errors or warnings.
Upvotes: 6
Views: 3042
Reputation: 4318
There's a well-known-hidden feature inside MSBuild to support it. You need to add somewhere the following configuration:
<ItemGroup Condition="'$(MSBuildProjectExtension)' == '.vcxproj'">
<ProjectCapability Include="PackageReferences" />
</ItemGroup>
<PropertyGroup Condition="'$(MSBuildProjectExtension)' == '.vcxproj'">
<NuGetTargetMoniker Condition="'$(NuGetTargetMoniker)' == ''">native,Version=v0.0</NuGetTargetMoniker>
<RuntimeIdentifiers Condition="'$(RuntimeIdentifiers)' == ''">win;win-x86;win-x64;win-arm;win-arm64</RuntimeIdentifiers>
</PropertyGroup>
This will enable VS to work with PackageReference in vcxproj projects.
I added it to the Directory.Build.props
in the root of my project.
From my understanding this generally enables NuGET managements and eliminates the need in any packages.config
and local package downloads.
From now on my VS resolved C++ packages from inside my NuGET cache itself just like for C# projects
Upvotes: 1
Reputation: 1634
Hmm, apparantly, C++ projects are not supported by PackageReference
according to learn.microsoft.com
ASP.NET apps targeting the full .NET Framework include only limited support for PackageReference. C++ and JavaScript project types are unsupported.
This makes the whole VS_PACKAGE_REFERENCES
option from CMake inapplicable for C++ projects.
Upvotes: 12