What is the recommended way of adding components d

2019-05-11 00:35发布

问题:

I have a C# Windows Forms project in which I use a component that I obtained through nuget. Now I was wondering what is the correct way of adding this component to the toolbox in the designer. Should I make a separate copy of the component on my hdd and add it from there or should I just add it from the project's packages folder or maybe do something different entirely?

I was wondering if:

  • having a separate copy of the component won't cause problems if I use a newer version of the component in another project?
  • using the copy from packages folder and then deleting, moving the project, won't that cause problems with the toolbox?

回答1:

Based on the conversation I had with Hans Passant in the comments (since he didn't post it as an answer):

Normally, when you get a windows forms component from nuget, it will automatically get added to the designers toolbox. The only time when it should not happen is when "Automatically Populate Toolbox" is set to false (Tools > Options > Windows Forms Designer > General).

In my particular case this does not happen. It might be related to "non-trivial dependencies that cannot be found at design time". But I'm not entirely sold on that, because I remember not being able to use such components in the designer at all, however the component that lead me to asking this question can be used there just fine. However this is likely material for a different question (and possibly on a different site).