Reputation: 403
Note: This is similar to How to add com reference in Rider, but that question never got a working answer and I found other people with the same problem but no solution.
When trying to add a reference to a reference to a C# project in Rider with Add -> Add Reference, the dialog is empty.
Even the official JetBrains documentation says to do it like that though.
So how could I, for example, add a reference to System.Windows.Forms
in a Console Application (does not include that namespace by default)?
Image of the Add Reference Dialog:
Upvotes: 2
Views: 5686
Reputation: 3693
Which TargetFramework do you use? If you use some classic framework like net48
everything should work fine.
For the modern target frameworks (like net6.0
) it is impossible to "just reference"
System.Windows.Forms
. For example if you add a plain reference to the project file like
<ItemGroup>
<Reference Include="System.Windows.Forms" />
</ItemGroup>
The project won't build properly. MSBuild produces the next warning:
Microsoft.Common.CurrentVersion.targets(2301, 5):
[MSB3245] Could not resolve this reference. Could not locate the assembly "System.Windows.Forms".
Check to make sure the assembly exists on disk. If this reference is required by your code, you may get compilation errors.
If you want to work with windows forms in modern console apps, you have to add these lines to the project file instead of adding a single reference:
<PropertyGroup>
<TargetFramework>net6.0-windows</TargetFramework>
<UseWindowsForms>true</UseWindowsForms>
</PropertyGroup>
Upvotes: 2