Skip to content

Commit 296d344

Browse files
authored
Allow Razor cohosting to work with non-Razor SDK projects (#12118)
Part of #11834
2 parents b662c82 + fd0ea99 commit 296d344

File tree

2 files changed

+67
-2
lines changed

2 files changed

+67
-2
lines changed

src/Razor/src/Microsoft.VisualStudioCode.RazorExtension/Microsoft.VisualStudioCode.RazorExtension.csproj

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,21 @@
4343
</ItemGroup>
4444

4545
<ItemGroup>
46-
<!-- Need to make sure ObjectPool is in the bin folder for local development scenarios -->
47-
<None Include="$(PkgMicrosoft_Extensions_ObjectPool)\lib\net8.0\Microsoft.Extensions.ObjectPool.dll" CopyToOutputDirectory="PreserveNewest" Visible="false" />
46+
<!-- Need to make sure ObjectPool is in the bin folder for local development scenarios -->
47+
<None Include="$(PkgMicrosoft_Extensions_ObjectPool)\lib\net8.0\Microsoft.Extensions.ObjectPool.dll" CopyToOutputDirectory="PreserveNewest" Visible="false" />
48+
49+
<Content Include="..\rzls\Targets\**\*.*">
50+
<LinkBase>Targets</LinkBase>
51+
<Pack>true</Pack>
52+
<PackagePath>content\Targets</PackagePath>
53+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
54+
</Content>
55+
56+
<Content Include=".\Targets\**\*.targets">
57+
<Pack>true</Pack>
58+
<PackagePath>content\Targets</PackagePath>
59+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
60+
</Content>
4861
</ItemGroup>
4962

5063
<Target Name="PackPublishContent" DependsOnTargets="Publish">
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
<!--
2+
***********************************************************************************************
3+
Microsoft.CSharpExtension.DesignTime.targets
4+
5+
A polyfill for the real Microsoft.CSharp.DesignTime.targets file that is supplied by the .NET
6+
project system in Visual Studio and the C# Dev Kit extension.
7+
https://github.com/dotnet/project-system/blob/8ba13c7fa917b86462e0ff32a07ef3e15eb8dfa6/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/DesignTimeTargets/Microsoft.CSharp.DesignTime.targets
8+
9+
WARNING: DO NOT MODIFY this file unless you are knowledgeable about MSBuild and have
10+
created a backup copy. Incorrect changes to this file will make it
11+
impossible to load or build your projects from the command-line or the IDE.
12+
13+
Copyright (c) .NET Foundation. All rights reserved.
14+
***********************************************************************************************
15+
-->
16+
17+
<Project>
18+
19+
<!-- Razor cohosting support for projects that don't use the Razor SDK -->
20+
21+
<!--
22+
If there are any .razor or .cshtml files in this project we want to do three things:
23+
24+
1. Add a 'RazorWithoutSdk' capability to the project so tooling can light up as necessary
25+
2. Reference the Razor source generator
26+
3. Add each .razor and .cshtml file to the project as an AdditionalFiles item so the source generator can see it
27+
-->
28+
29+
<!-- .NET Framework uses a different editor in VS -->
30+
<Target Name="DetectRazorOrCshtmlFiles" BeforeTargets="AssignProjectConfiguration" Condition="'$(UsingMicrosoftNETSdkRazor)' != 'true'">
31+
<ItemGroup>
32+
<!-- Collect all Razor and CSHTML files -->
33+
<_RazorOrCshtmlFiles Include="**\*.razor;**\*.cshtml" />
34+
</ItemGroup>
35+
36+
<!-- Add a capability to control initialization of Razor in the IDE -->
37+
<ItemGroup Condition="'@(_RazorOrCshtmlFiles)' != ''">
38+
<ProjectCapability Include="RazorWithoutSdk" />
39+
</ItemGroup>
40+
41+
<!-- As a get out of jail card, we let users turn off anything impactful, but their IDE won't really work. -->
42+
<ItemGroup Condition="'$(DisableAllRazorFilesAsAdditionalFiles)' != 'true' And '@(_RazorOrCshtmlFiles)' != ''">
43+
<AdditionalFiles Include="@(_RazorOrCshtmlFiles)" />
44+
</ItemGroup>
45+
46+
<ItemGroup Condition="'$(DisableAutomaticRazorSourceGeneratorReference)' != 'true' And '@(_RazorOrCshtmlFiles)' != ''">
47+
<!-- Our analyzer loader will redirect DLL loads to the right place for tooling, as long as the right filename is referenced -->
48+
<Analyzer Include="Microsoft.CodeAnalysis.Razor.Compiler.dll" />
49+
</ItemGroup>
50+
</Target>
51+
52+
</Project>

0 commit comments

Comments
 (0)