[英]How can I easily get the path of a file inside a folder in my solution in Visual Studio with C#?
[英]How can I programmatically get information about or manipulate another solution? (Visual Studio, C#)
我設法編寫了可以清理和構建另一個解決方案的代碼,並從該解決方案中運行了所有MSTest(可能還有其他諸如NUnit之類的),但是我需要能夠獲取所有測試類和方法名稱,以便分別運行測試(或者一次運行全部時,我可以從輸出字符串中提取通過/失敗的測試的名稱-但這不是很可靠的長期方法)。
我覺得這應該都是一個單獨的程序/插件,然后我可以在項目中使用所需的方式-但是肯定有人已經寫過類似的東西了嗎?
我在想我可以做類似的事情:
var solution = new Solution("C:\Documents\VisualStudioFolder\MySolution.sln");
solution.Clean();
solution.Build(); // could return a bool to check it was successful
List<Test> tests = solution.GetTests();
foreach (Test test in tests) {
if (test.Run()) {
Console.WriteLine("Test passed");
}
}
這種東西存在嗎?
我需要做的是編寫一個Visual Studio包(一個插件),您可以在其中訪問當前打開的解決方案:
var solution = ((DTE) GetService(typeof (DTE))).Solution;
接着:
var buildObject = solution.SolutionBuild;
buildObject.Build(true); // saves and builds
if (buildObject.LastBuildInfo == 0) {
//then build was successful
}
我仍然沒有找到運行測試的好方法,但是希望這對將來的人有所幫助。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.