Build argument -reference:ALIAS=DLL

My problem is the following. As I need to use System.Windows.Form namespace for Windows dialogs I first tried to use normal “Edit Reference” in MonoDevelop, search for the .dll in …\Unity\Editor\Data\Mono\lib\2.0 and just adding it. This caused a problem because as I had algo as reference System, when I write using System.Windows.Form and then build the solution, it tells me that it didn’t found ‘Windows’ in ‘System’ namespace. This is obvious because it didn’t had to lookup there. So I solved it in mono by adding “/reference:WinForm=<DLL_PATH>” in compiler additional arguments and in my class heading:

  extern alias WinForm.

When I needed to use a namespace from that import I write for example:

  WinForm::System.Windows.Forms.SaveFileDialog saveDialog = new WinForm::System.Windows.Forms.SaveFileDialog();
  saveDialog.FileName = Path.GetFileName(myPathVar);

My problem now is that I can’t access the compiler arguments in Unity. Error: Assets/scripts/GenerateFiles.cs(1,14): error CS0430: The extern alias `WinForm’ was not specified in -reference option, where do I put -reference??

I have tried:

Unity.exe -batchmode -buildWindowsPlayer “PATH.TO.EXE.exe” -reference:WinForm=“C:\Program Files (x86)\Unity\Editor\Data\Mono\lib
\mono\2.0\System.Windows.Forms.dll” but it ain’t working =S.

Thanks in advance.

You can access the compiler arguments in Unity by creating an smcs.rsp file in your project. These files are defined in the following doc:

Add your -reference flag into this file. Note that this file will not re-import automatically - you may need to right-click-reimport a script to refresh the project changes.

I’ve uploaded a sample project demonstrating this feature here:

Hello @b4th

I have the same error, missing an extern alias.

I’ve downloaded your sample, but it’s not working, either in my script.

I’m using Unity 2018.4.12f1. Is this outdated?,Hello @b4th

I’m also missing an extern alias:
“Assets\TestBehaviour.cs(1,14): error CS0430: The extern alias ‘ClassLibrary1’ was not specified in a /reference option”

I’ve downloaded your sample project. But it’s not working in your sample, either in my project.

I’m using Unity 2018.4.12f1. Could this be outdated? I’m not finding any newer answer.

Thanks in advance