Setting up Visual Studio Express 2012 and 2013 to write your own Grasshopper components in C#

A quick guide for setting up Visual Studio Express for developing Grasshopper components for Rhino 5.

This guide has been tested with Visual Studio 2012, 2013 and 2015. (Presumably 2014 would also be fine, though feedback is welcome!)


Update (12/3/14):

The process below has recently been made a lot easier by the release of the Grasshopper Assembly.

(Update 2, 16/5/14) Once installed, this automates steps 3-6 – all you do is select Rhino > Grasshopper Add-on when starting a new project.

The only thing you might want to do is step 7. If you want to run your components in debug mode, you will want to change the ‘post-build event command’ to the ‘Copy /Y…’ version as shown in the very last image.

If you don’t do this, your components will not automatically be copied to the GH components folder and they won’t appear in GH when you try to debug.

Thanks to Giulio on this forum post for bringing this to my attention.


1) Download and install Visual Studio Express 2012 for Windows Desktop.

(Note: VSE2012 for Windows8 seems to be specifically for creating Metro apps in Windows 8.)

http://www.microsoft.com/visualstudio/eng/downloads#d-2012-express

Make sure you also have the latest version of Grasshopper installed.

http://www.grasshopper3d.com/page/download-1

2) Create a new project and give it a name.

3) Set up DLLs

Under solution explorer, right click on References and click ‘Add Reference’.

Click ‘browse’.

Find the following DLLs on your computer:

  • RhinoCommon.dll
  • Grasshopper.dll
  • GH_IO.dll

Depending on your version of Grasshopper, they can be either within a dedicated Grasshopper folder in your program files, or within the plugins of your Rhino installation folder. Check here if you’re struggling to find them. On my computer, I found them at:

  • C:\Program Files\Rhinoceros 5.0 (64-bit)\Plug-ins\grasshopper_0.9.56.0
  • C:\Program Files\Rhinoceros 5.0 (64-bit)\System

4) Set ‘Copy Local’ to false

This is very important for avoiding errors! Select GH_IO in the solution explorer.

Then, under ‘Properties’, set ‘Copy Local’ to false.

Repeat this for the other DLLs Grasshopper.dll and RhinoCommon.dll.

5) Set the build paths

Open properties from the solution explorer.

Select build. Under configuration, set Debug.

Then, under ‘output path’, replace any text with ‘bin’, as shown above. Then, under configuration, change to ‘Release’ and change output path so that it is also ‘bin’.

The reason for this is so that you can easily switch between debug and release compiler modes without having to redefine the location of your project to Grasshopper.

6) Set up VSE to debug your components

In the full versions of Visual Studio, there is an option built into the user interface that allows you to easily set up debugging of DLLs. For instance, you can write a DLL for Rhino, hit ‘run’ in VS, and VS will run Rhino along with your DLL, with VS running in debug mode in the background.

With the Express edition, this option is removed from the user interface, but it is quite simple to set up your project manually so that it can be run in debug mode inside Rhino/GH.

Firstly, find in Windows Explorer where your project is saved. Find the csproj file. Right-click it and open it in a text editor.

You should see something like this.

Now, under <PropertyGroup> near the top, add the following lines:

   <StartAction>Program</StartAction>
   <StartProgram>C:\Program Files\Rhinoceros 5 (64-bit)\System\Rhino.exe</StartProgram>

(Change it if Rhino is installed in a different location.)

It should now look like:

Save the file and close.

7) Set up formatting to GHA

Double click on ‘Properties’ in the solution explorer.

Click the ‘Build Events’ tab, and under ‘Post build event command line’, enter the following text:

Copy "$(TargetPath)" "$(TargetDir)$(ProjectName).gha"
Erase "$(TargetPath)"

The reason for this is that Grasshopper won’t read files with DLL formats, but simply renaming the file extension to GHA will fix this.

You can also use this script to save the output anywhere you want. On my computer, I have used the following script instead:

copy /Y "$(TargetDir)$(ProjectName).dll" "C:\Users\jramsden\AppData\Roaming\Grasshopper\Libraries\$(ProjectName).gha"

This saves the output at the specified address – directly inside the Grasshopper directory in my AppData folder. I have also chosen not to delete the original file.

Further reading

A guide for creating custom components in Grasshopper, written by Ben Sitler, is very useful reading, even if written back in 2010.

5 thoughts on “Setting up Visual Studio Express 2012 and 2013 to write your own Grasshopper components in C#”

Leave a Reply

Your email address will not be published.

Time limit is exhausted. Please reload CAPTCHA.

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: