FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Switch from MSBuild properties to an AdditionalFiles json file by AArnott · Pull Request #1667 · MessagePack-CSharp/MessagePack-CSharp · GitHub

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .cs  (9) .csproj  (4) .json  (4) .md  (1) .props  (2) .sln  (1) .targets  (3) All 7 file types selected
Only manifest files
Deleted files Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
3 changes: 2 additions & 1 deletion MessagePack.sln
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "docs", "docs", "{344DC89D-8
ProjectSection(SolutionItems) = preProject
.gitignore = .gitignore
LICENSE = LICENSE
doc\MessagePackAnalyzer.json = doc\MessagePackAnalyzer.json
README.md = README.md
EndProjectSection
EndProject
Expand Down Expand Up @@ -103,7 +104,7 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MessagePack.SourceGenerator
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MessagePack.SourceGenerator.Unity.Tests", "tests\MessagePack.SourceGenerator.Unity.Tests\MessagePack.SourceGenerator.Unity.Tests.csproj", "{EAC1B79C-F77D-4DEF-BF53-75E700A301A4}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MessagePack.Analyzers.CodeFixes", "src\MessagePack.Analyzers.CodeFixes\MessagePack.Analyzers.CodeFixes.csproj", "{7A6CB600-2393-468F-9952-84EC624D57BD}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MessagePack.Analyzers.CodeFixes", "src\MessagePack.Analyzers.CodeFixes\MessagePack.Analyzers.CodeFixes.csproj", "{7A6CB600-2393-468F-9952-84EC624D57BD}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand Down
61 changes: 61 additions & 0 deletions MessagePackAnalyzer.schema.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
{
"$schema": "http://json-schema.org/draft-04/schema",
"title": "MessagePackAnalyzer.json schema",
"type": "object",
"additionalProperties": false,
"properties": {
"generator": {
"type": "object",
"description": "Customizes AOT source generation of formatters for custom types.",
"additionalProperties": false,
"properties": {
"usesMapMode": {
"type": "boolean",
"description": "A value indicating whether types will be serialized with their property names as well as their values in a key=value dictionary, as opposed to an array of values.",
"default": false
},
"resolver": {
"type": "object",
"description": "Describes the generated resolver.",
"additionalProperties": false,
"properties": {
"public": {
"type": "boolean",
"description": "A value indicating whether the generated resolver should be public (as opposed to internal). A public resolver is appropriate when developing a library that may be used by another assembly that needs to aggregate this generated resolver with others.",
"default": false
},
"name": {
"type": "string",
"description": "The name to use for the resolver.",
"default": "GeneratedMessagePackResolver"
},
"namespace": {
"type": "string",
"description": "The namespace the source generated resolver will be emitted into.",
"default": "MessagePack"
}
}
},
"formatters": {
"type": "object",
"description": "Customizes aspects of source generated formatters.",
"additionalProperties": false,
"properties": {
"namespace": {
"type": "string",
"description": "The root namespace into which formatters are emitted.",
"default": "Formatters"
}
}
}
}
},
"customFormattedTypes": {
"type": "array",
"description": "An array of fully-qualified names of types that are included in serialized object graphs but are assumed to have custom formatters registered already.",
"items": {
"type": "string"
}
}
}
}
56 changes: 36 additions & 20 deletions README.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -168,14 +168,19 @@ The MessagePackAnalyzer package aids with:

![analyzergif](https://cloud.githubusercontent.com/assets/46207/23837445/ce734eae-07cb-11e7-9758-d69f0f095bc1.gif)

If you want to allow a specific custom type (for example, when registering a custom type), put `MessagePackAnalyzer.json` at the project root and change the Build Action to `AdditionalFiles`.

![image](https://cloud.githubusercontent.com/assets/46207/23837427/8a8d507c-07cb-11e7-9277-5a566eb0bfde.png)
If you want to allow a specific custom type (for example, when registering a custom type), put `MessagePackAnalyzer.json` at the project root.
If using Unity, you should configure Unity to treat this as an `AdditionalFiles` in the C# compiler.

An example `MessagePackAnalyzer.json`:

```json
[ "MyNamespace.FooClass", "MyNameSpace.BarStruct" ]
{
"$schema": "https://raw.githubusercontent.com/MessagePack-CSharp/MessagePack-CSharp/develop/MessagePackAnalyzer.schema.json",
"customFormattedTypes": [
"MyNamespace.MyClass",
"MyNamespace.AnotherClass"
]
}
```

## Built-in supported types
Expand Down Expand Up @@ -1626,26 +1631,35 @@ T after = MessagePackSerializer.Deserialize<T>(serialized);

### Customizations

A few MSBuild properties can be set in your project to customize source generation:
You can customize the generated source through a `MessagePackAnalyzer.json` file added to the project root directory.
If using Unity, you should configure Unity to treat this as an `AdditionalFiles` in the C# compiler.

Property | Purpose | Default value
--|--|--
`PublicMessagePackGeneratedResolver` | A boolean value indicating whether the generated resolver should be `public`. This is useful for shared libraries so their consumers can leverage the AOT formatters (which are always `internal`) in the library. | `false`
`MessagePackGeneratedResolverNamespace` | The namespace to use for the generated resolver class. | The `$(RootNamespace)` of the project, or `MessagePack` if the root namespace is empty.
`MessagePackGeneratedResolverName` | The name of the generated resolver type. | `GeneratedMessagePackResolver`
`MessagePackGeneratedUsesMapMode` | A boolean value that indicates whether all formatters should use property maps instead of more compact arrays. | `false`

For example you could add this xml to your project file to set each of the above properties (in this example, to their default values):
An example `MessagePackAnalyzer.json`:

```xml
<PropertyGroup>
<PublicMessagePackGeneratedResolver>false</PublicMessagePackGeneratedResolver>
<MessagePackGeneratedResolverNamespace>$(RootNamespace)</MessagePackGeneratedResolverNamespace>
<MessagePackGeneratedResolverName>GeneratedMessagePackResolver</MessagePackGeneratedResolverName>
<MessagePackGeneratedUsesMapMode>false</MessagePackGeneratedUsesMapMode>
</PropertyGroup>
```json
{
"$schema": "https://raw.githubusercontent.com/MessagePack-CSharp/MessagePack-CSharp/develop/MessagePackAnalyzer.schema.json",
"generator": {
"resolver": {
"public": false,
"name": "GeneratedMessagePackResolver",
"namespace": "<your project root namespace>"
},
"formatters": {
"namespace": "Formatters"
},
"usesMapMode": false
},
"customFormattedTypes": [
"MyNamespace.MyClass",
"MyNamespace.AnotherClass"
]
}
```

The above example mostly sets defaults.
You can discover all the available settings, their defaults and meanings in a JSON editor that supports JSON schema, or by reviewing [the JSON schema][AnalyzerJsonSchema] yourself.

When exposing the generated resolver publicly, consumers outside the library should aggregate the resolver using its `Instance` property, which contains *only* the generated formatters.
The `InstanceWithStandardAotResolver` property is a convenience for callers that will not be aggregating the resolver with those from other libraries, since it aggregates built-in AOT friendly resolvers from the MessagePack library itself.

Expand Down Expand Up @@ -1702,3 +1716,5 @@ The StreamJsonRpc library is based on [JSON-RPC](https://www.jsonrpc.org/) and i
## How to build

See our [contributor's guide](CONTRIBUTING.md).

[AnalyzerJsonSchema]: https://github.com/MessagePack-CSharp/MessagePack-CSharp/blob/develop/MessagePackAnalyzer.schema.json
18 changes: 18 additions & 0 deletions doc/MessagePackAnalyzer.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"$schema": "../MessagePackAnalyzer.schema.json",
"generator": {
"resolver": {
"public": false,
"name": "GeneratedMessagePackResolver",
"namespace": "MessagePack"
},
"formatters": {
"namespace": "Formatters"
},
"usesMapMode": false
},
"customFormattedTypes": [
"MyNamespace.MyClass",
"MyNamespace.AnotherClass"
]
}
8 changes: 8 additions & 0 deletions sandbox/Sandbox/MessagePackAnalyzer.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"$schema": "../../MessagePackAnalyzer.schema.json",
"generator": {
"resolver": {
"public": true
}
}
}
1 change: 0 additions & 1 deletion sandbox/Sandbox/Sandbox.csproj
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
<OutputType>Exe</OutputType>
<TargetFramework>net6.0</TargetFramework>
<AllowUnsafeBlocks>True</AllowUnsafeBlocks>
<PublicMessagePackGeneratedResolver>true</PublicMessagePackGeneratedResolver>
</PropertyGroup>

<ItemGroup>
Expand Down
8 changes: 8 additions & 0 deletions sandbox/SharedData/MessagePackAnalyzer.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"$schema": "../../MessagePackAnalyzer.schema.json",
"generator": {
"resolver": {
"public": true
}
}
}
1 change: 0 additions & 1 deletion sandbox/SharedData/SharedData.csproj
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<PublicMessagePackGeneratedResolver>true</PublicMessagePackGeneratedResolver>
</PropertyGroup>

<ItemGroup>
Expand Down
Loading

Back | FazBrowse Home | New Git URL