I want to check if a c# project is NUnit or MSTest based. Currently, I read csproj's file and look for a specific string like below.
const string MSTEST_ELEMENT = "<TestProjectType>UnitTest</TestProjectType>";
const string NUNIT_ELEMENT = @"<Reference Include=""nunit.framework"">";
var file = File.ReadAllText("C:\myfile.csproj");
if (file.Contains(NUNIT_ELEMENT))
{
result = TestProjectType.NUnit;
}
else if (file.Contains(MSTEST_ELEMENT))
{
result = TestProjectType.MSTest;
}
It works as I expected but looking for a specific text in a file is ugly for me. Is there a better way to do this?