Search Unity

Difficulty Getting msc.rsp Working

Discussion in 'Windows' started by stonstad, Mar 6, 2019.

  1. stonstad

    stonstad

    Joined:
    Jan 19, 2018
    Posts:
    90
    Hello! I am attempting to include the following .NET Standard 2.0 libraries through a csc.rsp file. I am using Unity 2018.3.6f1, with IL2CPP/.NET Standard 4.x scripting.

    I have the following file in my \assets folder:

    csc.rsp



    Here's the resulting error on play:


    OK, so then I try removing System.ServiceModel.Primitives.dll but I can see my .NET Standard 2.0 WCF services require it.



    I'm totally confused as to what the workflow is to get this to work properly. What am I missing?

    What works is dropping the DLLs I need into the \Assets folder. I understand that I should not do this...

    Separate but related -- is there some kind of quirk in Unity where I must close the editor and re-open it for csc.rsp changes to work?

    Also -- when do I use csc.rsp vs mcs.rsp? The documentation on the Unity website shows mcs.rsp but build warnings request csc.rsp. Are the docs out-of-date?

    *edited to correct folder name assemblies are placed in.
     
    Last edited: Mar 7, 2019
  2. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    3,980
    The documentation must not be clear enough about this. You should use csc.rsp with the new scripting runtime, since it uses Roslyn as the C# compiler. You should use mcs.rsp with the old scripting runtime, since it uses mcs as the C# compiler. Which page are you looking at in the docs? I'll correct it.
     
    stonstad likes this.
  3. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    3,980
    What do you mean by the "Unity folder" here?

    If you don't do this, where is the System.ServiceModel.Primitives.dll file located in your project?
     
  4. stonstad

    stonstad

    Joined:
    Jan 19, 2018
    Posts:
    90
  5. stonstad

    stonstad

    Joined:
    Jan 19, 2018
    Posts:
    90
    To avoid compile errors, I am placing System.ServiceMode.Primitives.dll in \Assets.
     
  6. stonstad

    stonstad

    Joined:
    Jan 19, 2018
    Posts:
    90
    Confirmed, I am using csc.rsp with IL2CPP scripting runtime w/ .NET 4.x.
     
  7. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    3,980
    Where did you locate this file when it did not work?
     
  8. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    3,980
  9. stonstad

    stonstad

    Joined:
    Jan 19, 2018
    Posts:
    90
    Josh, I appreciate your assistance trying to get to the bottom of this. I performed a global search for System.ServiceModel.Primitives.dll in folder ..\Hub\Editor\2018.3.6f1\Editor. There were multiple results and I selected the .NET 4.5.0 version.

     
  10. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    3,980
    Ok, let me make sure I understand. Initially, you only put a csc.rsp file in the Assets folder of the project, but did not copy the System.ServiceMode.Primitives.dll into the project. Then you see the initial error mentioned in this thread. Is that correct?

    If you copy the System.ServiceMode.Primitives.dll files from the Data\MonoBleedingEdge\lib\mono\4.5 directory, then thinks work as expected. Is that also correct?

    If so, this sounds like a bug on the Unity side. The csc.rsp file should be all you need properly references this assembly.
     
  11. stonstad

    stonstad

    Joined:
    Jan 19, 2018
    Posts:
    90
    I tried so many things that it is entirely possible that I am not conveying the proper sequence of events. I will remove System.ServiceModel.Primitives.dll and the csc.rsp file and restart Unity. I will then walk forward through the sequence of steps and document here.
     
    JoshPeterson likes this.
  12. stonstad

    stonstad

    Joined:
    Jan 19, 2018
    Posts:
    90
    Initial State: No .NET platform libraries manually copied. No csc.rsp file. A single .NET Standard 2.0 DLL I authored is in the \Assets folder.

    Step 1. Unity Editor does not compile on play. Errors below.



    Step 2. Add csc.rsp file to .\Assets folder as shown below. Restart Unity. Unity Editor does not compile on play. Errors below.



    Step 3. Copy System.ServiceModel.Primitives.dll from Editor\2019.3.6f1\.\MonoBleedingEdge. Unity remains open. Compiling Scripts dialog appears. Errors go away.

    Editor play works as intended.
     
  13. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    3,980
    What Api Compatibility Level option is set in the Player Settings?
     
  14. stonstad

    stonstad

    Joined:
    Jan 19, 2018
    Posts:
    90
    .NET 4.x.

     
  15. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    3,980
    Try changing that to .NET Standard 2.0, if possible. That should not be necessary, but I'd like to know if it changes the outcome. When you do this, please remove the System.ServiceModel.Primitives.dll file from the Assets directory in your Unity project.
     
  16. stonstad

    stonstad

    Joined:
    Jan 19, 2018
    Posts:
    90
    .NET Standard 2.0 is more restrictive, isn't it? Here are the errors shown after changing to .NET Standard 2.0.

     
  17. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    3,980
    It is more restrictive. Since you built your assembly against .NET Standard 2.0 though, I thought this might change the behavior. However it seems to be the same.

    Can you submit a bug report for this issue? It looks like something is wrong on the Unity side.
     
  18. stonstad

    stonstad

    Joined:
    Jan 19, 2018
    Posts:
    90
    JoshPeterson likes this.
  19. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    3,980
  20. blairhoughton

    blairhoughton

    Joined:
    Jan 5, 2019
    Posts:
    9
    Looked at the link and it still doesn't mention csc.rsp, nor does anything suggest why things like this still occur when I add standard libraries to the csc.rsp file:

    Microsoft (R) Visual C# Compiler version 2.9.1.65535 (9d34608e)
    Copyright (C) Microsoft Corporation. All rights reserved.
    error CS0006: Metadata file 'System.Windows.Forms' could not be found​
     
  21. blairhoughton

    blairhoughton

    Joined:
    Jan 5, 2019
    Posts:
    9
    (later...)
    Ah, wait...I had left the ".dll" off the library in the csc.rsp file. Adding ".dll" to the name while Unity was running didn't clear up the error, but closing and reopening Unity did.
     
    JoshPeterson likes this.
  22. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    3,980
    Unfortunately the docs may take some time to be updated. The changes are not published yet.
     
  23. blairhoughton

    blairhoughton

    Joined:
    Jan 5, 2019
    Posts:
    9
    Even more unfortunately, using the csc.rsp and copying the DLL to the Assets folder is not working for me for all the DLLs I want to use. (I'm trying to get Microsoft.Office.Interop.Word to work there; I am starting to copy its dependencies, - office.dll and the VBE interop library - but things are not getting better and the error messages are being less and less informative. Curiously, when I open the project in Visual Studio and look at the library properties it says they are still in their system locations and not in .\Assets...)

    Oddly, if I only include the Forms library, I don't get an error for it, but when I add in the Interop libraries, Unity doesn't like the Forms library any more, saying "Loading assembly failed: 'Assets/System.Windows.Forms.dll'" with no further indication of why. The error messges for the other libraries are a mixture of "Reference has errors 'office'" and "Unable to resolve reference 'stdole'. Is the assembly missing or incompatible with the current platform?". The latter comes from office.dll and may be the reason for the former, but, again, the messages are very terse.

    What I'm most afraid of is that in order to fix those errors I may have to copy in dozens of Windows libraries to the Assets folder, while VS will still happly find them over in the system folders... Unless there's some way to put a pathname in the csc.rsp file so that Unity can resolve them there as well.
     
  24. blairhoughton

    blairhoughton

    Joined:
    Jan 5, 2019
    Posts:
    9
    Related: on the question of using mcs.rsp or csc.rsp, I found this page in the Unity docs: https://docs.unity3d.com/540/Documentation/Manual/PlatformDependentCompilation.html

    It finally clued me that the *.rsp files are target-dependent, with a different name for each compiler that Unity can build a project with. And it includes the ominous statement “you won’t know when one or another compiler is used.”

    This all seems like something that Unity could be managing under the build configuration system...
     
  25. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    3,980
    Thanks for pointing out this incorrect documentation. Note that the current version of this document is here:

    https://docs.unity3d.com/Manual/PlatformDependentCompilation.html

    It still mentions that "you don’t know when one or another compiler is used" statement, which is incorrect. Now mcs.rsp is used for the old scripting runtime, csc.rsp is used for the new scripting runtime. I'll update this document as well to reflect the current state of things.
     
  26. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    3,980
    Unity does not support Windows Forms, and I suspect that Office interop will struggle to work as well. You might be able to get this to work by copying all of the dependencies, as you mentioned, but this is not a scenario that we test for in Unity.

    Can I ask about your larger objective? Maybe there is a better solution which will integrate with Unity more effectively.
     
  27. stonstad

    stonstad

    Joined:
    Jan 19, 2018
    Posts:
    90
    @JoshPeterson Regarding the original topic of this thread -- getting a Unity-supported .NET Standard 2.0 library fixed in the build process with csc.rsp (System.ServiceModel.Primitives.dll) for either .NET 4.x or .NET Standard 2.0...

    The submitted bug is here: https://fogbugz.unity3d.com/default.asp?1134818_qlf5g41lutt066p4

    This is similar to the System.Net.Http.dll behavior that was previously fixed. This is preventing us from creating builds and shipping product. Is there path I can take to try to escalate?
     
  28. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    3,980
    I'm not too familiar with System.ServiceModel.Primitives.dll, but it looks like it is not part of .NET Standard 2.0. Is that correct? It seems like it might be a separate assembly that is built against .NET Standard 2.0. If so, you will need to copy it to the Assets/ folder of your project.
     
  29. stonstad

    stonstad

    Joined:
    Jan 19, 2018
    Posts:
    90
    Thanks for responding! I'm confused about what is included in Unity and what isn't. For .NET 4.x I would think this would be supported. Take a look at this repository: https://github.com/dotnet/wcf/tree/master/src

    Unity supports System.ServiceModel, SystemServiceModel.Http but not System.ServiceModel.Primitives. What is the guiding principle to determine which assemblies are included? And if one in particular is not included (i.e. System.ServiceModel.Primitives) what process do I follow to make sure I select the correct version?
     
  30. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    3,980
    Yes, this is all very confusing for me as well (and pretty much everyone I've talked to about it).

    With Unity, we currently include all of the assemblies in the .NET 4.7.1 API. We cannot implement all of the types in those assemblies on all platform (e.g. we don't implement any of the types in System.Windows.Forms.dll). I expect that future versions of Unity will implement higher versions of the .NET 4 API, but we're on 4.7.1 now.

    I don't know of a good reference on the web for the assemblies in the .NET 4.7.1 API, but you can find them in the C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.7.1 directory with a default installation of the .NET Framework.

    I do not see System.ServiceModel.Primitives.dll in that directory, so I suspect it is a separate assembly available via nuget.

    I would select a version that is compatible with .NET Standard 2.0. That should work with Unity.
     
  31. stonstad

    stonstad

    Joined:
    Jan 19, 2018
    Posts:
    90
    I completely appreciate the candor and your invaluable assistance to help us understand this better. So a funny observation here -- System.ServiceModel.Primitives is in the \v.4.7.1 directory under \facades.



    When using csc.rsp the editor loads System.ServiceModel.Http but not System.ServiceModel.Primitives.
     
  32. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    3,980
    That facades directory is for assemblies that are not a part of .NET 4.7.1, but are necessary to help .NET 4.7.1 implement .NET Standard (any version).
     
  33. stonstad

    stonstad

    Joined:
    Jan 19, 2018
    Posts:
    90
    OK, got it. Thanks Josh for all your help and insight here. Very much appreciated!
     
  34. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    3,980
    Any time! This .NET ecosystem can be difficult to navigate and understand, so I appreciate the ability to discuss these things.
     
  35. Ben-BearFish

    Ben-BearFish

    Joined:
    Sep 6, 2011
    Posts:
    1,175
    @JoshPeterson Could I ask you how to use a csc.rsp file to force Warnings as Errors?
     
  36. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    3,980
    Ben-BearFish likes this.
  37. Ben-BearFish

    Ben-BearFish

    Joined:
    Sep 6, 2011
    Posts:
    1,175
  38. JVaughan

    JVaughan

    Joined:
    Feb 6, 2013
    Posts:
    22
    Dealing with a similar issue as above in Unity 2019.1.10f1.
    I've been attempting to add UIAutomationProvider.dll via csc.rsp (and copying it into the project, and most of the myriad permutation I've read about above).

    Long story short this doesn't seem to work:
    -r:UIAutomationProvider.dll

    that just gives me the following error:
    C:/Users/Josh/Desktop/NativePlugins/Assets/csc.rsp Parse Error : C:/Users/Josh/Desktop/NativePlugins/Assets/csc.rsp: not parsed correctly: UIAutomationProvider.dll could not be found as a system library.
    If this was meant as a user reference please provide the relative path from project root (parent of the Assets folder) in the response file.
    UnityEditor.Scripting.ScriptCompilation.EditorCompilationInterface:TickCompilationPipeline(EditorScriptCompilationOptions, BuildTargetGroup, BuildTarget)


    adding the .dll in the assets folder and the updating the reference in the .rsp file just results in:
    Microsoft (R) Visual C# Compiler version 2.9.1.65535 (9d34608e)
    Copyright (C) Microsoft Corporation. All rights reserved.
    error CS0006: Metadata file '/UIAutomationProvider.dll' could not be found


    My script and runtime are both set to 4.x and when I've copied the file I tried versions from each .NET runtime version, no luck. These seems like something that should be supported on Windows as it has been part of the .NET Standard since version 3.0.
     
  39. Tautvydas-Zilys

    Tautvydas-Zilys

    Unity Technologies

    Joined:
    Jul 25, 2013
    Posts:
    6,443
    I don't know what that DLL is, but adding it to the project and correctly configuring it in the plugin importer should be enough. You don't need to put it into csc.rsp.
     
  40. Magasenakwa

    Magasenakwa

    Joined:
    Oct 13, 2018
    Posts:
    47
    I am having the exact same issue as @JVaughan but in 2018.2 (project depends on an asset that no longer works starting in 2018.3 so stuck on this version so I need to understand how to get this working in this version please)

    I have the exact same error when trying to use
    -r:System.Windows.Forms.dll

    Code (csharp):
    1.  
    2. Assets\mcs.rsp Parse Error : D:/ActiveUnityProjects/Test\Assets\mcs.rsp: not parsed correctly: System.Windows.Forms could not be found as a system library.
    3. If this was meant as a user reference please provide the relative path from project root (parent of the Assets folder) in the response file.
    4. UnityEditor.Scripting.ScriptCompilation.EditorCompilationInterface:TickCompilationPipeline(EditorScriptCompilationOptions, BuildTargetGroup, BuildTarget)
    5.  
    I am copying the dll from the Unity installation folder and placing it inside the Assets/Plugins folder and that works perfectly BUT the docs say "Use the rsp file and DON'T place the DLLs into your project" andso I try to NOT copy dlls from the Unity installatioon folder into my project and try to include the reference as described... but trying to do thing "the right way" causes me all these errors (duplicates of the same one) while doing it "the wrong way" works just fine

    What amI missing? How do I do this correctly? Thanks

    Code (csharp):
    1. -nowarn:0414
    2. -nowarn:0618
    3. -nowarn:0649
    4. -nowarn:0612
    5. -r:System.Windows.Forms.dll
    6.  
     
  41. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    3,980
    The System.Windows.Forms.dll assembly is not supported bu Unity, and so I don't believe it will work in any case. Out of curiosity, what do you need to use from Windows Forms? Maybe there is a different solution we can suggest.
     
  42. Magasenakwa

    Magasenakwa

    Joined:
    Oct 13, 2018
    Posts:
    47
    Hi Josh

    Thanks for getting back to me so quickly.

    There are two reasons why I am using this. The thing I was doing last night was trying to show a native popup to select a folder on my filesystem. Adding Windows.Forms.dll to the Plugins folder makes that an absolue breeze since our application is targetting Windows desktop only!

    The other reason is due to us wanting to detect a button press on a webcam and I don't knowof any functionality in Unity that can detect inputs being pressed on webcams... Fortunately, we found the AForge C# library and they have a working demo doing EXACTLY what we want to do but their demo ws made as a Win Forms app and thus they use structs from that lib while they do their camera detection and testing for inputs fromthe camera.

    If we want o duplicate what they have doen then we need to use what they used.

    Earlier today I found an open source library for Unity that opens up naative file/folder popups and that also uses the same dll but also imports user32.dll as a means of gettingrid of that "This class could not be registered" error that pops up in the editor only starting from the second time you hit play. (It pops up the error then works perfectly fine afterwards, giving the impression that the reference is not destroyed between sessions but at least it still works).

    If you have ANY advice for me onhow to detect that a button was pressed on a webcam then you would be my hero!!! Right now it seems like the only way for me to capture a button press on a webcam is to build a native Windows Form app to capture the video and then embed the binary into my Unity project and display the video capture screen as a separate application. Clearly that is insane overkill but the only other options we have are:
    1. Import Windows.Forms.dll and copy what those guys did in their demo
    2. Wait and see if you have any advice on how to capture button presses on a webcam :)

    I am crossing my fingersand praying to all that is holy in this world that you will come through for me onoption 2 :D
     
  43. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    3,980
    I don't have any suggestions about the webcam, unfortunately. If you really need to use System.Windows.Forms.dll, you can drop it into the Unity project - if that works, I would suggest that route. It is not supported by Unity, but maybe the code that executes for the webcam interaction will work.
     
  44. Magasenakwa

    Magasenakwa

    Joined:
    Oct 13, 2018
    Posts:
    47
    Too bad about the webcam input. I was really hoping you would come through for me on that one :( Oh well, it was an off chance :p

    As to that DLL issue...

    I ran into an interesting problem this morning, though... Inside the editor the popup shows just fine and everything works perfectly.. but when I build the app then the popup doesn't show. I had a look and the dll did get exported with the project so I don't know WHY it doesn't work outside the editor.

    This is why I wanted to remove the dll from the project and link to it using the rsp file, hoping that it will then use the system's dll (the one I added the reference to in VS) and maybe THAT will work... but as soon as I add it tothe resources file I just get those errors I posted above which then force me to drop the DLL back into the project even though the docs (or was it here) say to use the resources file and NOT add the dll to the project

    Basically, the way I understand it is that dropping the DLL into the project is wrong... and I am trying to do it the right way. What is the pointof the resources file if not to link to DLLs that are NOT in the project? ...also, why would you link to a dll that IS already in the project anyway? See my dilemma? The rsp file exists to let me link to the DLL without adding it to the project... and yet doing so just gives me errors.

    So my question is simply: How do I link to that DLL inside the rsp file without it giving me errors?
     
    Last edited: Aug 23, 2019
  45. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    3,980
    Do you mean the System.Windows.Forms.dll, or a DLL for the native code implementation of the open folder dialog that you mentioned earlier in the thread?
     
  46. Magasenakwa

    Magasenakwa

    Joined:
    Oct 13, 2018
    Posts:
    47
    Sorry, maybe I didn't make myself clear enough before. Apologies. By "native code" I meant they guy started writing his code in C# inside VS after creatingthe classes inside of Unity and thus this was a native Unity built everything .... but the code they wrote referenced the System.Windows.Forms dll.

    So their way, my way... we all ue that DLL and that DLL is what I want to link to without copying it into the project. Am I right in saying that is what the rsp files is supposed to accomplish?
     
    Last edited: Aug 23, 2019
  47. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    3,980
    Yes, the .rsp file is used to pass command line arguments to the C# compiler. If you want to reference class library assemblies (DLLs shipped with the .NET Framework), then the .rsp file is the way to go. We recommend this because if you make a copy of a DLL from the class libraries and use it in your project, it can easily become out of sync with the same assembly Unity ships in future versions.

    However, System.Windows.Forms.dll is a bit different. It is normally a class library assembly that is included with .NET Framework. Since Unity does not support it though, a .rsp file won't work in this case. So I think you have two options:

    1. Put a copy of System.Windows.Forms.dll in your Unity project. If it works, great! this is not something Unity supports though.

    2. Write custom C# code to p/invoke into the Windows C API to show the open file/folder dialog. This is not actually as difficult as it sounds, it is supported by Unity, and it will let you only use what you need (System.Windows.Forms.dll has a lot of code you probably don't need). For example, check out this solution: https://stackoverflow.com/questions/9088227/using-getopenfilename-instead-of-openfiledialog (there are many others available as well).
     
  48. Magasenakwa

    Magasenakwa

    Joined:
    Oct 13, 2018
    Posts:
    47
    I will definitely check out that link. Thanks.

    I unerstand you saying "That IS what it is for, yes, but this one DLL is different". I can easily say "Well okay then. If that is the case so be it" ... but your description of WHY it's different is a bit unclear. Not that it matters but if you COULD explain it a bit better I would be very grateful.

    Here is how I read your last post:
    "The rsp file is used to link to files that come with .NET but since Windows.Forms comes with .NET it works differently fom the other DLLs that come with .NET"
     
    Last edited: Aug 23, 2019
  49. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    3,980
    Since System.Windows.Forms.dll is not supported by Unity, is is not one of the normal class library assemblies that you can use from a .rsp file.

    I hope that makes more sense.
     
  50. Magasenakwa

    Magasenakwa

    Joined:
    Oct 13, 2018
    Posts:
    47
    Ahhhh... so THAT is the difference! You can link in anything from .NET as long as it is SUPPORTED BY UNITY... and this one is not. Okay, yeah, that makes a ton of sense now. Thanks for your time and patience ith me :)

    Greatly appreciated
     
    JoshPeterson likes this.