A custom Roslyn compiler and editor extension to access internals/privates for Unity.
In other words, you can access to any internals/privates in other assemblies, without reflection.
Let's say, "Open sesame!"
<< Description | Installation | Usage | Contributing >>
What's new? See changelog ![](https://camo.githubusercontent.com/d2b575b91203f3309a2dfae23f3b94ed6326bea52ca4eb3929dadc991632e213/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f72656c656173652d646174652f6d6f622d73616b61692f4f70656e536573616d65436f6d70696c6572466f72556e6974792e7376673f6c6162656c3d6c61737425323075706461746564)
Do you want to receive notifications for new releases? Watch this repo ![](https://camo.githubusercontent.com/207ba1c1411bdd054225830b0b76e9fe64a95b447ec0e8964eeb90c7476f61da/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f77617463686572732f6d6f622d73616b61692f4f70656e536573616d65436f6d70696c6572466f72556e6974792e7376673f7374796c653d736f6369616c266c6162656c3d5761746368)
Then Ali Baba climbed down and went to the door concealed among the bushes, and said, "Open, Sesame!" and it flew open.
This package allows to access to any internals/privates in other assemblies, without reflection.
For details about IgnoresAccessChecksToAttribute
, see
No InternalsVisibleTo, no problem – bypassing C# visibility rules with Roslyn.
- Easy to use
- this package is out of the box.
- Allow to access to any internal/private elements (types/members) in other assemblies, without reflection
- Create instance
- Get/set fields or properties
- Call method
- Create extension method that contains private access
- etc.
- Processes only
AssemblyDefinitionFile
you configured - Add/remove the scripting define symbols for each
AssemblyDefinitionFiles
- Support C#8
- Support
.Net 3.5
,.Net 4.x
and.Net Standard 2.0
dotnet
is not required- Publish as dll
- Published dll works without this package.
- Portable mode
- Without publishing, make the assembly available to access to internals/privates in other assemblies, even in projects that do not have this package installed.
- The best option when distributing as a package.
- Set/get value into readonly field
- Use reflection
- IDE support
- Use Csc-Manager to modify your VisualStudio Code and C# extension.
csc-manager enable-vscode
: Show internals/privates in other assembly.csc-manager disable-vscode
: Hide them.
- Use Csc-Manager to modify your VisualStudio Code and C# extension.
- Unity 2018.3 or later
This package is available on OpenUPM. You can install it via openupm-cli.
openupm add com.coffee.open-sesame-compiler
Find the manifest.json
file in the Packages
directory in your project and edit it to look like this:
{
"dependencies": {
"com.coffee.open-sesame-compiler": "https://github.com/mob-sakai/OpenSesameCompilerForUnity.git",
...
},
}
To update the package, change suffix #{version}
to the target version.
- e.g.
"com.coffee.open-sesame-compiler": "https://github.com/mob-sakai/OpenSesameCompilerForUnity.git#1.0.0",
Or, use UpmGitExtension to install and update the package.
- Select a
AssemblyDefinitionFile
in project view - Configure setting for the assembly in inspector view:
- Open Sesame: Use OpenSesameCompiler instead of default csc to compile this assembly. In other words, allow this assembly to access to internals/privates to other assemblies without reflection.
- Settings: how/hide the detail settings for this assembly.
- Modify Symbols: When compiling this assembly, add/remove semicolon separated symbols. Symbols starting with '!' will be removed.
NOTE: This feature is available even when 'Open Sesame' is disabled - Portable Mode: Make this assembly available to access in internals/privates to other assemblies, even in projects that do not have
Open Sesame Compiler
package installed.
- Modify Symbols: When compiling this assembly, add/remove semicolon separated symbols. Symbols starting with '!' will be removed.
- Publish: Publish this assembly as dll to the parent directory.
- Help: Open help page on browser.
- Enjoy!
- Clone demo branch in this repo and open it with Unity 2018.3 or later
git clone -b demo https://github.com/mob-sakai/OpenSesameCompilerForUnity.git
- The project has some inaccessible compilation errors
- Do not worry, they are proper errors.
The demo project access to internals/privates:
// EditorApplication.CallDelayed is an internal-static method in UnityEditor assembly.
EditorApplication.CallDelayed(() => Debug.Log("delayed"), 1);
- Select
Assets/Tests/Coffee.OpenSesame.Test.asmdef
in project view and activate 'Open Sesame' in inspector view
- Run all edit mode tests in test runner view (
Windows > General > Test Runner
).
The compilation error is gone, but some tests that depend on symbols will not pass.
[Test]
public void DefineSymbols()
{
const string log = "OSC_TEST is defined.";
LogAssert.Expect(LogType.Log, log);
#if OSC_TEST // <- not defined!
Debug.Log(log);
#endif
}
[Test]
public void RemoveSymbols()
{
const string log = "TRACE is not defined.";
LogAssert.Expect(LogType.Log, log);
#if !TRACE // <- defined automatically by Unity!
Debug.Log(log);
#endif
}
- Enable
symbols
to modify scripting define symbols for this assembly.
Then editModify Symbols
toOSC_TEST;!TRACE
. This means "addOSC_TEST
symbol and removeTRACE
symbol for this assembly."
- All tests pass!
For more details, see the article 1 (Japanese) and the article 2 (Japanese).
Issues are very valuable to this project.
- Ideas are a valuable source of contributions others can make
- Problems show where this project is lacking
- With a question you show where contributors can improve the user experience
Pull requests are, a great way to get your ideas into this repository.
See CONTRIBUTING.md.
This is an open source project that I am developing in my spare time.
If you like it, please support me.
With your support, I can spend more time on development. :)
- MIT
- GitHub page : https://github.com/mob-sakai/OpenSesameCompilerForUnity
- Releases : https://github.com/mob-sakai/OpenSesameCompilerForUnity/releases
- Issue tracker : https://github.com/mob-sakai/OpenSesameCompilerForUnity/issues
- Change log : https://github.com/mob-sakai/OpenSesameCompilerForUnity/blob/upm/CHANGELOG.md
- No InternalsVisibleTo, no problem – bypassing C# visibility rules with Roslyn
- Nuget version: https://www.nuget.org/packages/OpenSesameCompiler
- asmdefScriptingDefines(@pCYSl5EDgo) : https://github.com/pCYSl5EDgo/asmdefScriptingDefines
- Csc-Manager(@pCYSl5EDgo) : https://github.com/pCYSl5EDgo/Csc-Manager
- Special thanks to @pCYSl5EDgo, your ideas contributed to improve this package.