Skip to content

Move C++ projects to use PackageReference  #8171

Description

@asklar

Apparently PackageReference will work in C++ projects now. We should try it and see if there are any gaps, and if acceptable then remove the packages.config stuff as it complicates things.


@asklar As it turns out, PackageReference support in C++ projects works today. You will need to do the following:

  1. Add <ProjectCapability Include="PackageReferences" /> to an item group in your vcxproj file or a targets file included by it.
  2. Add a Directory.Build.props file or above the project’s directory, and add an Import element to it with the following value: $(MSBuildProjectExtensionsPath)$(MSBuildProjectFile).*.props. (You can technically add this anywhere that MSBuild will see it, but I find that putting it in Directory.Build.props ensures that it is both included at the correct place, and is also easily shared between all the projects in your solution.)
  3. Add a Directory.Build.targets file in the same location, and add an Import element to it with this value: $(MSBuildProjectExtensionsPath)$(MSBuildProjectFile).*.targets.
  4. Unload and reload your C++ project(s).

After that, not only will NuGet packages auto-restore like with csproj, but the NuGet Package Manager UI will also add and remove PackageReference elements from the project instead of creating a packages.config file. (If this doesn’t seem to work, you may need to use the VS 16.11 beta; that’s what I’m using, and it works great for me.) Note that vcxproj will require you to run File > Save All before changes made in the NuGet UI will persist to the project file, as with any other changes to a vcxproj made using the GUI. Hope this helps!

Originally posted by @wjk in dotnet/project-system#2491 (comment)

References

Metadata

Metadata

Assignees

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions