Browse Source

[Templating] Razor class library for components (#7461)

* [Components] Razor class library for components
* Updates the Razor Class Library to be a portable components library by
  default.
* Adds an option to support the old RCL that includes support for Views
  and pages.
* Usage:
  * `dotnet new razorclasslib` produces the same traditional Razor Class Library.
  * `dotnet new razorclasslib -s false` produces a Razor Class Library without views and pages support.
Javier Calvarro Nelson 7 years ago
parent
commit
6827bb7443

+ 1 - 0
src/ProjectTemplates/Web.ProjectTemplates/Microsoft.DotNet.Web.ProjectTemplates.csproj

@@ -25,6 +25,7 @@
     <!-- These projects product packages that the templates depend on. See GenerateContent.targets -->
     <PackageVersionVariableReference Include="$(RepositoryRoot)src\Azure\AzureAD\Authentication.AzureAD.UI\src\Microsoft.AspNetCore.Authentication.AzureAD.UI.csproj" />
     <PackageVersionVariableReference Include="$(RepositoryRoot)src\Azure\AzureAD\Authentication.AzureADB2C.UI\src\Microsoft.AspNetCore.Authentication.AzureADB2C.UI.csproj" />
+    <PackageVersionVariableReference Include="$(RepositoryRoot)src\Components\Components\src\Microsoft.AspNetCore.Components.csproj" />
     <PackageVersionVariableReference Include="$(RepositoryRoot)src\Components\Browser\src\Microsoft.AspNetCore.Components.Browser.csproj" />
     <PackageVersionVariableReference Include="$(RepositoryRoot)src\Components\Build\src\Microsoft.AspNetCore.Components.Build.csproj" />
     <PackageVersionVariableReference Include="$(RepositoryRoot)src\Components\Server\src\Microsoft.AspNetCore.Components.Server.csproj" />

+ 7 - 2
src/ProjectTemplates/Web.ProjectTemplates/RazorClassLibrary-CSharp.csproj.in

@@ -1,12 +1,17 @@
 <Project Sdk="Microsoft.NET.Sdk.Razor">
 
   <PropertyGroup>
-    <TargetFramework>netcoreapp3.0</TargetFramework>
+    <TargetFramework Condition="'$(SupportPagesAndViews)' == 'True'">netcoreapp3.0</TargetFramework>
+    <TargetFramework Condition="'$(SupportPagesAndViews)' != 'True'">netstandard2.0</TargetFramework>
     <RootNamespace Condition="'$(name)' != '$(name{-VALUE-FORMS-}safe_namespace)'">Company.RazorClassLibrary1</RootNamespace>
   </PropertyGroup>
 
-  <ItemGroup>
+  <ItemGroup Condition="'$(SupportPagesAndViews)' == 'True'">
     <FrameworkReference Include="Microsoft.AspNetCore.App" />
   </ItemGroup>
+  <ItemGroup Condition="'$(SupportPagesAndViews)' != 'True'">
+    <PackageReference Include="Microsoft.AspNetCore.Components" Version="${MicrosoftAspNetCoreComponentsPackageVersion}" />
+    <PackageReference Include="Microsoft.AspNetCore.Components.Build" Version="${MicrosoftAspNetCoreComponentsBuildPackageVersion}" PrivateAssets="all" />
+  </ItemGroup>
 
 </Project>

+ 4 - 0
src/ProjectTemplates/Web.ProjectTemplates/content/RazorClassLibrary-CSharp/.template.config/dotnetcli.host.json

@@ -8,6 +8,10 @@
     "skipRestore": {
       "longName": "no-restore",
       "shortName": ""
+    },
+    "SupportPagesAndViews": {
+      "longName": "support-pages-and-views",
+      "shortName": "s"
     }
   }
 }

+ 16 - 0
src/ProjectTemplates/Web.ProjectTemplates/content/RazorClassLibrary-CSharp/.template.config/template.json

@@ -20,6 +20,16 @@
   },
   "sourceName": "Company.RazorClassLibrary1",
   "preferNameDirectory": true,
+  "sources": [
+    {
+      "modifiers": [{
+        "condition": "(!SupportPagesAndViews)",
+        "exclude": [
+          "Areas/**"
+        ]
+      }]
+    }
+  ],
   "symbols": {
     "Framework": {
       "type": "parameter",
@@ -42,6 +52,12 @@
       "datatype": "bool",
       "description": "If specified, skips the automatic restore of the project on create.",
       "defaultValue": "false"
+    },
+    "SupportPagesAndViews": {
+      "type": "parameter",
+      "datatype": "bool",
+      "defaultValue": "true",
+      "description": "Whether to support adding traditional Razor pages and Views in addition to components to this library."
     }
   },
   "primaryOutputs": [