Skip to content

NSBFUNC004 triggers for test projects referencing a project that has functions - #115

Closed
andreasohlund wants to merge 5 commits into
mainfrom
NSBFUNC004-bug
Closed

NSBFUNC004 triggers for test projects referencing a project that has functions#115
andreasohlund wants to merge 5 commits into
mainfrom
NSBFUNC004-bug

Conversation

@andreasohlund

@andreasohlund andreasohlund commented Jun 4, 2026

Copy link
Copy Markdown
Member

root cause: Test projects are treated like exes

$ dotnet msbuild "src/InternalAutomation.Tests/InternalAutomation.Tests.csproj" -getProperty:OutputType
Exe

due to

- Microsoft.NET.Test.Sdk overrides the project's output type for .NET test projects.
- In ~/.nuget/packages/microsoft.net.test.sdk/18.5.1/build/net8.0/Microsoft.NET.Test.Sdk.targets:21:
<OutputType Condition="'$(UseWinUI)' != 'true' AND '$(UseUwpTools)' != 'true'">Exe</OutputType>

// because SourceGeneratorTest currently does not flow WithProperty(...) values to analyzers.
// Keep this fallback until analyzer config options are propagated in Particular.AnalyzerTesting.
public static bool IsIsolatedFunctionsProject(Compilation compilation, AnalyzerConfigOptions options)
=> IsIsolatedFunctionsProject(options) || compilation.GetTypeByMetadataName(FunctionAttribute) is not null;

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was the bug since it treated access to the attribute as "you are a functions project," which isn't correct

@andreasohlund andreasohlund Jun 4, 2026

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Test projects will be treated as exe even though they have <OutputType>Library</OutputType> explicitly set

@andreasohlund

Copy link
Copy Markdown
Member Author

Needs to be updated with Particular/Particular.AnalyzerTesting#31 for tests to pass

@danielmarbach

Copy link
Copy Markdown
Contributor

Should w switch to the function version instead? We can probably get it and just assert is greater than some version and be done with it?

@danielmarbach

danielmarbach commented Jun 4, 2026

Copy link
Copy Markdown
Contributor

The more I think about it the more I'm convinced we should kill this. There is a lot of complexity and the danger of misbehaving for something that you literally type once and then never touch again as a user and when you hit F5 in dev and your functions haven't been invoked you also immediately know what's missing because that literally the first thing we point out in the documentation.

@andreasohlund

Copy link
Copy Markdown
Member Author

I think that makes sense, I'll raise a PR to remove instead

@andreasohlund

Copy link
Copy Markdown
Member Author

Replaced by #116

@andreasohlund
andreasohlund deleted the NSBFUNC004-bug branch June 5, 2026 05:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants