- Install Visual Studio 2017 (with .Net Desktop Development tools, C# 4.6.1 and Game development with Unity)
- Install Unity, and Mono
- Create New Visual Studio Project
- Select File > New > Project
- On dialog, select
Visual C#>Class Library (.NET Framework) - Setup Name, Location, and Solution Name
- On Framework, Select
.NET Framework 4.6.1(or Unity compatible version)
- Add UnityEngine reference
- Select Project > Add Reference
- Select Browse > Browse...
- Browse to
\UNITYPATH\Editor\Data\Managed\UnityEngine.dll - On Solution Explorer, select Reference >
UnityEngine, then go to Properties, change Copy Local toFalse
- Add a new Unity Project
- At Visual Studio, select Project > $(ProjectName) Properties
- Go to Build tab, Select Configuration Debug
- Select Output Path to
\UNITYPROJECTPATH\Assets\Debug(or any name under assets) - Go to Build Events tab, on Post-build event command line, insert:
"\MONOPATH\bin\pdb2mdb" $(TargetDir)$(TargetFileName) - To debug, First build the project, then select Debug >
Attach Unity Debugger - For VS Code debug:
- Install Debugger for Unity Extension
- On VS Code, Open directory containing .csproj
- Go to Debug tab, Setup launch.json
- Set the Path to
\UNITYPROJECTPATH\Library\EditorInstance.json
- Setup Properties XML file:
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<MarcoName1>MarcoValue1</MarcoName1>
<MarcoName2>MarcoValue2</MarcoName2>
<DependentMarco3>$(MarcoValue2)Addon</DependentMarco3>
...
<MarcoNameN>MarcoValueN</MarcoNameN>
</PropertyGroup>
</Project>- At
.csprojfile, add following line:
<Project ...>
<Import ... />
<!-- Add the following line -->
<Import Project="Path\to\XmlFile" />
...
<!-- And use MarcoName just like other marcos -->
<HintPath>$(MarcoName1)...</HintPath>
...
</Project>- Step A.4.4 prevent Visual Studio from copying UnityEngine.dll to output directory, which is an unnessary and project corrupting step
Monois needed to generate debug symbol for unity debugging (Step B.5)- Not sure if $(TargetFileName) refers to 1 or 1+ dll (Step B.5)
- On Step B.4, one may also choose to use default output path and simlink it to project directory
- Only Unity version >=2018 support C# with .NET Framework 4.6.1.
- (Unconfirmed) It seems that managed DLL project can be complied with 1 Unity version and be compatibale with other version.
- Setup is tested with
- Windows 10 Pro (Version 1809, OSBuild 17763.615)
- Visual Studio 2017 (Version 15.9.14)
- Mono (Version 6.0.0)
- Unity (Version 2018.4.4f)
// 20190730_ll