Home > Software engineering >  How to add reference to framework component in Visual Studio?
How to add reference to framework component in Visual Studio?

Time:09-04

Using Visual Studio 2022, how do I add framework dependencies to a class library?

If I right click on Dependencies, I have options to add Project, Shared Projects, COM and Browse references. There is no option to add Framework dependencies.

Looking at my WinForms project, I see the component I want is C:\Program Files\dotnet\packs\Microsoft.WindowsDesktop.App.Ref\6.0.8. So I can click the Browse button and navigate to this folder, but the Browse function wants a filename.

If I right click on the Frameworks entry under Dependencies, I get no context menu whatsoever.

I see no way to add this component to the list of dependencies for this class library project.

CodePudding user response:

One way to get this done is to modify your csproj file. You need to change the SDK and tell it to use WinForms:

<Project Sdk="Microsoft.NET.Sdk.WindowsDesktop"> <!-- Change this -->

  <PropertyGroup>
    ...
    <UseWindowsForms>true</UseWindowsForms> <!-- Add this -->
    ...
  </PropertyGroup>

</Project>
  • Related