Whole Tomato Software Forums
Whole Tomato Software Forums
Main Site | Profile | Register | Active Topics | Members | Search | FAQ
User name:
Password:
Save Password
Forgot your password?

 All Forums
 Visual Assist
 Feature Requests
 Support for PackageReferences
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

grigorii_s
New Member

Ukraine
3 Posts

Posted - Mar 28 2022 :  05:18:37 AM  Show Profile  Reply with Quote
Hey!

There's one feature of Visual Studio 2022 that I use: It's specifying NuGet packages not in packages.config but directly in project files as <PackageReference/>. A consequence of that is imports of corresponding .props and .targets files are implicit. Imports are placed in generated props and targets files in obj subfolder for each project.

This feature is not officially supported for C++ projects but can be easily enabled.

The downside of using that feature is that Visual Assist knowns nothing about generated props and targets, so it cannot parse includes that correspond to imported packages. Is it possible to support it in Visual Assist?

Regards,
Grigorii

feline
Whole Tomato Software

United Kingdom
19054 Posts

Posted - Mar 28 2022 :  09:49:15 AM  Show Profile  Reply with Quote
What do I need to know to set up a test case for this?

Using VS2022 I have created a new, default C++ console solution. Then, based on this page:

https://docs.microsoft.com/en-us/nuget/consume-packages/package-references-in-project-files

I have added the following block to the .VCXPROJ file:

  <ItemGroup>
     <PackageReference Include="libjpeg" version="9.2.0.1" />
    <PackageReference Include="libjpeg.redist" version="9.2.0.1" />
  </ItemGroup>


I worked out these lines by making a separate C++ console solution in VS2022 and using the dialog:

IDE Tools menu -> NuGet Package Manager -> Manage NuGet Packages for Solution...

to add the package "libjpeg", and then opened the generated file "packages.config" in notepad and copied out the package name and version number details.

The solution where I have used the NuGet package manager dialog works as expected, the package is downloaded and I can include header files from it, and it compiles.

When just trying to add the package information to the VCXPROJ file directly it does not work, no package is downloaded, and trying to reference the package header files doesn't compile.

zen is the art of being at one with the two'ness
Go to Top of Page

grigorii_s
New Member

Ukraine
3 Posts

Posted - Mar 28 2022 :  09:59:04 AM  Show Profile  Reply with Quote
You need to add following lines to your vcxproj

  <ItemGroup>
    <ProjectCapability Include="PackageReferences" />
  </ItemGroup>
  <PropertyGroup>
    <NuGetTargetMoniker Condition="'$(NuGetTargetMoniker)' == ''">native,Version=v0.0</NuGetTargetMoniker>
    <RuntimeIdentifiers Condition="'$(RuntimeIdentifiers)' == ''">win;win-x86;win-x64;win-arm;win-arm64</RuntimeIdentifiers>
  </PropertyGroup>


Alternatively, you can add them to Directory.Build.props filtering projects by type:


  <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>


After that in Visual Studio 2022 the dialog "Manage NuGet Packages for Solution..." will work as expected for native C++ projects and will add PackageReferences directly into .vcxproj file.

Regards,
Grigorii
Go to Top of Page

feline
Whole Tomato Software

United Kingdom
19054 Posts

Posted - Mar 29 2022 :  11:46:39 AM  Show Profile  Reply with Quote
Can you send me a simple test solution that uses one of these techniques, that works, so I can try to see what you mean?

Adding the first block of code to my VCXPROJ file has stopped the IDE Build menu from showing up when I load that test solution. So that's really not helpful.

For the second method, I don't have any *.props files to modify.

Please send me the files via email:

[email protected]

including this thread ID or URL in the description, so we can match it up.

zen is the art of being at one with the two'ness
Go to Top of Page

feline
Whole Tomato Software

United Kingdom
19054 Posts

Posted - Mar 31 2022 :  12:22:24 PM  Show Profile  Reply with Quote
I have the same project, many thanks for this. I have put in a feature request to pick up packages included like this:

case=148009

zen is the art of being at one with the two'ness
Go to Top of Page

grigorii_s
New Member

Ukraine
3 Posts

Posted - Apr 01 2022 :  04:36:40 AM  Show Profile  Reply with Quote
Thank you.

Regards,
Grigorii
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
© 2023 Whole Tomato Software, LLC Go To Top Of Page
Snitz Forums 2000