-
Notifications
You must be signed in to change notification settings - Fork 1.1k
/
Copy pathGenerateBlazorBootExtensionJson.cs
53 lines (45 loc) · 1.49 KB
/
GenerateBlazorBootExtensionJson.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
// Copyright (c) .NET Foundation and contributors. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
//
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.Serialization.Json;
using System.Text;
using Microsoft.Build.Framework;
using Microsoft.Build.Utilities;
namespace Microsoft.NET.Sdk.BlazorWebAssembly
{
public class GenerateBlazorBootExtensionJson : Task
{
[Required]
public string OutputPath { get; set; }
public override bool Execute()
{
using var fileStream = File.Create(OutputPath);
try
{
WriteJson(fileStream);
}
catch (Exception ex)
{
Log.LogError(ex.ToString());
}
return !Log.HasLoggedErrors;
}
// Internal for tests
public void WriteJson(Stream output)
{
var result = new BootExtensionJsonData();
var serializer = new DataContractJsonSerializer(typeof(BootExtensionJsonData), new DataContractJsonSerializerSettings
{
UseSimpleDictionaryFormat = true
});
using var writer = JsonReaderWriterFactory.CreateJsonWriter(output, Encoding.UTF8, ownsStream: false, indent: true);
serializer.WriteObject(writer, result);
}
}
}