DartLang.PubSpec.Serialization.Yaml
3.0.0
See the version list below for details.
dotnet add package DartLang.PubSpec.Serialization.Yaml --version 3.0.0
NuGet\Install-Package DartLang.PubSpec.Serialization.Yaml -Version 3.0.0
<PackageReference Include="DartLang.PubSpec.Serialization.Yaml" Version="3.0.0" />
paket add DartLang.PubSpec.Serialization.Yaml --version 3.0.0
#r "nuget: DartLang.PubSpec.Serialization.Yaml, 3.0.0"
// Install DartLang.PubSpec.Serialization.Yaml as a Cake Addin #addin nuget:?package=DartLang.PubSpec.Serialization.Yaml&version=3.0.0 // Install DartLang.PubSpec.Serialization.Yaml as a Cake Tool #tool nuget:?package=DartLang.PubSpec.Serialization.Yaml&version=3.0.0
DartLang.PubSpec
A library to serialize and deserialize Dart pubspec.yaml files.
Usage
var yaml = File.ReadAllText("pubspec.yaml");
var pubspec = PubSpecYamlSerializer.Deserialize(yaml);
Console.WriteLine($"Name: {pubspec.Name}");
Console.WriteLine($"Version: {pubspec.Version}");
You can also use the JSON serializer:
var json = File.ReadAllText("pubspec.json");
var pubspec = PubSpecJsonSerializer.Deserialize(json);
Custom Deserializer
YAML
You can also build your own deserializer using YamlDotNet
directly:
var deserializer = new DeserializerBuilder()
.IgnoreUnmatchedProperties() // pub.dev will ignore other properties
.WithNamingConvention(UnderscoredNamingConvention.Instance) // dart uses underscores for properties
.WithPubSpecConverters() // converters for custom types
.Build();
return deserializer.Deserialize<PubSpec>(reader);
JSON
In case you need to use custom JsonSerializerOptions
, you can reuse the converters from DartLang.PubSpec.Serialization.Json
:
var json = File.ReadAllText("pubspec.json");
var options = new JsonSerializerOptions
{
PropertyNameCaseInsensitive = true,
PropertyNamingPolicy = JsonNamingPolicy.CamelCase,
Converters =
{
new SemVersionJsonConverter(),
new SemVersionRangeJsonConverter(),
new DependencyMapJsonConverter(),
new PlatformsJsonConverter(),
},
};
return JsonSerializer.Deserialize<PubSpec>(json, options);
Serialization
Serialization is currently not supported, but should not be hard to implement yourself.
License
MIT
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. |
-
net8.0
- DartLang.PubSpec (>= 3.0.0)
- YamlDotNet (>= 16.1.3)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
# 3.0.0
* Breaking: Renamed `PubSpecJsonSerializer` to `PubSpecJsonConverter`
* Breaking: Renamed `PubSpecYamlSerializer` to `PubSpecYamlConverter`
* Added more and also async overloads for de-/serialization in `PubSpecJsonConverter` and `PubSpecYamlConverter`
# 2.0.0
* Split de-/serialization for YAML into a separate package: `DartLang.PubSpec.Serialization.Yaml`
* Added support for de-/serializing JSON files using `DartLang.PubSpec.Serialization.Json`
# 1.1.0
* Upgraded to YamlDotNet 16.1.3
# 1.0.0
* Initial release 🎉
* Support for deserializing pubspec.yaml files using `PubSpec.Deserialize(String yaml)` and `PubSpec.Deserialize(StringReader reader)`.
* You can also build your own deserializer using:
```csharp
var deserializer = new DeserializerBuilder()
.IgnoreUnmatchedProperties() // pub.dev will ignore other properties
.WithNamingConvention(UnderscoredNamingConvention.Instance) // convention
.WithPubSpecConverters() // converters for custom types
.Build();
return deserializer.Deserialize<PubSpec>(reader);
```