HowTo: Run C# Script in Rhino using VS Code

In case you all like to use VSCode for C# in Grasshopper here is a possible solution:

follow steps 1 to 6, but also add Grasshopper dlls to the project file in step 4:

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>netcoreapp2.2</TargetFramework>
  </PropertyGroup>
  <ItemGroup>
    <Reference Include="RhinoCommon">
      <HintPath>C:\Program Files\Rhino 6\System\RhinoCommon.dll</HintPath>
      <Private>False</Private>
    </Reference>
  </ItemGroup>
  <ItemGroup>
    <Reference Include="Grasshopper">
      <HintPath>C:\Program Files\Rhino 6\Plug-ins\Grasshopper\Grasshopper.dll</HintPath>
      <Private>False</Private>
    </Reference>
  </ItemGroup>
  <ItemGroup>
    <Reference Include="GH_IO">
      <HintPath>C:\Program Files\Rhino 6\Plug-ins\Grasshopper\GH_IO.dll</HintPath>
      <Private>False</Private>
    </Reference>
  </ItemGroup>
  <ItemGroup>
    <Reference Include="GH_Util">
      <HintPath>C:\Program Files\Rhino 6\Plug-ins\Grasshopper\GH_Util.dll</HintPath>
      <Private>False</Private>
    </Reference>
  </ItemGroup>
</Project>

use this gh file :

VSCode_GH_Example.gh (17.4 KB)

and this cs script file, which is loaded into the file component:

ScriptComponentA.cs (1.2 KB)

This is a quick solution I made this evening, but it could potentially being improved…