Our website uses cookies to enhance your browsing experience.
Accept
to the top
close form

Fill out the form in 2 simple steps below:

Your contact information:

Step 1
Congratulations! This is your promo code!

Desired license type:

Step 2
Team license
Enterprise license
** By clicking this button you agree to our Privacy Policy statement
close form
Request our prices
New License
License Renewal
--Select currency--
USD
EUR
* By clicking this button you agree to our Privacy Policy statement

close form
Free PVS‑Studio license for Microsoft MVP specialists
* By clicking this button you agree to our Privacy Policy statement

close form
To get the licence for your open-source project, please fill out this form
* By clicking this button you agree to our Privacy Policy statement

close form
I am interested to try it on the platforms:
* By clicking this button you agree to our Privacy Policy statement

close form
check circle
Message submitted.

Your message has been sent. We will email you at


If you haven't received our response, please do the following:
check your Spam/Junk folder and click the "Not Spam" button for our message.
This way, you won't miss messages from our team in the future.

>
>
>
Unity projects analysis: the solution f…

Unity projects analysis: the solution file has two projects named "UnityEngine.UI"

Jun 09 2021

While PVS-Studio analyses a Unity project, one may stumble upon such an error: Error was encountered while trying to open solution file '...': The solution file has two projects named "UnityEngine.UI". This note discusses the reasons for this error and how to eliminate it.

Reasons

PVS-Studio uses some third-party libraries, including Roslyn and MSBuild to check C# projects. We use Roslyn to parse code. MSBuild parses solution (.sln) and project (.csproj) files. Besides, MSBuild is the main .NET build system.

You may encounter the error above when you call the Microsoft.Build.Construction.SoltuionFile.Parse method to receive a SolutionFile instance. The method is in the external library for the analyzer (Microsoft.Build.dll), so we can't change its behavior directly.

If you look closer at the text representation of the .sln file, you can notice duplicates in it. Example: (IDs of project types are shorter to make the example more compact).

0834_UnityProjectsDuplicates/image1.png

Note that this .sln file duplicates project names: UnityEngine.UI and Assembly-CSharp. Each instance corresponds to a unique project file. For example, these are UnityEngine.UI.csproj and UnityEngine.UI.Player.csproj for UntiyEngine.UI.

If you try to build this solution by MSBuild, you will see an already familiar error: Solution file error MSB5004: The solution file has two projects named "UnityEngine.UI".

Interestingly, Visual Studio and JetBrains Rider, unlike MSBuild, are able to build such projects. Apparently, they use a different build mechanism (maybe they parse the .sln file themselves).

Possible solutions

A possible solution is to change project settings. The Unity editor generates an .sln file with duplicates if the "Player projects" option is enabled. Disable it in the same Unity editor: Edit -> Preferences -> Player projects.

0834_UnityProjectsDuplicates/image2.png

After that, you may need to regenerate project files. The "Regenerate project files" button below is right for this.

Then duplicates from the .sln file must disappear, and the analysis should work fine.

If this method does not help or is not suitable for you, please email us.

Conclusion

We strive to improve the analysis of Unity projects. If you encounter any problems or have any wishes, please feel free to write to us.

Popular related articles


Comments (0)

Next comments next comments
close comment form