-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnotes.txt
375 lines (322 loc) · 13.4 KB
/
notes.txt
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
using Microsoft.Build.Framework;
using Microsoft.Build.Utilities;
namespace MSBuildLibrary
{
//https://github.com/dotnet/samples/blob/main/msbuild/custom-task-code-generation/MSBuildConsoleExample/MSBuildConsoleExample.sln
public class AppSettingStronglyTyped : Microsoft.Build.Utilities.Task
{
//The name of the class which is going to be generated
[Required]
public string SettingClassName { get; set; }
//The name of the namespace where the class is going to be generated
[Required]
public string SettingNamespaceName { get; set; }
//List of files which we need to read with the defined format: 'propertyName:type:defaultValue' per line
[Required]
public ITaskItem[] SettingFiles { get; set; }
// The filename where the class was generated
[Output]
public string ClassNameFile { get; set; }
public override bool Execute()
{
//Read the input files and return a IDictionary<string, object> with the properties to be created.
//Any format error it will return false and log an error
var (success, settings) = ReadProjectSettingFiles();
if (!success)
{
return !Log.HasLoggedErrors;
}
//Create the class based on the Dictionary
success = CreateSettingClass(settings);
return !Log.HasLoggedErrors;
}
private (bool, IDictionary<string, object>) ReadProjectSettingFiles()
{
var values = new Dictionary<string, object>();
foreach (var item in SettingFiles)
{
int lineNumber = 0;
var settingFile = item.GetMetadata("FullPath");
foreach (string line in File.ReadLines(settingFile))
{
lineNumber++;
var lineParse = line.Split(':');
if (lineParse.Length != 3)
{
Log.LogError(subcategory: null,
errorCode: "APPS0001",
helpKeyword: null,
file: settingFile,
lineNumber: lineNumber,
columnNumber: 0,
endLineNumber: 0,
endColumnNumber: 0,
message: "Incorrect line format. Valid format prop:type:defaultvalue");
return (false, null);
}
var value = GetValue(lineParse[1], lineParse[2]);
if (!value.Item1)
{
return (value.Item1, null);
}
values[lineParse[0]] = value.Item2;
}
}
return (true, values);
}
private (bool, object) GetValue(string type, string value)
{
try
{
// So far only few types are supported values.
if ("string".Equals(type))
{
return (true, value);
}
if ("int".Equals(type))
{
return (true, int.Parse(value));
}
if ("long".Equals(type))
{
return (true, long.Parse(value));
}
if ("guid".Equals(type))
{
return (true, Guid.Parse(value));
}
if ("bool".Equals(type))
{
return (true, bool.Parse(value));
}
Log.LogError($"Type not supported -> {type}");
return (false, null);
}
catch
{
Log.LogError($"It is not possible parse some value based on the type -> {type} - {value}");
return (false, null);
}
}
private bool CreateSettingClass(IDictionary<string, object> settings)
{
try
{
ClassNameFile = $"{SettingClassName}.generated.cs";
File.Delete(ClassNameFile);
StringBuilder settingsClass = new StringBuilder(1024);
// open namespace
settingsClass.Append($@" using System;
namespace {SettingNamespaceName} {{
public class {SettingClassName} {{
");
//For each element in the dictionary create a static property
foreach (var keyValuePair in settings)
{
string typeName = GetTypeString(keyValuePair.Value.GetType().Name);
settingsClass.Append($" public readonly static {typeName} {keyValuePair.Key} = {GetValueString(keyValuePair, typeName)};\r\n");
}
// close namespace and class
settingsClass.Append(@" }
}");
File.WriteAllText(ClassNameFile, settingsClass.ToString());
}
catch (Exception ex)
{
//This logging helper method is designed to capture and display information from arbitrary exceptions in a standard way.
Log.LogErrorFromException(ex, showStackTrace: true);
return false;
}
return true;
}
private string GetTypeString(string typeName)
{
if ("String".Equals(typeName))
{
return "string";
}
if ("Boolean".Equals(typeName))
{
return "bool";
}
if ("Int32".Equals(typeName))
{
return "int";
}
if ("Int64".Equals(typeName))
{
return "long";
}
return typeName;
}
private static object GetValueString(KeyValuePair<string, object> keyValuePair, string typeName)
{
if ("Guid".Equals(typeName))
{
return $"Guid.Parse(\"{keyValuePair.Value}\")";
}
if ("string".Equals(typeName))
{
return $"\"{keyValuePair.Value}\"";
}
if ("bool".Equals(typeName))
{
return $"{keyValuePair.Value.ToString().ToLower()}";
}
return keyValuePair.Value;
}
}
}
/*
<UsingTask TaskName="FooTask" AssemblyFile="$(MSBuildThisFileDirectory)$(OutputPath)MSBuildLibrary35.dll"/>
<Target Name="FooTaskTarget" AfterTargets="Build">
<FooTask Parameter1="abc">
<Output TaskParameter="Result1" PropertyName="SettingClassFileName" />
</FooTask>
<Message Text="Hello foo $(SettingClassFileName)" Importance="high" />
</Target>
*/
//https://learn.microsoft.com/en-us/visualstudio/msbuild/task-writing?view=vs-2022
/*
public class MyTask : Microsoft.Build.Utilities.Task
{
// The filename where the class was generated
[Output]
public string Result1 { get; set; }
public override bool Execute()
{
string currentProjectPath = this.BuildEngine.ProjectFileOfTaskNode;
var projectCollection = new ProjectCollection();
var project = new Project(currentProjectPath, null, null, projectCollection);
// Log some project properties
Log.LogMessage(MessageImportance.High, $"Project File: {currentProjectPath}");
Log.LogMessage(MessageImportance.High, $"Target Framework: {project.GetPropertyValue("TargetFramework")}");
Log.LogMessage(MessageImportance.High, $"Output Path: {project.GetPropertyValue("OutputPath")}");
project.SetProperty("foox", "fooxvalue");
project.SetGlobalProperty("far", "far");
this.Result1 = project.GetPropertyValue("TargetFramework");
return true;
}
}
public class CollectPropertiesTask : Microsoft.Build.Utilities.Task
{
[Output]
public ITaskItem[] AllProperties { get; set; }
public override bool Execute()
{
var properties = new List<ITaskItem>();
Project project = new Project(BuildEngine.ProjectFileOfTaskNode);
foreach (var item in project.GlobalProperties)
{
//Log.LogMessage(MessageImportance.High, $@"sssssssss {item.Key}");
}
if (project != null)
{
foreach (var prop in project.AllEvaluatedProperties)
{
var taskItem = new TaskItem(prop.Name);
taskItem.SetMetadata("Value", prop.EvaluatedValue);
properties.Add(taskItem);
}
}
project.Save(@"C:\temp\cc.csproj");
AllProperties = properties.ToArray();
return true;
}
}
<!--
<ItemGroup>
<PackageReference Include="Microsoft.Build" Version="15.9.20" />
<PackageReference Include="Microsoft.Build.Utilities.Core" Version="15.9.20" />
</ItemGroup>
<Target Name = "out" AfterTargets="Build">
<Message Text = "out: $(MSBuildThisFileDirectory)MSBuildLibrary35.dll" Importance="high" />
</Target>
<UsingTask TaskName = "FooTask" AssemblyFile="$(MSBuildThisFileDirectory)$(OutputPath)MSBuildLibrary35.dll"/>
<UsingTask TaskName = "SimpleTask" AssemblyFile="$(MSBuildThisFileDirectory)$(OutputPath)MSBuildLibrary35.dll"/>
<UsingTask TaskName = "MyTask" AssemblyFile="$(MSBuildThisFileDirectory)$(OutputPath)MSBuildLibrary35.dll"/>
<UsingTask TaskName = "CollectPropertiesTask" AssemblyFile="$(MSBuildThisFileDirectory)$(OutputPath)MSBuildLibrary35.dll"/>
<Target Name = "FooTaskTarget" AfterTargets="Build">
<FooTask Parameter1 = "abc">
<Output TaskParameter="Result1" PropertyName="SettingClassFileName" />
</FooTask>
<Message Text = "Hello foo $(SettingClassFileName)" Importance="high" />
</Target>
<Target Name = "UseSimpleTask" AfterTargets="Build">
<SimpleTask/>
</Target>
<Target Name = "UseMyTask" AfterTargets="Build">
<MyTask><Output TaskParameter = "Result1" PropertyName="SetMe" /></MyTask>
<Message Text = "SetMe: $(SetMe)" Importance="high" />
</Target>
<Target Name = "UseCollectPropertiesTask" AfterTargets="Build">
<CollectPropertiesTask>
<Output TaskParameter = "AllProperties" ItemName="CapturedProperties" />
</CollectPropertiesTask>
<Message Text = "%(CapturedProperties.Identity) = %(CapturedProperties.Value)" Importance="high"/>
</Target>
<Target Name = "CustomAfterBuildTarget" AfterTargets="Build">
<Message Text = "Hello from CustomAfterBuildTarget" Importance="high" />
<Message Text = "MSBuildThisFile: $(MSBuildThisFile)" Importance="high" />
<Message Text = "MSBuildThisFileDirectory: $(MSBuildThisFileDirectory)" Importance="high" />
<Message Text = "MSBuildThisFileDirectoryNoRoot: $(MSBuildThisFileDirectoryNoRoot)" Importance="high" />
<Message Text = "MSBuildThisFileExtension: $(MSBuildThisFileExtension)" Importance="high" />
<Message Text = "MSBuildThisFileFullPath: $(MSBuildThisFileFullPath)" Importance="high" />
<Message Text = "MSBuildThisFileName: $(MSBuildThisFileName)" Importance="high" />
<Message Text = "BinFolder: $(BinFolder)" Importance="high" />
<Message Text = "DestinationFolder: $(DestinationFolder)" Importance="high" />
<Message Text = "OutDir: $(OutDir)" Importance="high" />
<Message Text = "OutputPath: $(OutputPath)" Importance="high" />
<Message Text = "BaseOutputPath: $(BaseOutputPath)" Importance="high" />
<Message Text = "PublishDir: $(PublishDir)" Importance="high" />
</Target>
-->
*/
<Target Name = "debugout" AfterTargets="Build">
<Message Text = "Hello from CustomAfterBuildTarget" Importance="high" />
<Message Text = "MSBuildThisFile: $(MSBuildThisFile)" Importance="high" />
<Message Text = "MSBuildThisFileDirectory: $(MSBuildThisFileDirectory)" Importance="high" />
<Message Text = "MSBuildThisFileDirectoryNoRoot: $(MSBuildThisFileDirectoryNoRoot)" Importance="high" />
<Message Text = "MSBuildThisFileExtension: $(MSBuildThisFileExtension)" Importance="high" />
<Message Text = "MSBuildThisFileFullPath: $(MSBuildThisFileFullPath)" Importance="high" />
<Message Text = "MSBuildThisFileName: $(MSBuildThisFileName)" Importance="high" />
<Message Text = "BinFolder: $(BinFolder)" Importance="high" />
<Message Text = "DestinationFolder: $(DestinationFolder)" Importance="high" />
<Message Text = "OutDir: $(OutDir)" Importance="high" />
<Message Text = "OutputPath: $(OutputPath)" Importance="high" />
<Message Text = "BaseOutputPath: $(BaseOutputPath)" Importance="high" />
<Message Text = "PublishDir: $(PublishDir)" Importance="high" />
</Target>
Benchmark.NET
Terminal.GUI
WPFUI
LINQKit
MediatR
Polly
NodaTime
HangFire
Serilog
NLOG
Refit
Apizr
FluentValidation
log4net
FluentAssertions
NSubstitute
Dapper
Flurl
ManyConsole
Humanizer.Core
AutoMapper
Quartz.NET
NAudio
CsvHelper
Spectre.Console
coverlet.collector
in src:
dotnet pack -c Debug
dotnet new install Projects\Coree.Template.Project\bin\Package\Coree.Template.Project.0.2.8934.6807-local.nupkg