I want to wait until dotnet hosting bundle is installed. Usually there would a some sort of return code:
- 0 -> ok
- < 1 -> error
PS D:\app> .\dotnet-hosting-6.0.4-win.exe /install /passive /norestart
Msi doesn't exist, is there any other way?
I want to wait until dotnet hosting bundle is installed. Usually there would a some sort of return code:
PS D:\app> .\dotnet-hosting-6.0.4-win.exe /install /passive /norestart
Msi doesn't exist, is there any other way?
We solved it by running next command in a loop:
using System.ComponentModel;
using System.Diagnostics;
bool found = false;
// 36 * 5s = 180s = 3 minutes
for (int i = 0; i < 36; i++)
{
try
{
using Process p = new();
if (!string.IsNullOrWhiteSpace(Environment.GetEnvironmentVariable("SYSTEMROOT")))
{
p.StartInfo.WorkingDirectory = Environment.GetEnvironmentVariable("SYSTEMROOT");
}
p.StartInfo.FileName = "dotnet";
p.StartInfo.Arguments = "--list-runtimes";
p.Start();
// additionally we can search for desired runtime
found = true;
break;
}
catch (Win32Exception)
{
// command is not available yet
}
Thread.Sleep(5000);
}
Runtimes example:
Microsoft.AspNetCore.App 3.1.23 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 3.1.28 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 3.1.31 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 5.0.15 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 5.0.17 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 6.0.4 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 6.0.5 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 6.0.8 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 6.0.11 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.NETCore.App 3.1.23 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 3.1.28 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 3.1.31 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 5.0.15 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 5.0.17 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 6.0.4 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 6.0.5 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 6.0.8 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 6.0.11 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.WindowsDesktop.App 3.1.23 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 3.1.28 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 3.1.31 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 5.0.15 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 5.0.17 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 6.0.4 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 6.0.5 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 6.0.8 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 6.0.11 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
You can try to use Start-Process -Wait
to run the installer and wait for it to finish:
Start-Process .\dotnet-hosting-6.0.4-win.exe -ArgumentList "/install /passive /norestart"
I didn't test it on ASP.NET Core Runtime 6.0 but I had similar problem with installing .NET SDK 6.0. Running in Powershell just this command as described in docs:
./dotnet-sdk-6.0.403-win-x64.exe /install /quiet /norestart
started the installation process but immediately returned to Powershell (the installation continued in the background). It seems that .exe and .msi installers works that way and you need to use start /wait
in cmd or Start-Process -Wait
in Powershell to wait in terminal/script for the process installation to finish. Like this:
Powershell
Start-Process -Wait 'C:\dotnet-sdk-6.0.410-win-x64.exe' -ArgumentList '/install /quiet /norestart';
cmd
start /w C:\dotnet-sdk-6.0.410-win-x64.exe /install /quiet /norestart