Skip to content

Exclude snapshot files from the build - #2034

Open
SimonCropp wants to merge 2 commits into
mainfrom
exclude-snapshots-from-build
Open

SimonCropp wants to merge 2 commits into
mainfrom
exclude-snapshots-from-build

Conversation

@SimonCropp

Copy link
Copy Markdown
Member

A snapshot can have any extension, and many extensions mean something to the build:

  • .verified.cs / .verified.vb are compiled
  • .verified.resx is embedded
  • .verified.xaml is compiled as a page
  • .verified.razor / .verified.cshtml are compiled as components and views
  • the Web and Worker SDKs copy .verified.json and .verified.config to the output and publish directories

Verify.targets now removes snapshot files from the default Compile, EmbeddedResource, Content, Page, ApplicationDefinition, MauiXaml and AvaloniaXaml items and leaves them as None, so they still show nested in the IDE.

  • This happens in Verify.targets, not Verify.AfterMicrosoftNetSdk.props, because the Razor, Web and Worker SDKs glob their Content after that props file.
  • A Content snapshot is moved to None with its metadata, so it keeps its nesting and any explicit DependentUpon. Its copy settings are cleared.
  • Each item type is skipped when its default items are disabled (eg EnableDefaultCompileItems=false).
  • Opt out with <DisableVerifySnapshotExclusion>true</DisableVerifySnapshotExclusion>.

Behaviour change: a project that explicitly includes snapshots as Content now gets them as None, since MSBuild cannot tell those apart from the SDK's default items. The opt-out restores the old behaviour.

FileNestingTests now also report Compile and EmbeddedResource items and copy metadata, with new cases for source/resource snapshots, Razor/cshtml snapshots and the opt-out. The opt-out case shows the current behaviour: .verified.cs is compiled and .verified.resx embedded.

Once this ships, build/Verify.SourceGenerators.targets in Verify.SourceGenerators is redundant: it only removes *.verified.cs / *.received.cs from Compile.

A snapshot can have any extension, and many extensions mean something to
the build: .verified.cs is compiled, .verified.resx embedded, .xaml compiled
as a page, .razor/.cshtml compiled, and the Web and Worker SDKs copy .json
and .config snapshots to the output and publish directories.

Snapshots are now removed from the default Compile, EmbeddedResource,
Content, Page, ApplicationDefinition, MauiXaml and AvaloniaXaml items and
left as None. Content snapshots move to None with their metadata, keeping
any DependentUpon but not their copy settings. Opt out with
DisableVerifySnapshotExclusion.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

1 participant