Long time reader, first time poster.
I have written a Unity project where a user can upload an asset to an endpoint and the endpoint will generate an AssetBundle. Right now it is just running on my computer.
The idea is the endpoint computer runs the command prompt Unity editor code and bundles it with:
Which works fine and great in the Unity GUI
Works fine and great on the Command Prompt
Crashes on the ASP.NET site.
The site is running my user so I don’t believe it is a permissions issue, but seems to be an issue with the project.lock.json and project.json files.
Here are somethings I observed:
Running in GUI created the project.json and project.lock.json files
Running in Command Prompt re-used the files
Running on the .NET site DELETES the files
Building a Windows Standalone AssetBundle works fine on .NET, but WSAPlayer fails
I did take the liberty of saving the log files
Command Prompt log file
Platform assembly: C:\program files\Unity\Editor\Data\Managed\Unity.CecilTools.dll (this message is harmless)
Restoring NuGet packages from ‘C:\uploadServer\Unity\commandPromptCode\UWP\project.json’.
DisplayProgressbar: Building Player
NuGet packages successfully restored.
*There are also cases where it reuses the project.json if available
.NET log file
Platform assembly: C:\program files\Unity\Editor\Data\Managed\Unity.CecilTools.dll (this message is harmless)
Restoring NuGet packages from ‘C:\uploadServer\Unity\commandPromptCode\UWP\project.json’.
DisplayProgressbar: Building Player
Project lock file validation failed.
DisplayProgressNotification: Build Failed
Error building Player: Failed to restore NuGet packages.
(Filename: Line: -1)
I am not entirely sure if this has to do with my IIS settings or it is something locally. But it is truly strange that it deletes the project.json and project.lock.json files
Other people have very recently reported similar issues:
However, we were never able to reproduce this locally. Would you be willing to give us access to (perhaps stripped down) ASP.NET program so we could figure out what’s going on?
Can you fill a bug report with details so our QA could look into it and it wouldn’t get lost? Forum is not the best place for tracking issues like these.
Hello,
any luck with the solution? I’m facing the same problem right now. BuildPipeline.BuildAssetBundles works fine when running from editor, cmd or powershell, but crashes when called by ASP.NET Web API.
Many thanks for any answer.
I’ll try to describe how my solution works:
I have Web API that is called by Angular app from browser.
When I upload file, Web API copies the file to Resources of Unity project, and runs Unity in batch mode:
Process process = new Process();
process.StartInfo.FileName = "C:\Program Files\Unity 2017.4.4f1\Editor\Unity.exe";
process.StartInfo.Arguments = " -batchmode -quit -projectPath "D:\Workspace\AssetBundlesBuilder" -executeMethod CreateAssetBundles.BuildwsaAssetBundles -logfile D:\log\log-AssetBundlesBuild.txt"
process.Start();
process.WaitForExit();
Method BuildwsaAssetBundles adds colliders and makes some optimizations and finally there is:
In IIS Application Pool i set the user to “me” (my user account) - admin account, to assure the permissions.
My findings:
When I run debug I can see that while executing BuildPipeline.BuildAssetBundles, files project.json and project.lock.json are deleted from UWP folder in Unity project.
In log file there is an error:
Restoring NuGet packages from 'D:\Workspace\ProjectPath\AssetBundlesBuilder\UWP\project.json'.
DisplayProgressbar: Building Player
Project lock file validation failed.
DisplayProgressNotification: Build Failed
Error building Player: Failed to restore NuGet packages.
When I run Unity from Powershell with command: & "C:\Program Files\Unity 2017.4.4f1\Editor\Unity.exe" -batchmode -quit -projectPath "D:\Workspace\ProjectPath\AssetBundlesBuilder" -executeMethod CreateAssetBundles.BuildwsaAssetBundles -logfile D:\log\log-AssetBundlesBuild.txt, asset bundles are built correctly
Also when I run method from Unity (I added it to menu [MenuItem("Assets/Build WSA")]) everything works fine.
I checked and logged users and they are “me” in all cases.
We managed to solve it via PM. Basically, Unity and NuGet were launched with a different set of environment variables. The solution was to force NuGet cache directories to match between Unity and NuGet by setting an environment variable before building your bundles:
var cacheDir = @"D:\NuGet";
Directory.CreateDirectory(cacheDir);
Environment.SetEnvironmentVariable("NUGET_PACKAGES", cacheDir);