Now it seems to be all handled by this .resx and after I added my resource there, I still don’t see autocomplete showing this Properties.Resources.Ghtml, which is how i would call the resource in old version of visual studio
I also had a problem adding icons in the latest versions of Visual Studio. When I double-click the .resx file VS opens the new interface of the Resource Explorer. And all the images added through this new interface have the wrong path to the Resource folder.
The workaround is to open the .resx file with the legacy Resource Editor: right-click - Open with... - Managed Resources Editor. Images added with the legacy one have the right path.
Add the following code to your plugin to retrieve the embedded image and use it as the icon:
protected override Bitmap Icon
{
get
{
using (var stream = Assembly.GetExecutingAssembly()
.GetManifestResourceStream("MyGrasshopperAssembly1.spiral.png"))
{
return stream != null ? new Bitmap(stream) : null;
}
}
}
The full resource name must include the namespace and folder path. For example, if spiral.png is in a folder called Resources, the resource name would be:
Thanks! This method is similar to what was linked in my OP.
Would you say doing so through System.Reflection would have performance penalties?
I honestly have no idea. Something about calling Properties.Resources.Filename seems faster than GetExecutingAssembly() and look for it.
I would say using resource files is slightly faster because it relies on strongly-typed resource accessors, which avoid the reflection overhead of GetManifestResourceStream. However, as far as I understand, using direct embedding is a more standard approach in .NET Core. In fact, it seems that Grasshopper2 icons are implemented using direct embedding.
Drop this file in your project, you may need to modify your .csproj file, but you may also be able to just show external files in Solution Explorer, and then right click on this file and choose “Include in Project”. Resources.zip (1.5 KB)