部署Hololens 101教程Origami时遭遇CS0012错误求助
Hey there, sorry to hear you've been stuck on this CS0012 error for a week—let's break down the possible fixes step by step based on your setup:
1. Fix the Missing Windows Runtime Assembly Reference Directly in Visual Studio
The error explicitly points to a missing assembly reference, so let's address that first:
- Open the UWP project located at
Origami/App/GeneratedProjects/UWPin Visual Studio 2017 - Right-click your project in the Solution Explorer → Add → Reference
- In the Reference Manager window, navigate to Universal Windows → Extensions
- Look for the assembly named
Windows(matching the version255.255.255.255mentioned in the error) and check the box next to it - Click OK to save, then try rebuilding the project
2. Verify Unity Player Settings for UWP Compatibility
Misconfigured Unity settings are a common culprit for cross-platform build errors. Let's double-check:
- In Unity, go to Edit → Project Settings → Player
- Switch to the UWP tab
- Under Other Settings:
- Set Scripting Runtime Version to
.NET 4.x Equivalent(older versions like .NET 3.5 often cause assembly reference conflicts) - Set Api Compatibility Level to
.NET 4.x - Ensure Target SDK Version matches the Windows 10 SDK installed in your Visual Studio (setting it to
Latest Installedavoids version mismatches)
- Set Scripting Runtime Version to
- After adjusting these settings, re-export the UWP project from Unity and try building again
3. Address the Assembly-CSharp-firstpass Observation
Don't stress too much about the missing Assembly-CSharp-firstpass folder—this assembly only gets generated when you have scripts placed in Unity's Plugins directory (it prioritizes compiling plugin scripts before regular game scripts):
- If your project doesn't have any plugins or scripts in the
Pluginsfolder, it's completely normal for this assembly to be missing. This is likely not the root cause of your CS0012 error. - If you suspect plugins might be involved, try creating an empty
Pluginsfolder in your Unity project, add a dummy C# script inside it, then re-export the UWP project to see if the assembly appears.
4. Clean and Rebuild to Eliminate Cache Issues
Corrupted build cache often causes odd reference errors:
- In Visual Studio: Go to Build → Clean Solution, then delete the
binandobjfolders in your UWP project directory. Rebuild the solution afterward. - In Unity: Go to Edit → Clear All PlayerPrefs, or (for a deeper clean) close Unity, delete the
Libraryfolder in your project directory (back up your project first!), then reopen Unity and re-export the UWP project.
5. Check for Version Compatibility
Your Visual Studio 2017 15.7.1 is a bit outdated. While it's technically compatible with Unity 2017.2.0f3, updating to the latest patch for VS 2017 (version 15.9.x) might resolve hidden compatibility bugs. You can do this via the Visual Studio Installer.
Also, if your scripts directly reference CoreApplicationView or CoreWindow, wrap those references in platform-specific conditional compilation to ensure they only run in UWP:
#if UNITY_WSA_10_0 using Windows.UI.Core; // Your code using CoreApplicationView/CoreWindow here #endif
Hope one of these steps gets you past the build error!
内容的提问来源于stack exchange,提问作者gladys0313

