2012-10-23 2 views
2

누구나 다음 코드가 PS 화면에 "blablabla"를 표시하지 않는 이유를 말해 줄 수 있습니까? 내가 보는 모든 함수에서 반환되는 임의의 숫자입니다.Console.WriteLine이 NuGet Package Manager 창에 아무 것도 출력하지 않는 이유는 무엇입니까?

# Create a function that loads our managed code into powershell 
function InitType 
{ 
    [string]$SourceCode = @" 

    using System; 

    namespace TestApp 
    {  

     // This class houses the public methods that we'll use from powershell 

     public static class TestMethods 
     { 
      public static int GetRandom() 
      { 
       var id = new Random().Next(); 
       Console.WriteLine("bla bla bla"); 
       return id; 
      } 
     } 
    } 
"@ 

    # use the powershell 2.0 add-type cmdlet to compile the source and make it available to our powershell session 
    add-type -TypeDefinition $SourceCode 
} 

# Load our C# code 
InitType 

# Call our method 
[TestApp.TestMethods]::GetRandomAndOutputMessage 

()

+0

내 시스템에서는 [TestApp.TestMethods] :: GetRandom()을 호출하고 var 대신 int를 사용합니다. 올바른 코드를 게시했는지 확인하십시오. – vonPryz

+0

powershell v3.0에서 코드가 작동합니다! '[TestApp.TestMethods] :: GetRandom() '을 호출합니다 –

+0

어쩌면 제가 누락되었지만 TestMethods가 GetRandomAndOutputMessage()가 아닌 GetRandom을 정의합니다 – Anonimista

답변

3

Nuget 패키지 관리자는 PowerShell 콘솔이 아니다. Console.WriteLine 콘솔 "응용 프로그램"의 콘솔에 씁니다. Visual Studio는 콘솔 응용 프로그램이 아닙니다. NPM을 실행하는 창은 PowerShell 엔진을 호스팅하고 PSHost 인터페이스를 구현하여 엔진이 정보를 창에 출력 할 수 있도록합니다. Console.WriteLine은 해당 시나리오에서 작동하지 않습니다.

관련 문제