Skip to content

Allow Razor files to appear in any source item type#7417

Merged
drewnoakes merged 11 commits intodotnet:mainfrom
davidwengier:RazorFilesCanBeInAnyItemType
Jul 27, 2021
Merged

Allow Razor files to appear in any source item type#7417
drewnoakes merged 11 commits intodotnet:mainfrom
davidwengier:RazorFilesCanBeInAnyItemType

Conversation

@davidwengier
Copy link
Member

@davidwengier davidwengier commented Jul 22, 2021

Fixes #7411
Fixes dotnet/aspnetcore#34188

This changes the DynamicItemHandler for Razor so that instead of being hardcoded to the Content item type, it now uses CPSes SourceItemsService (via an ISourceItemsHandler) so that it can see all items in any type that is considered a source file. Essentially my understanding is that this will now see any file that is in the project tree. This solves various issues from enterprise solutions:

  • OrchardCore includes Razor files in the EmbeddedResource item type
  • Bing has Razor files in the None item type (ie, the default from the SDK) and uses custom build targets and tasks to process them at build time
  • MAUI uses a custom item type added by AvailableItemName

I'm still doing manual validation, but want to get a real build so may as well put this up too.

Microsoft Reviewers: Open in CodeFlow

@davidwengier davidwengier requested a review from a team as a code owner July 22, 2021 05:32
}

public void Handle(IComparable version, IProjectChangeDescription projectChange, ContextState state, IProjectDiagnosticOutputService logger)
public void Handle(IComparable version, IImmutableDictionary<string, IProjectChangeDescription> projectChanges, ContextState state, IProjectDiagnosticOutputService logger)
Copy link
Member Author

Choose a reason for hiding this comment

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

Recommend reviewing this file with whitespace turned off, otherwise GitHub overplays the changes.

@drewnoakes
Copy link
Member

Looks good.

As discussed separately, this may add Razor files to intellisense which are not present in the build.

It seems like it would be safer to have a property that controls which item types are considered dynamic. This could be added here I think, with a small tweak to your new ISourceItemHandler interface to also take ConfigurationGeneral, sync-linked to the items it receives today, then pulling from the required item type(s) alone.

@davidwengier
Copy link
Member Author

It works!
image

(Top is VS 2022 normal, bottom is with my changes)

@davidwengier
Copy link
Member Author

And verified in Project System Tools when dumping the Roslyn workspace that all of the right files are there. I think this is good to go from my point of view.

this may add Razor files to intellisense which are not present in the build

For the Razor editor this is actually a good thing. Firstly it matches the experience of using the old editor, which is the main concern we have (we don't want users to notice that anything is different in VS 2022 with the new editor), and its also something I think we are happy with, with respect to lighting up the editor in any circumstances. If that changes in future we can always update.

@davidwengier
Copy link
Member Author

Not sure how you'll feel about the last couple of commits here.. but I thought it beat duplicating all those methods to handle a 2-tuple. If a larger refactoring is desired, you can always do it when you fix the evaluation bit 😛

@davidwengier
Copy link
Member Author

@dotnet/project-system can I get reviews on this? would love to get this in to preview 3 so Bing can test it etc.

@drewnoakes drewnoakes merged commit cd57cde into dotnet:main Jul 27, 2021
@ghost ghost added this to the 17.0 milestone Jul 27, 2021
@davidwengier
Copy link
Member Author

Thanks Drew!

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.

Don't hardcode dynamic file item type Consider moving Content includes for cshtml and razor files from RazorSDK -> NETSdk

3 participants