Is there any way to tell Unity to generate the solution files through script (perhaps some undocumented API) or through the command line?
For context - I’d like to run some code analysis tools on my C# code, on a build machine, from the command line. Many of these tools operate on solution files rather than directories of source files.
I don’t want to check in the solution files - that way madness lies.
As far as I can see they’re only generated upon opening a script or the solution from within the Unity editor. Running a command line build doesn’t seem generate any solution files, even in Library/ or Temp/.
This works at least in 5.4.2f2, but it’s likely it’ll work in older versions of Unity. In much older versions, that same option was called something different, but it might work in those too.
That’s a great idea Chippit, thanks! Do you know if this works from a build script called using batch mode and ‘-executeMethod’?
I ended up writing a Python script to generate solution and project files - it’s not perfect (as it requires some knowledge of the Unity project structure) but it’s enough to generate a solution file that many command-line tools (e.g. ReSharper) are happy with.
This is precisely how I have used it, so I can confirm that that works. Unlike when clicking the menu item from a normal running instance of Unity, it also does not attempt to shell execute the file so it won’t open it in VS/Monodev/whatever editor you use when you do it from batch mode.
Could someone please elaborate on where does “EditorApplication.ExecuteMenuItem(“Assets/Open C# Project”);” need to go in order to generate solution file from command line?
Also, has anyone tried this in headless Unix environment (I’m using docker image for builds)?
Is your class definitely called ‘Game’? Is it available to the editor, i.e. in an ‘Editor’ folder? You’ve misspelled ‘-quit’.
Also something catching me out recently is that sometimes VSTU doesn’t connect properly; I had to hook it up by choosing the external script editor in the preferences screen of Unity (find and choose devenv.exe).
This requires your project to compile. We have an issue with auto generated code (from Entitas). The auto-generated code is gitignored, so I wanted to generate it as the first step of my CI/CD build. However this requires a .csproj to be generated first.
Unfortunately, running UnityEditor.SyncVS.SyncSolution from command line fails, as the project doesn’t compile. This is strange, because it’s possible from Unity’s menu item Assets/Open C# Project.
@mdab121 I suppose the correct workaround for this is to ensure you code compile when calling SyncSolution from command line.
I purposely made a error in my c#:
Scripts have compiler errors.```
Unity wont even call SyncSolution from command line (so no .sln or .csproj will be generated).
I dont know about any workaroud to avoid unity to abort batchmode.