cyclonedx-dotnet
cyclonedx-dotnet copied to clipboard
Test projects are not excluded with option "exclude-test-projects"
We have dotnet core 5.0 projects where the property < IsTestProject>true</ IsTestProject> is not present, but vs still identfy it as test project. To avoid manual effort to add this property to all test projects it would be nice if cyclonedx dotnet can also identfy testprojects in a way how visualstudio is doing it.
Does anyone know what mechanism is used to detect test projects? I started digging into the .NET source but had trouble finding it.
@coderpatros I believe it is here: /CycloneDX.Core/Services/ProjectFileService.cs
public static bool IsTestProject(string projectFilePath)
{
XmlDocument xmldoc = new XmlDocument();
xmldoc.Load(projectFilePath);
XmlElement elt = xmldoc.SelectSingleNode("/Project/PropertyGroup[IsTestProject='true']") as XmlElement;
return elt != null;
}
I think it is done by the vstest adapters to identify through its test framework.This might be an overkill to re-implement this here for all test frameworks so I would like to close this issue with the comment that all testprojects need to add the IsTestProject property with the value true (maybe a hint in the readme?)
If there are no others who want this issue to be opened - I will close it by end of this week.
@coderpatros I believe it is here: /CycloneDX.Core/Services/ProjectFileService.cs
public static bool IsTestProject(string projectFilePath) { XmlDocument xmldoc = new XmlDocument(); xmldoc.Load(projectFilePath); XmlElement elt = xmldoc.SelectSingleNode("/Project/PropertyGroup[IsTestProject='true']") as XmlElement; return elt != null; }
I should have been more specific. How does the .NET tooling detect a test project.
It might be as simple as looking for a dependency reference to the Microsoft.NET.Test.Sdk test adapter.
I think it is done by the vstest adapters to identify through its test framework.This might be an overkill to re-implement this here for all test frameworks so I would like to close this issue with the comment that all testprojects need to add the IsTestProject property with the value true (maybe a hint in the readme?)
If there are no others who want this issue to be opened - I will close it by end of this week.
There should be a section added to the README on how test dependencies are detected and handled. But I would like to keep the issue open until there is a better solution than just use the IsTestProject
property.
Another topic, I think for now the < IsTestProject> property does not work when the property is imported from a property sheet, for example, our project is configured like
<Import Project="..\..\_Globals\PropertySheets\CSharpNetCoreAppTest.props" />
and in the CSharpNetCoreAppTest.props we already add the property < IsTestProject>true</ IsTestProject>, but this project is not excluded, only when we add the property explicitly in the project, then it's excluded, so could you please check that?
I ran into the same problem, since we reference it in a more 'general' place. The code simple loads de .csproj file and now (after PR 585) checks for Microsoft.Net.Test.SDK reference or explicit IsTestProject.
Both are provided via NuGet in my case (Test.SDK as 2nd level package reference and IsTestProject via buildtransitive .props.
It looks like we still need to set IsTestProject explicitly for the moment.
The PR #585 did not fix it at all, I use Directory.Build.props in my root test folder, there is the <IsTestProject>true</IsTestProject>
, but since the code just look into the csproj xml, its not enough