Skip to content

Commit 78aa113

Browse files
authored
Improve update of .NET nanoFramework (#1022)
1 parent f33c63d commit 78aa113

File tree

3 files changed

+70
-8
lines changed

3 files changed

+70
-8
lines changed

CodeGen/Generators/NanoFrameworkGenerator.cs

Lines changed: 62 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -119,25 +119,77 @@ public static void Generate(string rootDir, Quantity[] quantities)
119119
/// </summary>
120120
/// <param name="rootDir">The root directory</param>
121121
/// <param name="quantities">The quantities to update nuspecs</param>
122-
public static void UpdateNanoFrameworkDependencies(
122+
public static bool UpdateNanoFrameworkDependencies(
123123
string rootDir,
124124
Quantity[] quantities)
125125
{
126126
// working path
127127
string path = Path.Combine(rootDir, "UnitsNet.NanoFramework\\GeneratedCode");
128128

129129
Log.Information("");
130-
Log.Information("Updating .NET nanoFramework references using nuget CLI");
130+
Log.Information("Restoring .NET nanoFramework projects");
131131

132132
// run nuget CLI
133133
var nugetCLI = new Process
134+
{
135+
StartInfo = new ProcessStartInfo
136+
{
137+
FileName = Path.Combine(rootDir, "Tools/nuget.exe"),
138+
Arguments = $"restore {path}\\UnitsNet.nanoFramework.sln",
139+
UseShellExecute = false,
140+
CreateNoWindow = true,
141+
RedirectStandardError = true
142+
}
143+
};
144+
145+
// start nuget CLI and wait for exit
146+
if (!nugetCLI.Start())
147+
{
148+
Log.Information("");
149+
Log.Information("Failed to start nuget CLI to restore .NET nanoFramework projects");
150+
Log.Information("");
151+
}
152+
else
153+
{
154+
// wait for exit, within 2 minutes
155+
if (!nugetCLI.WaitForExit((int)TimeSpan.FromMinutes(2).TotalMilliseconds))
156+
{
157+
Log.Information("");
158+
Log.Information("Failed to complete execution of nuget CLI to restore .NET nanoFramework projects");
159+
Log.Information("");
160+
}
161+
else
162+
{
163+
if (nugetCLI.ExitCode == 0)
164+
{
165+
Log.Information("Done!");
166+
Log.Information("");
167+
}
168+
else
169+
{
170+
Log.Information("");
171+
Log.Information($"nuget CLI executed with {nugetCLI.ExitCode} exit code");
172+
173+
Log.Information(nugetCLI.StandardError.ReadToEnd());
174+
175+
return false;
176+
}
177+
}
178+
}
179+
180+
Log.Information("");
181+
Log.Information("Updating .NET nanoFramework references using nuget CLI");
182+
183+
// run nuget CLI to perform update
184+
nugetCLI = new Process
134185
{
135186
StartInfo = new ProcessStartInfo
136187
{
137188
FileName = Path.Combine(rootDir, "Tools/nuget.exe"),
138189
Arguments = $"update {path}\\UnitsNet.nanoFramework.sln -PreRelease",
139190
UseShellExecute = false,
140-
CreateNoWindow = true
191+
CreateNoWindow = true,
192+
RedirectStandardError = true
141193
}
142194
};
143195

@@ -199,11 +251,18 @@ public static void UpdateNanoFrameworkDependencies(
199251
{
200252
Log.Information("");
201253
Log.Information($"nuget CLI executed with {nugetCLI.ExitCode} exit code");
254+
255+
Log.Information(nugetCLI.StandardError.ReadToEnd());
256+
257+
return false;
202258
}
203259
}
260+
204261
}
205262

206263
Log.Information("");
264+
265+
return true;
207266
}
208267

209268
private static NanoFrameworkVersions ParseCurrentNanoFrameworkVersions(string rootDir)

CodeGen/Program.cs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,11 +74,14 @@ public static int Main(bool verbose = false, DirectoryInfo? repositoryRoot = nul
7474
UnitsNetWrcGenerator.Generate(rootDir, quantities);
7575
}
7676

77-
if(updateNanoFrameworkDependencies)
77+
if (updateNanoFrameworkDependencies)
7878
{
79-
NanoFrameworkGenerator.UpdateNanoFrameworkDependencies(
79+
if (!NanoFrameworkGenerator.UpdateNanoFrameworkDependencies(
8080
rootDir,
81-
quantities);
81+
quantities))
82+
{
83+
return 1;
84+
}
8285
}
8386

8487
if (!skipNanoFramework)

tools/NuGet.exe

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
version https://git-lfs.github.com/spec/v1
2-
oid sha256:852b71cc8c8c2d40d09ea49d321ff56fd2397b9d6ea9f96e532530307bbbafd3
3-
size 6784920
2+
oid sha256:04eb6c4fe4213907e2773e1be1bbbd730e9a655a3c9c58387ce8d4a714a5b9e1
3+
size 7034784

0 commit comments

Comments
 (0)