Search Unity

Building Unity app with libraries compiled with .NET 4.0 (Visual Studio 2013)

Discussion in 'Windows' started by bhmed, Feb 5, 2014.

  1. bhmed

    bhmed

    Joined:
    Feb 5, 2014
    Posts:
    16
    I am trying to make an app using the Unity game engine while referencing a library compiled with .NET 4.0. I've noticed that every time I open the project in the Unity Editor, it switches the framework on my Visual Studio solution from 4.0 back to 3.5, so my referenced library is no longer usable. I do not need the functionality of the Unity Editor, I am willing to write my entire program in C# scripts if possible.

    Is it possible to make a .NET 4.0 project without using the Unity Editor? 99% of my code is in C# scripts, but it seems like I still need to have a game object in the Unity Editor with my main script attached to it in order for the Unity window to open.

    Is there a way for me to write a script that makes this first game object for me so I never have to open the Unity Editor? If I do open it then my framework is changed back to .NET 3.5 and I cannot use my .NET 4.0 library.

    I am running Visual Studio 2013 Professional and Unity Editor 4.3.4 on Windows 8.1 with the Windows 8.1 SDK installed.

    Thanks for any help!
     
  2. Tomas1856

    Tomas1856

    Unity Technologies

    Joined:
    Sep 21, 2012
    Posts:
    3,899
    Are you talking about Windows Desktop application, or Windows Store Apps? I don't quite understand what you're trying to achieve here, You'll still need some resources for your application, which can only be added via Unity Editor, sure there are methods like Resources.Load, etc, but still. Could you describe more, what are you doing?
     
  3. bhmed

    bhmed

    Joined:
    Feb 5, 2014
    Posts:
    16
    We are trying to publish a Unity app in the current .NET 4.5 framework that a connected peripheral requires. Is there a way to load the Unity resources without requiring the Unity Editor, since that currently pushes the project framework back to .NET 3.5?
     
    Last edited: Feb 6, 2014
  4. Tomas1856

    Tomas1856

    Unity Technologies

    Joined:
    Sep 21, 2012
    Posts:
    3,899
    When you say 'Unity app', what is it, Unity's Windows Standalone player, or Windows Store Apps?
     
  5. bhmed

    bhmed

    Joined:
    Feb 5, 2014
    Posts:
    16
    It's a standalone application we'd like to run with a Windows standalone player, but have been told needs to publish as a Windows Store App to use the Visual Studio compiler and the current .NET framework. All we want is a method that remains compatible with the .NET 4,5 framework that we need for some included dlls.
     
    Last edited: Feb 6, 2014
  6. Tautvydas-Zilys

    Tautvydas-Zilys

    Unity Technologies

    Joined:
    Jul 25, 2013
    Posts:
    10,674
    Well, that will be problematic, as Unity doesn't run on .NET on Windows Standalone Player (it uses Mono, which only supports up to .NET 3.5).

    The only way I see of making it work would involve native plugins as a bridge. Or, as you mentioned, publishing it as Windows Store Application.
     
  7. bhmed

    bhmed

    Joined:
    Feb 5, 2014
    Posts:
    16
    We have been attempting to publish it as a Windows Store app. That solution would be fine, but we still need a method of creating the first game object without the Unity Editor, which forces everything back to the Mono framework.
     
  8. Tautvydas-Zilys

    Tautvydas-Zilys

    Unity Technologies

    Joined:
    Jul 25, 2013
    Posts:
    10,674
    Last edited: Feb 6, 2014
  9. bhmed

    bhmed

    Joined:
    Feb 5, 2014
    Posts:
    16
    This looks promising and could be just what we need. We're trying it now. Thanks.
     
  10. bhmed

    bhmed

    Joined:
    Feb 5, 2014
    Posts:
    16
    I am trying to compile the first example located here: http://files.unity3d.com/tomas/Metro/Examples/XAMLUnityConnectionV4.zip

    I am able to open the main folder in Unity Editor, open the test scene, and build the project as a Windows Store XAML C++ app in the XAMLConnection\Export directory as the ReadMe.txt says. However, when I open XAMLConnection\Export\XALMConnection.sln I am unable to complete the next step of compiling it. I get the following error:

    1>C:\Program Files (x86)\MSBuild\12.0\bin\Microsoft.Common.CurrentVersion.targets(1635,5): warning MSB3245: Could not resolve this reference. Could not locate the assembly "UnityPlayer". Check to make sure the assembly exists on disk. If this reference is required by your code, you may get compilation errors.

    I see that in the MyCustomPlugin project there is a reference to a "UnityPlayer", but it seems that Visual Studio cannot find it. I've noticed that there is a UnityPlayer.dll located in XAMLUnityConnection\Export\Players\Windows80\X86\debug but when I try adding it to the references I get an error:

    "A reference to XAMLConnection\Export\Players\Windows80\X86\debug\UnityPlayer.dll could not be added".

    I have also tried switching the Visual Studio project build platform from X86 to ARM and using the associated UnityPlayer.dll in the same manner and received the same error.

    Am I correct in assuming that UnityPlayer.dll is generated by the Unity Editor when I built the XAML C++ project? And how can I resolve the missing references to UnityPlayer that are present in the visual studio solution?

    Thank you for your help.
     
  11. Tomas1856

    Tomas1856

    Unity Technologies

    Joined:
    Sep 21, 2012
    Posts:
    3,899
    You must pick winmd file, not dll file, when adding references.
     
  12. Tautvydas-Zilys

    Tautvydas-Zilys

    Unity Technologies

    Joined:
    Jul 25, 2013
    Posts:
    10,674
    Also, I'd suggest building to an empty folder from Unity Editor, as opposed over files that were probably built with another Unity version. You can modify the code generated by Unity Editor manually after it creates a Visual Studio solution.
     
  13. bhmed

    bhmed

    Joined:
    Feb 5, 2014
    Posts:
    16
    We are still having trouble compiling the Visual Studio solution created by the Unity Editor. We have tried making a new project in Unity Editor and immediately building it into a Windows Store app without modification. Since we would prefer to use C#, we selected the type as "XAML C# Solution" and used the 8.1 SDK. After the build finished we opened the resultant Visual Studio solution and tried to compile. The following error was shown:

    Error 1 Error : DEP0700 : Registration of the app failed. Windows cannot install package NewUnityProject because the package requires architecture ARM, but this computer has architecture x64. (0x80073cf3)

    We have tried changing the build platform in the project settings to ARM and x86, but the error still shows.

    Does Unity support x64 Store apps? And if not how can we get the Visual Studio solution to compile?

    Our ultimate goal is to add a .NET 4.5 library as a reference to the Visual Studio solution and then modify the code that is generated by Unity Editor as you stated in your comment (in order to call functions from said library).

    Thank you.
     
  14. Tomas1856

    Tomas1856

    Unity Technologies

    Joined:
    Sep 21, 2012
    Posts:
    3,899
    X86 should be working fine on X64 systems.

    And no, Unity currently doesn't support X64 Windows Store Apps, in other words - pick X86 configuration.

    P.S You won't be able to reference .NET 4.5, because Windows Store Apps can only reference .NET for Windows Store Apps.
     
  15. bhmed

    bhmed

    Joined:
    Feb 5, 2014
    Posts:
    16
    How do I change the configuration to X86? When I change it in the Visual Studio program properties I get the same error as I posted above.

    Is there a way to produce a Unity application that uses .NET 4.5?
     
    Last edited: Feb 7, 2014
  16. Tomas1856

    Tomas1856

    Unity Technologies

    Joined:
    Sep 21, 2012
    Posts:
    3,899
    Could you copy - paste the error, because the error you posted above signifies, that you can't run ARM application on X64 OS. But I assure you can run X86 applications on X64 machines.

    No.