Skip to content

Commit

Permalink
Merge pull request #8 from mob-sakai/develop
Browse files Browse the repository at this point in the history
Release 3.4.0
  • Loading branch information
mob-sakai committed Sep 8, 2020
2 parents da038e4 + 5fae908 commit 52fa070
Show file tree
Hide file tree
Showing 19 changed files with 6,853 additions and 93 deletions.
35 changes: 35 additions & 0 deletions .github/workflows/package_release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
name: release

on:
push:
branches:
- master
- alpha
- beta

jobs:
build:
runs-on: ubuntu-latest

steps:

- uses: actions/checkout@v2

- name: Cache Nuget
uses: actions/cache@v2
with:
path: |
!~/.nuget/packages/OpenSesame.*
~/.nuget/packages
key: ${{ runner.os }}-nuget-packages-${{ hashFiles('**/eng/Versions.props') }}

- name: Cache Node
uses: actions/cache@v2
with:
path: ~/.npm
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}

- run: npm ci && npx semantic-release
env:
NUGET_TOKEN: ${{ secrets.NUGET_TOKEN }}
GITHUB_TOKEN: ${{ github.token }}
25 changes: 25 additions & 0 deletions .github/workflows/package_test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
name: test

on:
push:
branches:
- develop

jobs:
build:
runs-on: ubuntu-latest

steps:

- uses: actions/checkout@v2

- name: Cache Nuget
uses: actions/cache@v2
with:
path: |
!~/.nuget/packages/OpenSesame.*
~/.nuget/packages
key: ${{ runner.os }}-nuget-packages-${{ hashFiles('**/eng/Versions.props') }}

- run: |
./tool.sh --pack --run-tests
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Update Roslyn
name: roslyn

on:
issues:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Update Roslyn (test)
name: roslyn-test

on:
issues:
Expand Down
18 changes: 0 additions & 18 deletions .github/workflows/update_roslyn.sh

This file was deleted.

1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ Desktop.ini
Tests/**/.vs/
Tests/**/obj/
Tests/**/bin/
.idea/
13 changes: 13 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# [3.4.0-beta.4](https://github.com/mob-sakai/OpenSesame/compare/v3.4.0-beta.3...v3.4.0-beta.4) (2020-08-12)


### Features

* disable all access checks (again) ([58909d5](https://github.com/mob-sakai/OpenSesame/commit/58909d5d3bbe0708418b5cd7d53d4f6ebbaacec8))

# [3.4.0-beta.3](https://github.com/mob-sakai/OpenSesame/compare/v3.4.0-beta.2...v3.4.0-beta.3) (2020-08-07)


### Features

* inject IgnoresAccessChecksToAttribute automatically ([288fa86](https://github.com/mob-sakai/OpenSesame/commit/288fa8608226757b75203534bc616a9f3e523939))
49 changes: 49 additions & 0 deletions LICENSE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
The MIT License (MIT)

Copyright 2020 mob-sakai

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

---
Here is the original copyright:


The MIT License (MIT)

Copyright (c) .NET Foundation and Contributors

All rights reserved.

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
130 changes: 90 additions & 40 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,81 +3,131 @@ Open Sesame

A custom [Roslyn](https://github.com/dotnet/roslyn) compiler **that allows access to internals/privates in other assemblies.**

![GitHub](https://img.shields.io/github/license/mob-sakai/OpenSesame)
![ci](https://github.com/mob-sakai/OpenSesame/workflows/Release/badge.svg)
![License](https://img.shields.io/github/license/mob-sakai/OpenSesame)

## Changes from original roslyn
![.NetFramework](https://img.shields.io/static/v1?label=.Net+Framework&message=4.7+or+later&color=blue)
![.NetCore](https://img.shields.io/static/v1?label=.Net+Core&message=2.0+or+later&color=red)
![.NetStandard](https://img.shields.io/static/v1?label=.Net+Standard&message=2.0+or+later&color=orange)

* Change the names of the packages
* Allow unsafe code automatically
* Add `MetadataImportOptions.All` to compilation options
* All public static methods in `AccessCheck.cs` will return `true`
![test](https://github.com/mob-sakai/OpenSesame/workflows/test/badge.svg)
![release](https://github.com/mob-sakai/OpenSesame/workflows/release/badge.svg)

## Description

This package contains a custom [Roslyn](https://github.com/dotnet/roslyn) compiler.
If the package is installed in a c# project, it will override the compiler used in the build.

The custom compiler automatically injects `IgnoresAccessChecksToAttribute` to the assembly.
This attribute ignores accessibility to the assembly with the given name.
In other words, **you can access to internals/privates in other assemblies, without [reflection feature][reflection].**

Have you ever heard of a secret attribute `IgnoresAccessChecksToAttribute`?
For more information, See [the great article by Filip W][ignores-access].

[reflection]: https://docs.microsoft.com/en-us/dotnet/csharp/programming-guide/concepts/reflection
[ignores-access]: https://www.strathweb.com/2018/10/no-internalvisibleto-no-problem-bypassing-c-visibility-rules-with-roslyn/

### Changes from original roslyn

* Change the names of the packages `Microsoft.*` to `OpenSesame.*`
* Allow unsafe code automatically (for .Net Framework)
* With `MetadataImportOptions.All` for compilation options
* With `BinderFlags.IgnoreAccessibility` for compilation options
* Inject `IgnoresAccessChecksToAttribute` automatically

### Supported frameworks

* .Net Framework 4.7 or later
* .Net Core 2.0 or later
* .Net Standard 2.0 or later
* Unity 2018.3 or later

<br><br><br><br>

## Packages

| PAckage Name | Original Package | Version | Downloads |
| Package Name | Original Package | Version | Downloads |
| ------------------------------------ | ----------------------------------- | ------- | --------- |
| [OpenSesame.Net.Compilers.Toolset][] | [Microsoft.Net.Compilers.Toolset][] | ![V1][] | ![D1][] |
| [OpenSesame.Net.Compilers][] | [Microsoft.Net.Compilers][] | ![V2][] | ![D2][] |
| [OpenSesame.NetCore.Compilers][] | [Microsoft.NetCore.Compilers][] | ![V3][] | ![D3][] |

[OpenSesame.Net.Compilers.Toolset]: https://www.nuget.org/packages/OpenSesame.Net.Compilers.Toolset
[Microsoft.Net.Compilers.Toolset]: https://www.nuget.org/packages/Microsoft.Net.Compilers.Toolset
[V1]: https://img.shields.io/nuget/v/Microsoft.Net.Compilers.Toolset
[D1]: https://img.shields.io/nuget/dt/Microsoft.Net.Compilers.Toolset
[V1]: https://img.shields.io/nuget/v/OpenSesame.Net.Compilers.Toolset
[D1]: https://img.shields.io/nuget/dt/OpenSesame.Net.Compilers.Toolset
[MV1]: https://img.shields.io/nuget/v/Microsoft.Net.Compilers.Toolset

[OpenSesame.Net.Compilers]: https://www.nuget.org/packages/OpenSesame.Net.Compilers
[Microsoft.Net.Compilers]: https://www.nuget.org/packages/Microsoft.Net.Compilers
[V2]: https://img.shields.io/nuget/v/Microsoft.Net.Compilers
[D2]: https://img.shields.io/nuget/dt/Microsoft.Net.Compilers
[V2]: https://img.shields.io/nuget/v/OpenSesame.Net.Compilers
[D2]: https://img.shields.io/nuget/dt/OpenSesame.Net.Compilers

[OpenSesame.NetCore.Compilers]: https://www.nuget.org/packages/OpenSesame.NetCore.Compilers
[Microsoft.NetCore.Compilers]: https://www.nuget.org/packages/Microsoft.NetCore.Compilers
[V3]: https://img.shields.io/nuget/v/Microsoft.NetCore.Compilers
[D3]: https://img.shields.io/nuget/dt/Microsoft.NetCore.Compilers
[V3]: https://img.shields.io/nuget/v/OpenSesame.NetCore.Compilers
[D3]: https://img.shields.io/nuget/dt/OpenSesame.NetCore.Compilers

<br><br><br><br>

## Usage

### For C# project (.Net Framework)

For a C# project (`*.csproj`), you can install the Toolset package to change the compiler to be used at build time.

#### ~~How to run (demo)~~
1. Install the nuget package [OpenSesame.Net.Compilers.Toolset][] to the project.
2. The accessibility of all symbols (types, methods, properties, etc.) will be ignored.

1. ~~Clone [demo project]()~~
```sh
git clone demo-proj
cd demo-proj
```
2. ~~The compilation will fail because this project contains internals/privates access.~~
```sh
# The following command will fail.
dotnet run
```
```sh
```
3. ~~Install `OpenSesameCompiler` package to project from nuget~~
```sh
dotnet add OpenSesameCompiler
```
4. ~~Add `<CscToolPath>$(PkgOpenSesameCompiler)tools/csc.exe</CscToolPath>` to `PropertyGroup` in `demo.csproj`.~~
~~Or, execute the following command.~~
```sh
dotnet run /p:CscToolPath=$(PkgOpenSesameCompiler)tools/csc.exe
### For C# project (.Net Core or .Net Standard)

For a C# project (`*.csproj`), you can install the Toolset package to change the compiler to be used at build time.

1. Install the nuget package [OpenSesame.Net.Compilers.Toolset][] to the project.
2. Adddd the following somewhere in your code:
```cs
[assembly: System.Runtime.CompilerServices.IgnoresAccessChecksTo("<TargetAssemblyName>")]
```
5. ~~Enjoy!~~
3. The accessibility of the symbols (types, methods, properties, etc.) contained in the `<TargetAssemblyName>` will be ignored.

### For Unity

Use a unity package [com.coffee.open-sesame-compiler](https://github.com/mob-sakai/OpenSesameCompilerForUnity).

<br><br><br><br>

## Develop

### Update Roslyn
### Update Roslyn version

| OpenSesame | Roslyn |
| ---------- | -------- |
| ![V1][] | ![MV1][] |

If a new stable version of the Rosly package has been released, please update Roslyn.

[Create an issue using the Roslyn update request issue template][issue_template]

[issue_template]: https://github.com/mob-sakai/OpenSesame/issues/new?assignees=mob-sakai&template=update_roslyn.md&title=Request+to+update+roslyn%3A+%7Bversion%7D

### Test
### Run Tests

```
roslyn/build.sh --pack -r -c Release
dotnet test tests
./tool.sh --pack --run-tests
```

### Release

When push to `beta` or `master` branch, this package is automatically released by GitHub Action.

* Update version of the package
* Update and push CHANGELOG.md
* Create version tag
* Release on GitHub
* Publish to nuget registory

Alternatively, release it manually with the following command:

```bash
$ node run release -- --no-ci
```
16 changes: 16 additions & 0 deletions Tests/PrivateLibrary.Console/PrivateLibrary.Console.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>netstandard2.0;netstandard2.1;netcoreapp2.1;netcoreapp3.0;netcoreapp3.1;net47;net471;net472;net48</TargetFrameworks>
<OutputType>Exe</OutputType>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\PrivateLibrary\PrivateLibrary.csproj" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="OpenSesame.Net.Compilers.Toolset" Version="3.4.0">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
</ItemGroup>
</Project>
13 changes: 13 additions & 0 deletions Tests/PrivateLibrary.Console/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using System;

[assembly: System.Runtime.CompilerServices.IgnoresAccessChecksToAttribute("PrivateLibrary")]
namespace PrivateLibrary.Console
{
class Program
{
static void Main(string[] args)
{
System.Console.WriteLine(new InternalClass().privateStringField);
}
}
}
16 changes: 0 additions & 16 deletions Tests/PrivateLibrary.Tests/IgnoresAccessChecksToAttribute.cs

This file was deleted.

0 comments on commit 52fa070

Please sign in to comment.