CAKE 0.21.1.0을 사용합니다.다른 .cake 파일에 CakeContext 전달
내 build.cake
스크립트에 다른 .cake
스크립트 : tests.cake
이로드됩니다.
tests.cake
에는 TestRunner
이라는 클래스가 있습니다. TestRunner
에는 RunUnitTests()
이라는 메서드가 있으며 VSTest
메서드 provided by CAKE을 사용하여 단위 테스트를 실행합니다.
build.cake
에서 나는 TestRunner
의 몇 가지 인스턴스를 만듭니다.
error CS0120: An object reference is required for the non-static field, method, or property 'VSTest(IEnumerable<FilePath>, VSTestSettings)'
내가 tests.cake
에 CakeContext
의 명시 적 인스턴스 VSTest
를 호출해야하기 때문에이 생각 : 나는 인스턴스 중 하나에 RunUnitTests()
메소드를 호출 할 때마다, 나는 다음과 같은 오류 메시지가 표시됩니다.
내 질문 : 내 tests.cake
스크립트가 CakeContext
인스턴스를 내 build.cake
스크립트와 공유하도록하려면 어떻게해야합니까? 컴파일하려면 tests.cake
을 얻으려면 어떻게해야합니까?
편집 :
devlead's reply에 대응하여, 좀 더 정보를 추가하기로 결정했습니다.
내가 devlead의 제안을 따라 내RunUnitTests()
방법 서명을 변경 :
TestRunnerAssemblies
읽기 전용 사전이다
TestRunner testRunner = TestRunnerAssemblies[testRunnerName];
testRunner.RunUnitTests(this);
을 :
public void RunUnitTests(ICakeContext context)
build.cake
에서, 내 작업 중 하나는 다음과 같은 작업을 수행합니다 tests.cake
및 testRunnerName
은 이전에 정의 된 변수입니다. (build.cake
, 나는 #l "tests.cake"
를 삽입 한.)
지금이 오류 메시지가 표시 :
error CS0027: Keyword 'this' is not available in the current context
내가 잘못하고있는 중이 야 무엇을?
편집 :
는 좀 더주의 깊게 읽는 방법을 배울 필요, 신경 쓰지 마. this
을 전달하는 대신, 원래 제안 된 devlead처럼 Context
을 대신 전달했습니다. 이제 RunUnitTests
메소드를 문제없이 호출 할 수 있습니다.
다음과 같이 this'는 대신,'Context'을 사용'사용하지 마십시오 https://github.com/cake -contrib/Cake.Recipe/blob/develop/setup.cake # L13 또한 @devlead 예제에 표시된대로 –