Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test projects are not excluded with option "exclude-test-projects" #669

Open
AlbertoMonteiro opened this issue Mar 29, 2023 · 7 comments
Open
Labels

Comments

@AlbertoMonteiro
Copy link
Contributor

Opening a new issue because the previous one was closed, but didnt fixed all the cases as I explained in my comment:
#363 (comment)

@Bertk
Copy link
Contributor

Bertk commented Apr 5, 2023

Please add the property <IsTestProject>true</IsTestProject> in the test csproj file. As far as I know cyclonedx-dotnet does not merge all props and target files.

@schoofseggl
Copy link

I can confirm this bug. In Directory.Build.Props we set the property IsTestProject to all test projects:

	<PropertyGroup Condition="$(MSBuildProjectName.EndsWith('.Tests')) or $(MSBuildProjectName.EndsWith('.IntegrationTests'))">
		<IsPackable>False</IsPackable>
		<IsTestProject>True</IsTestProject>
	</PropertyGroup>

But during the run it was analyzed even though we called it with the option to ignore test projects. When we set it directly in the csproj file, it is skipped as expected.

@Bertk
Copy link
Contributor

Bertk commented Jul 18, 2023

The cyclonedx-dotnet tool uses solution, project and intermediate output file project.assets.json. The tool is executed after a build is executed and does not use or create any derived project property settings from build target.

Therefore the definition of the IsTestProject property in a *.props or *.target file which is resolved during build target execution cannot be used for the exclude-test-projects option.

This limitation for exclude-test-projects option should be documented in README.md.

--exclude-test-projects option resolves IsTestProject property value from project file after a build is executed. Therefore <IsTestProject>true</IsTestProject> shall be defined in csproj file or in an explicit import property file within the csproj file without conditions.

@schoofseggl
Copy link

This is technically understood - but from a user perspecitve I am now forced to apply an error prone + manual process (to add the flag everywhere and don't forget that in the future) where there is already a better and central place.

What about having an --ignore-pattern commandline paramter, where I can specify pattern to ignore projects that should not be scanned?

@Bertk
Copy link
Contributor

Bertk commented Jul 19, 2023

A new feature with a command line option filter projects could solve it but the list of options is already pretty huge.

Anyway, #736 might be a better solution which also allows to eliminate some low level XML document handling.

Copy link

This issue is stale because it has been open for 3 months with no activity.

@github-actions github-actions bot added the stale label Dec 31, 2023
@t4m45
Copy link

t4m45 commented Aug 29, 2024

Just for information, I had the same issue in a .net framework 4.8 project. The <IsTestProject>true</IsTestProject> property was set, but the projects were not excluded.

Turns out, I had to migrate the packages.config files to PackageReference. After that, the exclude-test-projects parameter was working properly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants