https://github.com/mob-sakai/OpenSesameCompilerForUnity
A Roslyn compiler 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!"
https://github.com/mob-sakai/OpenSesameCompilerForUnity
compiler csharp editor internal private roslyn unity unity3d upm-package
Last synced: 5 months ago
JSON representation
A Roslyn compiler 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!"
- Host: GitHub
- URL: https://github.com/mob-sakai/OpenSesameCompilerForUnity
- Owner: mob-sakai
- License: mit
- Created: 2019-12-25T00:57:17.000Z (almost 6 years ago)
- Default Branch: upm
- Last Pushed: 2020-10-06T13:34:54.000Z (almost 5 years ago)
- Last Synced: 2024-10-30T00:04:48.267Z (11 months ago)
- Topics: compiler, csharp, editor, internal, private, roslyn, unity, unity3d, upm-package
- Language: C#
- Homepage: https://github.com/mob-sakai/OpenSesameCompilerForUnity
- Size: 405 KB
- Stars: 105
- Watchers: 8
- Forks: 7
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Funding: .github/FUNDING.yml
- License: LICENSE.md
Awesome Lists containing this project
README
Open Sesame Compiler For Unity
===**:warning: NOTE: This project has been integrated into [CSharpCompilerSettingsForUnity](https://github.com/mob-sakai/CSharpCompilerSettingsForUnity). We are NOT continuing development in this repository. :warning:**
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!"**


[](https://openupm.com/packages/com.coffee.open-sesame-compiler/)
[](https://github.com/mob-sakai/OpenSesameCompilerForUnity/releases)
[](https://github.com/mob-sakai/OpenSesameCompilerForUnity/releases)

[](https://github.com/mob-sakai/OpenSesameCompilerForUnity/blob/upm/LICENSE.txt)
[](http://makeapullrequest.com)
[](https://twitter.com/intent/follow?screen_name=mob_sakai)<< [Description](#description) | [Installation](#installation) | [Usage](#usage) | [Contributing](#contributing) >>
### What's new? [See changelog ](https://github.com/mob-sakai/OpenSesameCompilerForUnity/blob/upm/CHANGELOG.md)
### Do you want to receive notifications for new releases? [Watch this repo ](https://github.com/mob-sakai/OpenSesameCompilerForUnity/subscription)
### Support me on GitHub!
[](https://github.com/users/mob-sakai/sponsorship)
## Description> _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](https://www.strathweb.com/2018/10/no-internalvisibleto-no-problem-bypassing-c-visibility-rules-with-roslyn/).#### Features
* 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.#### NOTE: Unsupported Features
* Set/get value into readonly field
* Use reflection
* IDE support
* Use [Csc-Manager](https://github.com/pCYSl5EDgo/Csc-Manager) to modify your [VisualStudio Code](https://code.visualstudio.com/download) and [C# extension](https://marketplace.visualstudio.com/items?itemName=ms-vscode.csharp).
* `csc-manager enable-vscode`: Show internals/privates in other assembly.
* `csc-manager disable-vscode`: Hide them.
## Installation#### Requirement
* Unity 2018.3 or later
#### Using OpenUPM
This package is available on [OpenUPM](https://openupm.com).
You can install it via [openupm-cli](https://github.com/openupm/openupm-cli).
```
openupm add com.coffee.open-sesame-compiler
```#### Using Git
Find the `manifest.json` file in the `Packages` directory in your project and edit it to look like this:
```json
{
"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](https://github.com/mob-sakai/UpmGitExtension) to install and update the package.
## Usage1. Select a `AssemblyDefinitionFile` in project view
2. 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.
* **Publish**: Publish this assembly as dll to the parent directory.
* **Help**: Open help page on browser.
1. Enjoy!
## Demo1. 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
```
2. The project has some inaccessible compilation errors

3. Do not worry, they are proper errors.
The demo project access to internals/privates:
```cs
// EditorApplication.CallDelayed is an internal-static method in UnityEditor assembly.
EditorApplication.CallDelayed(() => Debug.Log("delayed"), 1);
```
4. Select `Assets/Tests/Coffee.OpenSesame.Test.asmdef` in project view and activate 'Open Sesame' in inspector view

5. 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.

```cs
[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
}
```
6. Enable `symbols` to modify scripting define symbols for this assembly.
Then edit `Modify Symbols` to `OSC_TEST;!TRACE`. This means *"add `OSC_TEST` symbol and remove `TRACE` symbol for this assembly."*

1. All tests pass!
For more details, see [the article 1 (Japanese)](https://qiita.com/mob-sakai/items/f3bbc0c45abc31ea7ac0) and [the article 2 (Japanese)](https://qiita.com/mob-sakai/items/a24780d68a6133be338f).
## Contributing### Issues
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
Pull requests are, a great way to get your ideas into this repository.
See [CONTRIBUTING.md](/../../blob/develop/CONTRIBUTING.md).### Support
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. :)[](https://www.patreon.com/join/mob_sakai?)
[](https://github.com/users/mob-sakai/sponsorship)
## License* MIT
## Author
[mob-sakai](https://github.com/mob-sakai)
[](https://twitter.com/intent/follow?screen_name=mob_sakai)## See Also
* 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](https://www.strathweb.com/2018/10/no-internalvisibleto-no-problem-bypassing-c-visibility-rules-with-roslyn/)
* Nuget version: https://www.nuget.org/packages/OpenSesameCompiler
* asmdefScriptingDefines([@pCYSl5EDgo](https://github.com/pCYSl5EDgo)) : https://github.com/pCYSl5EDgo/asmdefScriptingDefines
* Csc-Manager([@pCYSl5EDgo](https://github.com/pCYSl5EDgo)) : https://github.com/pCYSl5EDgo/Csc-Manager## Special Thanks
* Special thanks to [@pCYSl5EDgo](https://github.com/pCYSl5EDgo), your ideas contributed to improve this package.