• Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
1
Question by YJack · Mar 13, 2016 at 06:21 PM · api.netcrossplatformcompatibilityhack

Check API Compatibility Level

Hello guys,

I'm evolving another solution to put at Asset Store. That solution works ok using .NET 2.0 Subset but I can really improve things using .NET 2.0.

-How can I check if I`m using regular .NET 2.0 or .NET 2.0 Subset? (So I don`t need to force someone to use .NET 2.0 or avoid implement the .NET 2.0 solution)

-It`s possible to add just a single part of .NET 2.0 into a .NET 2.0 subset deploy?

Thanks!

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

2 Replies

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by Bunny83 · Mar 15, 2016 at 02:45 AM

Well, something like that would require you to wrap your code in conditional preprocessor tags. However, as far as i know there's no preprocessor define for the used .NET level. So you can't really detect the API level automatically that way. Everything else that involves checks at runtime won't work as your code wouldn't compile if a used feature isn't available. If the code doesn't compile you can check anything.


edit
Unity now has all sorts of symbols defined for various purposes. Just check the documentation. So the following example is kinda outdated but may be still relevant for custom feature switches.


So the usual solution is to wrap your code in preprocessor tags and simply use your own custom define. If it's just a single c# file you could add the define at the beginning of the file, so the user can comment it in / out. If you have many files which would be affected, the user would need to add the define to the project settings (scripting define symbols). By default you probably want to use .NET 2.0 subset.

 // uncomment the following line if you use .Net 2.0 and not .Net 2.0 subset
 //#define USE_DOTNET20
 
 #if USE_DOTNET20
 // Some code that requires the full .Net 2.0 support
 #else
 // code that is used when working with .Net 2.0 subset.
 #endif

Again if multiple files need that check you should define the symbol in the player settings. You can add a comment to your code that informs the user that he can add that symbol if he want to.

 /***
  If you use .Net 2.0 and not .Net 2.0 subset you should add the following symbol to the scripting define symbols in the player settings(Edit->Project Settings->Player->Other Settings):
 
  USE_DOTNET20
 ***/


Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image YJack · Mar 15, 2016 at 12:18 PM 0
Share

Wonderful answer, Bunny83!

The proposed solution is more our less what I have in $$anonymous$$d as plan B (The plan A is to find a way to "automatically" define USE_DOTNET20. By "Automatically" I mean without user interference).

But you really helped me in the sense of reinforce the possibility of Plan A non-existence.

Best Regards,

avatar image
1

Answer by booferei · Apr 01, 2021 at 02:25 PM

The accepted answer from Mar 15, 2016 is obsolete. Unity added support for the relevant #define directives on version 5.3.4, which, Incidentally, came out on this exact same date - Mar 15, 2016.

These two directives are relevant to the OP's question:

 NET_2_0: Defined when building scripts against .NET 2.0 API compatibility level
 NET_2_0_SUBSET: Defined when building scripts against .NET 2.0 Subset API compatibility level

For more see: Platform dependent compilation.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

39 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Is it okay to have an external .dll referenced in my game? 0 Answers

Unity building error with .dll compiled in .NET 3.5. 0 Answers

Unity API or more? 1 Answer

Unity 5.5 API Compatibility 1 Answer

Need help using Google Drive API from NuGet with Unity 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges