Create a Directory.Build.props file right next to your .sln file:
<Project>
<PropertyGroup>
<UnityDllsPath>path_to_unity_installation\Editor\Data\Managed\</UnityDllsPath>
</PropertyGroup>
</Project>Add this to your .csproj:
<ItemGroup>
<Reference Include="UnityEngine">
<HintPath>$(UnityDllsPath)\UnityEngine.dll</HintPath>
</Reference>
<Reference Include="UnityEditor">
<HintPath>$(UnityDllsPath)\UnityEditor.dll</HintPath>
</Reference>
</ItemGroup>Option 2 - Via Rabadash8820/UnityAssemblies NuGet package
Create a Directory.Build.props file right next to your .sln file:
<Project>
<PropertyGroup>
<UnityProjectPath>$(MSBuildProjectDirectory)\relative_path_to_unity_project\</UnityProjectPath>
</PropertyGroup>
</Project>The path will be relative from the folder that contains the csproj file. If have different folder structures for different csproj files, you might need to push some or all of that path down to individual csproj files.
Add this to your csproj file:
<ItemGroup>
<PackageReference Include="Unity3D" Version="3.0.0" />
<Reference Include="$(UnityEditorPath)" Private="false" />
</ItemGroup>Remove the reference with UnityEditorPath unless you are writing an editor-only DLL. UnityEngine is automatically referenced, you don't have to write anything for it.