1

My build (in VS2022) has a C++/CLI assembly that needs to reliably reference types the WindowsDesktop.App.Ref package for .NET 6. Like types in the WindowsBase assembly. I cannot find a way to do this that works for all developers.

I was trying to use the version found in this folder:

c:/program files/dotnet/packs/windowsdesktop.app.ref

On my brand new machine it looks like this:

enter image description here

But the problem is that different developers have different "latest" version subfolders here One developer has only a subfolder named "6.0.8". Another has "6.0.7". It seems that updating to the latest Visual Studio would install it, but some of us cannot do that right now for unrelated reasons.

So is there some downloadable MS installer I can run, separate from visual studio that can ensure that one specific version like 6.0.11 lives in that folder?

(Then, i could just ask every developer to install it and hard code the .VCXPROJ file)

OR

Is there some other basic .NET 6 base folder that I should be trying to use to get at these types at build time? Like, say maybe this one?

C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App

Because here I see that:

enter image description here

The rules about this stuff confuse me.

Guru Stron
  • 102,774
  • 10
  • 95
  • 132
Joe
  • 5,394
  • 3
  • 23
  • 54
  • Maybe you can try using [global.json](https://learn.microsoft.com/en-us/dotnet/core/tools/global-json) but not sure it is applicable to C++/CLI projects. – Guru Stron Dec 08 '22 at 18:55
  • 3
    The documented way is [here](https://learn.microsoft.com/en-us/dotnet/core/porting/cpp-cli#port-a-ccli-project), "WPF and Windows Forms usage" section. What it doesn't tell you is that the added FrameworkReference needs to be inside an ItemGroup, that took me an hour. – Hans Passant Dec 08 '22 at 19:34
  • @HansPassant Perfect! Thank you!. By the way, isn't framework reference a really new thing that they just added to C++/CLI? I seem to recall reading something about that in the release notes recently... – Joe Dec 08 '22 at 20:13
  • Or was that a NuGet thing? – Joe Dec 08 '22 at 20:18

1 Answers1

2

You can install either the full SDK with needed version from here (or install via Powershell script, see reference for options).

UPD

As mentioned in comments, you can add FrameworkReference element to the .vcxproj file (see WPF and Windows Forms usage docs) to allow .NET Core C++/CLI projects usage of Windows Forms and WPF APIs:

<ItemGroup>
  <FrameworkReference Include="Microsoft.WindowsDesktop.App" />
</ItemGroup>
Guru Stron
  • 102,774
  • 10
  • 95
  • 132
  • Unfortunately installing the .NET DesktopRuntime does not affect that `c:/program files/dotnet/packs folder`. It only affects the second one I listed, `c:/program files/dotnet/shared`. I can do that if I must. But the nice thing about using the `dotnet/packs` folder is that in Visual Studio I have a macro that always reliably points me there. I don't have such a macro for `dotnet/shared` – Joe Dec 08 '22 at 19:11
  • @Joe have you tried installing SDK or does it have the same effect in terms of `dotnet/packs` folder? – Guru Stron Dec 08 '22 at 19:12
  • Oh I get it now. The entire SDK, NOT just the DesktopRuntime.! My mistake. Yes, it does look like that will do it. I was looking at the wrong installer. I can't try it on my work machine for a couple of days but I'm very confident that will work and I will come back here and mark that as the answer. Thank you! – Joe Dec 08 '22 at 19:15
  • @Joe hope it helps! If not - I'm out of ideas and we will need to wait for someone smarter) – Guru Stron Dec 08 '22 at 19:18
  • Turns out Hans Passant's comment to my original message above did the trick! – Joe Dec 08 '22 at 20:18
  • @Joe yep, was wondering if `FrameworkReference` approach which is used to reference workloads [in libraries](https://learn.microsoft.com/en-us/aspnet/core/fundamentals/target-aspnetcore?view=aspnetcore-7.0&tabs=visual-studio#use-the-aspnet-core-shared-framework) would work here also. – Guru Stron Dec 08 '22 at 20:28
  • @Joe since Hans has not added as answer - updated mine. – Guru Stron Dec 13 '22 at 09:36