简体   繁体   中英

Failed to run reference rewriter with command error with unity error when adding a DLL to the assets folder

I have encountered this error when I am adding the DAI.dll to the assets folder. this error happens when I try to build.

UnityException: Failed to run reference rewriter with command --target="Temp\\StagingArea\\DAI.dll" --additionalreferences="Temp\\StagingArea","C:\\Program Files (x86)\\Windows Kits\\10\\UnionMetadata\\10.0.17134.0\\Facade","C:\\Program Files (x86)\\Windows Kits\\10\\References\\10.0.17134.0\\Windows.AI.MachineLearning.Preview.MachineLearningPreviewContract\\1.0.0.0","C:\\Program Files (x86)\\Windows Kits\\10\\References\\10.0.17134.0\\Windows.ApplicationModel.Calls.CallsVoipContract\\3.0.0.0","C:\\Program Files (x86)\\Windows Kits\\10\\References\\10.0.17134.0\\Windows.ApplicationModel.SocialInfo.SocialInfoContract\\2.0.0.0","C:\\Program Files (x86)\\Windows Kits\\10\\References.....(followed by alot more of this)....

I am using visual Studio 2017 version 15.7.3 and Unity version 2017.2.0b7

I have added the DLL to the assets folder in unity.

These are my player and build settings.

在此处输入图片说明

在此处输入图片说明

You need to change the settings in unity ( Settings example in the photo below ):

  1. Find your dll file in your project inside Unity.
  2. Click on it once to highlight it.
  3. You will see the dll options in the Isnpector
  4. Usually for HoloLens, you only select "WSAPlayer"
  5. Click Apply to save settings.
  6. Rebuild 在此处输入图片说明

Warnings

  1. Sometime the dll that you trying to include is referencing something else is not included and that's why it will not work, but the error will be different than what you got.
  2. Sometimes you may need to import an older version of the DLL. For example, I tried to import Newtonsoft.Json 11.0.2, but 11.0.2 was referencing a newer core framework than the solution that unity generate. There is a way to update it, but I didn't want to deal with it every time, so I found out that the highest version that I can use is 9.0.1 (I had to skip 11.0.2, 11.0.1, 10.0.3, 10.0.2, 10.0.1).
  3. Also, keep in mind that you should include netstandard dll.
  4. I usually have UWP test project in hand to try to test my dll with it. If it works there, then it is a good first step that it may work after importing it to Unity assuming it does not have dependencies.

Last result workaround

  1. You can comment the code that references your dll
  2. build the project from unity without the dll
  3. in the generated UWP solution, you can add dll normally and even use nuget to install your desired dll
  4. Uucomment your code.
  5. Build your solution then deploy to your device or create a package to deploy it to device or store.
  6. This works nicely as a work around.
  7. One issue with this is that you will need to import dll or install nuget every time solution generated if it was deleted. It gets annoying and if you are working with a team, it can get confusing when they get the project and think that it does not work. Meaning you need to do more work to communicate and deploy.
  8. Second issue, Unity is moving away from .NET backend to IL2CPP (I don't think you can do this in the CPP generated project). Meaning this is a short term workaround.

Consider upgrading to Unity 2018.2

  1. Using .NET 4.X instead of .NET 3.4 Equivalent made my life easier with references and issues related to references and using more modern C# code.
  2. You can install it and still keep the 2017 version if you install Unity Hub. This will minimize the risk of considering the update.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM