There is a problem with newtonsoft.json.dll after adding plastic SCM
A while ago, I opened a new personal project. Because it is a new project, I use the latest ones for everything I want. Therefore, I used plastic SCM officially launched by unity for version control
the plug-in was installed at the beginning. There was nothing wrong with it and it was OK to use. But as the project code piles up, well, the problem arises.
Because I use the powerful newtonsoft. JSON library. After it was added to the project, there was nothing wrong with using it a few days ago and it can be used normally. However, when I used this library in the code of the editor, I referenced the newtonsoft.json namespace and found that the problem came out. Unity kept reporting errors:
There are two in the project newtonsoft.json. This baffled me. After positioning, I found that there is also a newtonsoft.json Library in the plastic SCM package:
good heavens! You also changed someone’s name, # ¥% @# ¥, at least you also changed the namespace… You have a big surprise! Well, I’ll admit it. Who told me to use your stuff
Since you are determined to use it, I’ll think about how to solve it. Because I had no problem in the non editor code before, it may be that the JSON Library in the SCM package itself only runs in the editor mode, and some of the editor codes we wrote refer to the library in the SCM package… Speechless
My current solution:
Option 1:
Delete the original library and copy the in plastic SCM to the project to keep the versions of the two DLLs consistent:
1. Delete the JSON library referenced by ourselves in the project
2. Right click to find the physical path of the JSON Library in plastic SCM:
3. Find it and copy it to the plugins directory of our project, and modify its name as newtonsoft.json.dll
4. Then enter the project and wait for the compilation to be completed
Option 2:
Do not delete the JSON library you put into the project, and keep it coexisting with plastic SCM. However, there are requirements for the storage location of the physical path of the code file because. Asmdef is used.
1. Sort out the code of our editor and create an asmdef file (assembly definition file) in the relative root directory of the code:
For example, in my project, I was working on a level editor, so I sorted the code of the level editor into a levelmaker/scripts directory, and then right-click in the levelmaker directory to create asmdef:
As for sorting the code, if you do well in directory planning in the early stage, there should be no problem. As for how much code an asmdef file contains, it depends on the situation of the project. Some projects are more fine-grained. As for the code of the editor, I generally like to divide it by each tool.
2. After creating the. Asmdef file, unity will enclose our editor code and finally compile it into an independent DLL. Check the override reference option in the setting of. Asmdef, and the assembly references setting item will appear:
3. Add a reference to the dot product + sign, select the DLL file we need to specify the reference, and wait for compilation after applying
4. Finally, don’t forget to check the platform option in the settings, otherwise there will be problems in compiling when publishing
Option 3:
This method is not recommended because I haven’t used it. Just think of
Copy the plastic SCM separately, which is not maintained by packagesmanager, and put it in the plugins directory, so we can do whatever we want… For example, replace the JSON library it refers to with our own… Well, this sounds a bit like scheme 1… In fact, unity has also modified the JSON library it refers to
I don’t recommend it. After all, packagesmanager maintenance is very good, and any version iteration can be updated as soon as possible… After all, plastic SCM is just a tool
Option 4:
Find the source code of the JSON library, and compile your own JSON library after modification… Um…
newtonsoft. JSON library source code: https://github.com/JamesNK/Newtonsoft.Json