Pour obtenir une clé
d'essai remplissez le formulaire ci-dessous
Demandez des tariffs
Nouvelle licence
Renouvellement de licence
--Sélectionnez la devise--
USD
EUR
RUB
* En cliquant sur ce bouton, vous acceptez notre politique de confidentialité

Free PVS-Studio license for Microsoft MVP specialists
To get the licence for your open-source project, please fill out this form
** En cliquant sur ce bouton, vous acceptez notre politique de confidentialité.

I am interested to try it on the platforms:
** En cliquant sur ce bouton, vous acceptez notre politique de confidentialité.

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"

09 Jui 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
Why should Unity game developers use static analysis?

Date: 11 Mai 2022

Author: Artem Rovenskii

The cost of making a video game has increased over the years. Game development is becoming increasingly complex, the code base is getting larger as well. It's getting harder for developers to track b…
PVS-Studio static analyzer to recheck Unity

Date: 08 Avr 2022

Author: Artem Rovenskii

Unity is one of the most popular game engines. It helps create many excellent cross-platform projects. It's been 4 years since the last time we checked Unity's source code. Time has come again to see…
Checking Barotrauma with the PVS-Studio static analyzer

Date: 31 Mar 2022

Author: Mikhail Evtihevich

Barotrauma is an indie game where you can steer a submarine, hide from monsters, and even play the accordion to save your ship from going down. The Barotrauma project is developed by Undertow Games i…
Playing with null: Checking MonoGame with the PVS-Studio analyzer

Date: 04 Fév 2022

Author: Vadim Kuleshov

The PVS-Studio analyzer often checks code of libraries, frameworks, and engines for game development. Today we check another project — MonoGame, a low-level gamedev framework written in C#.
Nintendo Switch: drop test of the Ryujinx emulator's source code

Date: 30 Jui 2021

Author: Danila Karpov

Each generation, companies like Sony, Microsoft and Nintendo delight their consumers with new consoles and different games for them. Yet there is a caveat - some games exclusively run on their platfo…

Comments (0)

Next comments
Unicorn with delicious cookie
Nous utilisons des cookies pour améliorer votre expérience de navigation. En savoir plus
Accepter