Bardzo ... bardzo dziwny problem.Właściwość "Informacje" we właściwości Strumień instancji Powershell niedostępna kompilacja
Korzystanie VS2015 oraz .NET 4,52
opracowałem ten kod C# PowerShell jest uruchomiony skrypt i łapie wyjście. tak:
using (PowerShell powerShellInstance = PowerShell.Create())
{
powerShellInstance.AddScript(scriptContents);
Collection<PSObject> PSOutput = powerShellInstance.Invoke();
if (powerShellInstance.Streams.Information.Count > 0)
{
foreach (var item in powerShellInstance.Streams.Information)
{
//do something with info
}
}
}
}
Kompiluje i uruchamia (na komputerze z systemem Windows 10 pro), bez problemów.
Dopóki mam nową maszynę (powierzchnia Pro 4, tak też Windows 10 Pro) i starał się skompilować kod, otrzymuję ten błąd:
'PSDataStreams' does not contain a definition for 'Information' and no extension method 'Information' accepting a first argument of type 'PSDataStreams' could be found (are you missing a using directive or an assembly reference?)
To wszystko jest oparte TFS, więc jestem na pewno jest to ten sam kod.
Gdybym goto definicja na dwóch maszynach problem staje się oczywiste:
Więc wykomentowane kodu nie kompilacji i prowadził ją, aby zobaczyć, co się dzieje Runtime:
Więc nieruchomość jest tam. Czy ktoś ma dobre wytłumaczenie tego?
BTW: dokumentacja msdn nie wspomina właściwość informacji ..
Czy zainstalowałeś Powershell 5 Preview na starym systemie, ale nie nowy? A może różne wersje między nimi? – alroc
Nie, to jest maszyna z czystym Winem 10, tylko z zainstalowanym studiem – Flores