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
()
내 시스템에서는 [TestApp.TestMethods] :: GetRandom()을 호출하고 var 대신 int를 사용합니다. 올바른 코드를 게시했는지 확인하십시오. – vonPryz
powershell v3.0에서 코드가 작동합니다! '[TestApp.TestMethods] :: GetRandom() '을 호출합니다 –
어쩌면 제가 누락되었지만 TestMethods가 GetRandomAndOutputMessage()가 아닌 GetRandom을 정의합니다 – Anonimista