How do I add Unity support to a NuGet package?

2020-07-10 20:21发布

问题:

How do I publish a package to NuGet that supports Unity (the game engine)?

Also, do I need to have Unity installed to compile it, or is targeting a specific framework version enough?

回答1:

How do I publish a package to NuGet that supports Unity (the game engine)?

Just follow the instructions in the doc. Class library for Unity3D is nothing different from regular .NET Class library. It just uses a different runtime comes from Unity3D's fork of mono.

Also, do I need to have Unity installed to compile it, or is targeting a specific framework version enough?

Yes. If your library uses Unity3D types, the project needs to reference assemblies, such as UnityEngine.dll and UnityEditor.dll, from Unity3D. If your library doesn't use Unity3D types, you still need to test it with Unity3D. Because older Unity3D targets .NET 2.0 and a subset of .NET 3.5. So if your library uses features only available in .NET 4+, it won't work with Unity3D. See also Using dll.

It's better to install Visual Studio Tools for Unity3D for VS2015 (for VS2017, install VSTU in the VS installer instead) and then you can target one of the Unity3D targets:

As for the publishment of your package, I think you'd better publish your package on Unity3D asset store since it is officially supported. You may want to try this improved version of Unity3D asset store tools when publishing your package to the asset store.



标签: c# unity3d nuget