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

Detect test projects without build #110

Open
eNeRGy164 opened this issue May 14, 2019 · 4 comments
Open

Detect test projects without build #110

eNeRGy164 opened this issue May 14, 2019 · 4 comments
Labels
General Enhancement New feature or request

Comments

@eNeRGy164
Copy link
Contributor

When loading a solution, I'ld like to differentiate between "normal" projects and "test" projects without compiling the project.
It seems that Buildalyzer doesn't surface the properties that shows these details.

I could look at PackageReferences, but these are not parsed in the ProjectFile class. It only shows if there are any references.
This would be a small change and can help if the person analyzing a solution knows which test framework is used for a certain project.

There is also a more generic and robust way.
As far as I can determine, Visual Studio looks at the IsTestProject property that is inserted by
NuGet packages like xunit.core or Microsoft.NET.Test.Sdk using a .props file like this:

<Project>
  <PropertyGroup>
    <IsTestProject>true</IsTestProject>
  </PropertyGroup>
</Project>

For example, removing the last package reference containing this property from a project will immediately change the icon of a project in Visual Studio.

Currently, only the AnalyzeResults show this property after calling the expensive Build() method.
Is there a way to access the loaded .props using Buildalyzer?

@daveaglick
Copy link
Collaborator

I could look at PackageReferences, but these are not parsed in the ProjectFile class. It only shows if there are any references.

Thanks for the PR! I'm assuming that addresses this method of checking for test projects?

Currently, only the AnalyzeResults show this property after calling the expensive Build() method.
Is there a way to access the loaded .props using Buildalyzer?

No, not currently. I'm not even totally sure what that would look like - Buildalyzer gets it's data by hooking the logging that MSBuild performs during a build. I'd need some other mechanism to get the props file and it would have to be cross-platform and have a reasonable fallback if the project weren't built yet.

There may be another easier way. In searching for IsTestProject uses across the dotnet org, it looks like that property typically gets defined based on path:

https://github.com/dotnet/buildtools/blob/28606b8791ccf507651febbf41c480dd87d4a507/src/Microsoft.DotNet.Build.Tasks/PackageFiles/Build.Common.props#L60

We could either expose something similar or, given that I'm not sure I want to bake this in since it's not exactly authoritative, you could do a similar check for tests in the path using ProjectFile.Path.

@daveaglick daveaglick added the Discussion/Question Discussions or questions about the code label May 16, 2019
@eNeRGy164
Copy link
Contributor Author

Thanks for the PR! I'm assuming that addresses this method of checking for test projects?

Yup, thanks for merging.

No, not currently. I'm not even totally sure what that would look like - Buildalyzer gets it's data by hooking the logging that MSBuild performs during a build. I'd need some other mechanism to get the props file and it would have to be cross-platform and have a reasonable fallback if the project weren't built yet.

There may be another easier way. In searching for IsTestProject uses across the dotnet org, it looks like that property typically gets defined based on path:

https://github.com/dotnet/buildtools/blob/28606b8791ccf507651febbf41c480dd87d4a507/src/Microsoft.DotNet.Build.Tasks/PackageFiles/Build.Common.props#L60

We could either expose something similar or, given that I'm not sure I want to bake this in since it's not exactly authoritative, you could do a similar check for tests in the path using ProjectFile.Path.

I think there is somewhere, something available that should make this visible without a build(). But I'm not sure where to look for the msbuild properties/analyzer results for the designtime build that is produced.

@daveaglick
Copy link
Collaborator

👍 I'll leave this issue open as a feature request and we can add more support if anyone figures out what to look at.

@daveaglick daveaglick added General Enhancement New feature or request and removed Discussion/Question Discussions or questions about the code labels May 17, 2019
@molekp
Copy link

molekp commented Feb 4, 2022

Hi
I would also like to have AnalyzerResult without calling Build().

I'm working on new feature in Stryker.Net that will allow to execute it without building projects (see stryker-mutator/stryker-net#466). We currently calling it to examine properties of testing project (like TargetFramework). When we using it, our (already) builded projects are cleared.

Is it posiible to prevent to clear output directory or implement this feature (getting AnalyzerResult without building project)?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
General Enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants