-
Notifications
You must be signed in to change notification settings - Fork 212
Allow Razor cohosting to work with non-Razor SDK projects #12118
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
Changes from all commits
56966ae
84d8816
902486c
14d8062
d2f67b4
3b63388
df18762
fd0ea99
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
<!-- | ||
*********************************************************************************************** | ||
Microsoft.CSharpExtension.DesignTime.targets | ||
|
||
A polyfill for the real Microsoft.CSharp.DesignTime.targets file that is supplied by the .NET | ||
project system in Visual Studio and the C# Dev Kit extension. | ||
https://github.com/dotnet/project-system/blob/8ba13c7fa917b86462e0ff32a07ef3e15eb8dfa6/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/DesignTimeTargets/Microsoft.CSharp.DesignTime.targets | ||
|
||
WARNING: DO NOT MODIFY this file unless you are knowledgeable about MSBuild and have | ||
created a backup copy. Incorrect changes to this file will make it | ||
impossible to load or build your projects from the command-line or the IDE. | ||
|
||
Copyright (c) .NET Foundation. All rights reserved. | ||
*********************************************************************************************** | ||
--> | ||
|
||
<Project> | ||
|
||
<!-- Razor cohosting support for projects that don't use the Razor SDK --> | ||
|
||
<!-- | ||
If there are any .razor or .cshtml files in this project we want to do three things: | ||
|
||
1. Add a 'RazorWithoutSdk' capability to the project so tooling can light up as necessary | ||
2. Reference the Razor source generator | ||
3. Add each .razor and .cshtml file to the project as an AdditionalFiles item so the source generator can see it | ||
--> | ||
|
||
<!-- .NET Framework uses a different editor in VS --> | ||
<Target Name="DetectRazorOrCshtmlFiles" BeforeTargets="AssignProjectConfiguration" Condition="'$(UsingMicrosoftNETSdkRazor)' != 'true'"> | ||
<ItemGroup> | ||
<!-- Collect all Razor and CSHTML files --> | ||
<_RazorOrCshtmlFiles Include="**\*.razor;**\*.cshtml" /> | ||
</ItemGroup> | ||
|
||
<!-- Add a capability to control initialization of Razor in the IDE --> | ||
<ItemGroup Condition="'@(_RazorOrCshtmlFiles)' != ''"> | ||
<ProjectCapability Include="RazorWithoutSdk" /> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we need to condition this with a 'back out' flag? I assume it won't do anything bad to have it on, so probably not? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, project capabilities don't do anything, they're just like attributes you attach to things. In this case, given this file is only used in the C# Extension, even adding the capability is redundant, since it doesn't do anything and nothing cares whether its there, but its easier to have the files matching :) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Is there a way to avoid the copy/paste of the file? Or if not, can this at least link to the other file somewhere so somebody knows when to update one they can also update the other? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It is linked at the top of this file (at least, I think I remember doing that, but I'm typing this on my phone so who knows!) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You linked to the whole file, but that's a somewhat different flavor. Not sure if that repo should minimally extract a file out so some file can be the same, or whether we should just adopt that file into the C# extension project system directly. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Logged #12137 |
||
</ItemGroup> | ||
|
||
<!-- As a get out of jail card, we let users turn off anything impactful, but their IDE won't really work. --> | ||
<ItemGroup Condition="'$(DisableAllRazorFilesAsAdditionalFiles)' != 'true' And '@(_RazorOrCshtmlFiles)' != ''"> | ||
<AdditionalFiles Include="@(_RazorOrCshtmlFiles)" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup Condition="'$(DisableAutomaticRazorSourceGeneratorReference)' != 'true' And '@(_RazorOrCshtmlFiles)' != ''"> | ||
<!-- Our analyzer loader will redirect DLL loads to the right place for tooling, as long as the right filename is referenced --> | ||
<Analyzer Include="Microsoft.CodeAnalysis.Razor.Compiler.dll" /> | ||
</ItemGroup> | ||
</Target> | ||
|
||
</Project> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But who can edit this file if only those knowledgable in MSBuild can edit it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thats why I created the file, because I'm not qualified to modify it 😁