Skip to content

Commit 753100b

Browse files
committed
Added script to format dotnet code, updated editorconfig for the same
1 parent 89ab4cd commit 753100b

4 files changed

Lines changed: 67 additions & 30 deletions

File tree

.editorconfig

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,19 @@ root = true
88
indent_style = space
99
indent_size = 4
1010
trim_trailing_whitespace = true
11-
insert_final_newline = false
11+
insert_final_newline = true
1212

1313
# SA1200: Using directives should be placed correctly
1414
dotnet_diagnostic.SA1200.severity = none
1515

16+
[*.cake]
17+
indent_style = space
18+
indent_size = 4
19+
trim_trailing_whitespace = true
20+
insert_final_newline = true
21+
1622
[*.{xaml,xml,config,manifest}]
1723
indent_style = space
1824
indent_size = 2
1925
trim_trailing_whitespace = true
20-
insert_final_newline = false
26+
insert_final_newline = false

cake-build/tasks/build.cake

Lines changed: 57 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@ Task("_Clean")
66
.Does(() =>
77
{
88
Information("Cleaning build directories...");
9-
9+
1010
// Clean the main solution which includes all core projects (NetFramework, NetStandard, iOS, Android, Tests, etc.)
1111
CleanSolution();
12-
12+
1313
// Clean custom output directories that are not part of standard project outputs
14-
CleanDirectory(paths.TestResults);
14+
CleanDirectory(paths.TestResults);
1515
});
1616

1717
Task("_Restore_Main")
@@ -25,9 +25,9 @@ Task("_Version")
2525
.Does(() =>
2626
{
2727
Information($"Setting version to {version}");
28-
28+
2929
var assemblyInfoPath = paths.Src.CombineWithFilePath("CommonAssemblyInfo.cs");
30-
30+
3131
CreateAssemblyInfo(assemblyInfoPath, new AssemblyInfoSettings
3232
{
3333
Company = "Ably",
@@ -43,37 +43,37 @@ Task("_NetFramework_Build")
4343
.Does(() =>
4444
{
4545
Information("Building .NET Framework solution...");
46-
46+
4747
var settings = buildConfig.ApplyStandardSettings(
4848
new MSBuildSettings(),
4949
configuration
5050
);
51-
51+
5252
settings = settings.WithTarget("Build");
53-
53+
5454
MSBuild(paths.NetFrameworkSolution, settings);
5555
});
5656

5757
Task("_NetStandard_Build")
5858
.Does(() =>
5959
{
6060
Information("Building .NET Standard solution...");
61-
61+
6262
var settings = new DotNetBuildSettings
6363
{
6464
Configuration = configuration,
6565
NoRestore = true
6666
};
6767
var msbuildSettings = new DotNetMSBuildSettings();
68-
69-
68+
69+
7070
if (!string.IsNullOrEmpty(defineConstants))
7171
{
7272
msbuildSettings = msbuildSettings.WithProperty("DefineConstants", defineConstants);
7373
}
74-
74+
7575
settings.MSBuildSettings = msbuildSettings;
76-
76+
7777
DotNetBuild(paths.NetStandardSolution.FullPath, settings);
7878
});
7979

@@ -87,20 +87,20 @@ Task("_Xamarin_Build")
8787
.Does(() =>
8888
{
8989
Information("Building Xamarin solution...");
90-
90+
9191
if (!FileExists(paths.XamarinSolution))
9292
{
9393
Warning("Xamarin solution not found, skipping build");
9494
return;
9595
}
96-
96+
9797
var settings = buildConfig.ApplyStandardSettings(
9898
new MSBuildSettings(),
9999
configuration
100100
);
101-
101+
102102
settings = settings.WithTarget("Build");
103-
103+
104104
MSBuild(paths.XamarinSolution, settings);
105105
});
106106

@@ -109,32 +109,32 @@ Task("_Build_Ably_Unity_Dll")
109109
.Does(() =>
110110
{
111111
Information("Merging Unity dependencies into IO.Ably.dll...");
112-
112+
113113
var netStandard20BinPath = paths.Src
114114
.Combine("IO.Ably.NETStandard20")
115115
.Combine("bin/Release/netstandard2.0");
116-
116+
117117
if (!DirectoryExists(netStandard20BinPath))
118118
{
119119
throw new Exception($"NETStandard2.0 bin directory not found: {netStandard20BinPath}. Please build the project first.");
120120
}
121-
121+
122122
var primaryDll = netStandard20BinPath.CombineWithFilePath("IO.Ably.dll");
123-
123+
124124
if (!FileExists(primaryDll))
125125
{
126126
throw new Exception($"Primary DLL not found: {primaryDll}. Please build the IO.Ably.NETStandard20 project first.");
127127
}
128-
128+
129129
var newtonsoftDll = paths.Root
130130
.Combine("lib/unity/AOT")
131131
.CombineWithFilePath("Newtonsoft.Json.dll");
132-
132+
133133
if (!FileExists(newtonsoftDll))
134134
{
135135
throw new Exception($"Newtonsoft.Json.dll not found at: {newtonsoftDll}");
136136
}
137-
137+
138138
var dllsToMerge = new[]
139139
{
140140
netStandard20BinPath.CombineWithFilePath("IO.Ably.DeltaCodec.dll"),
@@ -143,23 +143,47 @@ Task("_Build_Ably_Unity_Dll")
143143
netStandard20BinPath.CombineWithFilePath("System.Threading.Tasks.Extensions.dll"),
144144
newtonsoftDll
145145
};
146-
146+
147147
var unityOutputPath = paths.Root.Combine("unity/Assets/Ably/Plugins");
148148
var outputDll = unityOutputPath.CombineWithFilePath("IO.Ably.dll");
149-
149+
150150
// Delete existing output DLL if it exists
151151
if (FileExists(outputDll))
152152
{
153153
DeleteFile(outputDll);
154154
Information($"Deleted existing DLL: {outputDll}");
155155
}
156-
156+
157157
// Merge all dependencies into primary DLL in one go
158158
ilRepackHelper.MergeDLLs(primaryDll, dllsToMerge, outputDll);
159-
159+
160160
Information($"✓ Unity DLL created at: {outputDll}");
161161
});
162162

163+
Task("_Format_Code")
164+
.Description("Format C#, XML and other files")
165+
.Does(() =>
166+
{
167+
Information("Formatting code with dotnet-format...");
168+
169+
// Using 'whitespace' mode for fast formatting without building the project
170+
// This applies .editorconfig rules for whitespace, indentation, etc. without semantic analysis
171+
// Much faster than default mode which requires compilation
172+
var exitCode = StartProcess("dotnet", new ProcessSettings
173+
{
174+
Arguments = $"format {paths.MainSolution.FullPath} whitespace --no-restore"
175+
});
176+
177+
if (exitCode == 0)
178+
{
179+
Information("✓ Code formatted successfully");
180+
}
181+
else
182+
{
183+
throw new Exception($"dotnet format failed with exit code {exitCode}");
184+
}
185+
});
186+
163187
///////////////////////////////////////////////////////////////////////////////
164188
// PUBLIC TARGETS
165189
///////////////////////////////////////////////////////////////////////////////
@@ -190,3 +214,8 @@ Task("Build.Xamarin")
190214
Task("Update.AblyUnity")
191215
.Description("Update Ably DLLs inside unity project")
192216
.IsDependentOn("_Build_Ably_Unity_Dll");
217+
218+
// Public task: Format code using dotnet-format
219+
Task("Format.Code")
220+
.Description("Format code using dotnet-format")
221+
.IsDependentOn("_Format_Code");

format-code.cmd

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
dotnet cake cake-build/build.cake -- --target=Format.Code

format-code.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
format-code.sh

0 commit comments

Comments
 (0)