I have been unable to successfully build my Windows RT application from Unity.
I have a bunch of dll files compile against .NET 4.5 targeting Windows 8.1 platform. I have made a WinRT app with a simple GUI, but I need more than that so I look into Unity.
I have read an article on how to reference WinRT dlls in Unity: http://docs.unity3d.com/Manual/windowsstore-plugins.html. I have 6 dlls of my own and one dll from NuGet (protobuf-net library). I have created a dummy project for each of my dlls with at least partially commented bodies and compiled them against Unity .NET 3.5 Subset Base Class Libraries. I had to comment out a couple of public methods because they accept Windows.Storage-related types as parameters, but I do not use them in my scripts so I suppose this is okay.
I have placed all my fake dlls in `Assets/Plugins` and checked 'Editor' only under platforms for plugins. I have placed all my .NET 4.5 dlls under `Assets/Plugins/WSA` and selected 'WSAPlayer' as platform for editor, SDK81 as SDK and respective fake dll as placeholder. My dlls reference `WindowsPreview.Kinect` SDK so I copied it under `Assets/Plugins/WSA` as Unity could not find it.
As far as I understand, Unity will not use my WinRT scripts (at least they throw exceptions because my code is commented out), so I need to build a Visual Studio project. I go File->Build Settings, choose Windows Store, set SDK to 8.1, check Debugging Unity C# projects and development build and try to build it. During player postprocessing stage I get this error:
Exception: Failed to run Reference Rewriter with cmdline --target="Temp/StagingArea\Plugins\WSA\SDK81\ClassLibrary2.dll" --framework="C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETCore\v4.5.1" --additionalreferences="Temp/StagingArea","Temp/StagingArea\TempSerializationWeaver\Plugins\WSA","Temp/StagingArea\TempSerializationWeaver\Plugins\WSA\X86","Temp/StagingArea\TempSerializationWeaver\Plugins\WSA\ARM","Temp/StagingArea\TempSerializationWeaver\Plugins\WSA\SDK81","Temp/StagingArea\TempSerializationWeaver\Plugins\WSA\SDK81\X86","Temp/StagingArea\TempSerializationWeaver\Plugins\WSA\SDK81\ARM" --platform="C:\Program Files (x86)\Windows Kits\8.1\References\CommonConfiguration\Neutral\Windows.winmd" --support="Temp/StagingArea\UnityEngine.dll" --supportpartialns=Unity.Partial --system=System --dbg=pdb --alt=System.Xml.Serialization --ignore=System.IConvertible,mscorlib.[Temp/StagingArea\Plugins\WSA\SDK81\ClassLibrary2.dll]
Catastrophic failure while running rrw: Mono.Cecil.AssemblyResolutionException: Failed to resolve assembly: 'SkeletonTracker, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'
at Unity.ReferenceRewriter.RewriteContext.RewriteResolver.ResolveAndRegisterWinmd(AssemblyNameReference name)
at Unity.ReferenceRewriter.RewriteContext.RewriteResolver.Resolve(AssemblyNameReference name)
at Mono.Cecil.MetadataResolver.Resolve(TypeReference type)
at Unity.ReferenceRewriter.RewriteTypeReferences.Visit(TypeReference type, String referencingEntityName)
at Unity.ReferenceRewriter.ReferenceDispatcher.Visit(MethodReference method, String referencingEntityName)
at Unity.ReferenceRewriter.ReferenceDispatcher.DispatchMethodBody(MethodBody body)
at Unity.ReferenceRewriter.ReferenceDispatcher.DispatchMethod(MethodDefinition method)
at Unity.ReferenceRewriter.ReferenceDispatcher.DispatchMethods(TypeDefinition type)
at Unity.ReferenceRewriter.ReferenceDispatcher.Dispatch()
at Unity.ReferenceRewriter.RewriteOperation.Execute(RewriteContext context)
at Unity.ReferenceRewriter.Program.Main(String[] args)
PostProcessMetroPlayer.RunReferenceRewriter (WSASDK wsaSDK, System.String playerPackage, System.String stagingArea, System.String assemblyPath, System.String winRTLegacyPath) (at C:/buildslave/unity/build/PlatformDependent/MetroPlayer/Extensions/Managed/PostProcessMetroPlayer.cs:325)
MetroPlugin.RunReferenceRewriter (System.String playerPackage, System.String stagingArea, System.String winrtLegacyPath) (at C:/buildslave/unity/build/PlatformDependent/MetroPlayer/Extensions/Managed/MetroPlugin.cs:148)
PostProcessMetroPlayer.PostProcessSDKSpecific (WSASDK targetSDK, BuildTarget target, BuildOptions options, System.String playerPackage, System.String stagingArea, .ProjectImages images, .LibraryCollection libraryCollection) (at C:/buildslave/unity/build/PlatformDependent/MetroPlayer/Extensions/Managed/PostProcessMetroPlayer.cs:890)
PostProcessMetroPlayer.PostProcess (BuildTarget target, BuildOptions options, System.String installPath, System.String stagingAreaData, System.String stagingArea, System.String playerPackage) (at C:/buildslave/unity/build/PlatformDependent/MetroPlayer/Extensions/Managed/PostProcessMetroPlayer.cs:597)
UnityEditor.Metro.BuildPostprocessor.PostProcess (BuildPostProcessArgs args) (at C:/buildslave/unity/build/PlatformDependent/MetroPlayer/Extensions/Managed/ExtensionModule.cs:84)
UnityEditor.PostprocessBuildPlayer.Postprocess (BuildTarget target, System.String installPath, System.String companyName, System.String productName, Int32 width, Int32 height, System.String downloadWebplayerUrl, System.String manualDownloadWebplayerUrl, BuildOptions options, UnityEditor.RuntimeClassRegistry usedClassRegistry) (at C:/buildslave/unity/build/Editor/Mono/BuildPipeline/PostprocessBuildPlayer.cs:316)
UnityEditor.HostView:OnGUI()
ClassLibrary2.dll is one of the dlls I have included, SkeleteonTracked is another of my dlls and ClassLibrary2.dll references SkeletonTracker (it is named ClassLibrary2.dll because Visual Studio refactoring sucks). I have tried messing with things and managed to get same errors with different dlls that make such dependencies. As far as I understand, Unity tries to take the right dlls but cannot resolve that they depend on each other.
I have then decided to check the box `Don't process` for all of my dlls. Unity was able to build the Visual Studio solution. First of all I had to change configuration from ARM to x86. Then I tried building with no success:
The type or namespace name 'GameController' could not be found (are you missing a using directive or an assembly reference?)
`GameController` is one of the namespaces in my dlls. I opened the file the error occured in and
using GameController;
was all red. My Unity scripts were placed under `Assembly-CSharp-metro-vs2013/Assets/Scripts`, but none of my dlls were referenced by the `Assembly-CSharp-metro-vs2013` project. They were all placed under main project ( `New Unity Project`, did not bother renaming) and my scripts could not see them.
Why not add them to the project that has my scripts? I have done that and my statements are no more red. I got an error, saying
There was a mismatch between the processor architecture of the project being built "MSIL" and the processor architecture of the reference "ClassLibrary2", "x86". This mismatch may cause runtime failures. Please consider changing the targeted processor architecture of your project through the Configuration Manager so as to align the processor architectures between your project and references, or take a dependency on references with a processor architecture that matches the targeted processor architecture of your project.
Okay, I changed `Assembly-CSharp-metro-vs2013`'s platform from any cpu to x86. The error is fixed, yet another one pops out:
The command ""C:\Program Files\Unity\Editor\Data\PlaybackEngines\metrosupport\Tools\SerializationWeaver\SerializationWeaver.exe" "C:\Users\Karolis\Documents\old stuff\yogamin-unity\yogamin-Unity\obj\Store 8.1\x86\Debug\x86\Debug\Assembly-CSharp.dll" -pdb -verbose -unity-engine="C:\Users\Karolis\Documents\yogamin-unity\build4\New Unity Project\Unprocessed\UnityEngine.dll" "C:\Users\Karolis\Documents\old stuff\yogamin-unity\yogamin-Unity\obj\Store 8.1\x86\Debug\x86\Debug"" exited with code 1.
So looks like it is trying to inject something into somewhere. I copied the command and ran it separately from command line. The output is the following:
Symbols will be read from C:\Users\Karolis\Documents\yogamin-unity\build3\New Unity Project\Unprocessed\UnityEngine.pdb
Weaving assembly C:\Users\Karolis\Documents\yogamin-unity\yogamin-Unity\obj\Store 8.1\x86\Master\x86\Master\Assembly-CSharp.dll
Symbols will be read from C:\Users\Karolis\Documents\yogamin-unity\yogamin-Unity\obj\Store 8.1\x86\Master\x86\Master\Assembly-CSharp.pdb
Mono.Cecil.AssemblyResolutionException: Failed to resolve assembly: 'MatcherController, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'
at Mono.Cecil.BaseAssemblyResolver.Resolve(AssemblyNameReference name, Reader Parameters parameters)
at Mono.Cecil.DefaultAssemblyResolver.Resolve(AssemblyNameReference name)
at Mono.Cecil.MetadataResolver.Resolve(TypeReference type)
at Unity.Serialization.Weaver.MethodEmitterBase.WillUnitySerialize(FieldDefinition fieldDefinition)
at Unity.Serialization.Weaver.SerializeMethodEmitter.ShouldProcess(FieldDefinition fieldDefinition)
at System.Linq.Enumerable.<>c__DisplayClassf`1.b__e(TSource x)
at System.Linq.Enumerable.WhereEnumerableIterator`1.MoveNext()
at Unity.Serialization.Weaver.MethodEmitterBase.EmitMethodBody()
at Unity.Serialization.Weaver.SerializationWeaver.AddSerializeMethod()
at Unity.Serialization.Weaver.SerializationWeaver.Weave()
at usw.Weaver.WeaveAssembly(String assemblyPath, AssemblyDefinition unityEngineAssemblyDefinition)
at usw.Weaver.Weave()
at usw.Program.RunProgram(ConversionOptions options)
at usw.Program.Main(String[] args)
So it looks like it cannot resolve `MatcherController` assembly that I added to references in my previous step. I commented out all code that uses my assemblies, but that did not fix the error. I had to delete all those references and then it worked. But wait, it does nothing, and the core logic is in my dlls...
So at this point I am dazed and confused and seek your help.
My machine runs:
- Windows 8.1 64 bit
- Unity 5.0.0f4 64 bit (personal edition, just trying things)
- Visual Studio 2013 Ultimate
↧