Skip to content

Commit

Permalink
#17 - include-api option
Browse files Browse the repository at this point in the history
  • Loading branch information
albx committed May 24, 2024
1 parent 5bd8d71 commit 9c0e50d
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 18 deletions.
2 changes: 1 addition & 1 deletion BlazorSwa.Template.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<PackageType>Template</PackageType>
<PackageVersion>0.3.0</PackageVersion>
<PackageId>BlazorSwa.Template</PackageId>
Expand Down
12 changes: 4 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# BlazorSwa.Template
A project template for creating a Blazor WebAssembly app and an Azure Function api which will be hosted on Azure Static Web Apps.
A project template for creating a Blazor WebAssembly app and, optionally, an Azure Function api which will be hosted on Azure Static Web Apps.

## Requirements
.NET 6 SDK with Azure workload and Azure Functions v4 runtime must be installed.
.NET 8 SDK with Azure workload and Azure Functions v4 runtime must be installed.

## Installation
You can install the package from [NuGet](https://www.nuget.org/packages/BlazorSwa.Template/) using this command from the .NET CLI:
Expand All @@ -21,16 +21,12 @@ If you prefer Visual Studio to create the project, search *Blazor static web app

### Options
The following option is available:
- **--api Isolated/InProcess**: specifies the Azure function project type (isolated runtime or in process). The default value is **Isolated**.
- **--include-api**: specifies whether add the azure function project (isolated runtime). The default value is **false**.

### Examples
To create a Blazor WebAssembly project with an Azure Function project with isolated runtime, execute the following command from the .NET CLI:
```
dotnet new blazorswa --api Isolated -n <YourProjectName>
```
To create a Blazor WebAssembly project with an Azure Function project in process, execute the following command from the .NET CLI:
```
dotnet new blazorswa --api InProcess -n <YourProjectName>
dotnet new blazorswa --include-api -n <YourProjectName>
```

### Some tips
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"$schema": "http://json.schemastore.org/dotnetcli.host",
"$schema": "https://json.schemastore.org/dotnetcli.host",
"symbolInfo": {
"IncludeAzureFunction": {
"longName": "include-func",
"IncludeApi": {
"longName": "include-api",
"shortName": ""
}
}
Expand Down
15 changes: 9 additions & 6 deletions content/BlazorSwaTemplate/.template.config/template.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"$schema": "http://json.schemastore.org/template",
"$schema": "https://json.schemastore.org/template",
"author": "Alberto Mori",
"classifications": [ "Web", "Blazor", "WebAssembly", "Azure", "Azure Functions", "Static Web Apps" ],
"identity": "BlazorSwa.Template",
Expand Down Expand Up @@ -33,13 +33,16 @@
]
},
{
"condition": "(IncludeAzureFunction)",
"condition": "(IncludeApi)",
"rename": {
"Api.Isolated": "Api"
}
},
"exclude": [
"BlazorSwaTemplate.Client/wwwroot/sample-data/**"
]
},
{
"condition": "(!IncludeAzureFunction)",
"condition": "(!IncludeApi)",
"exclude": [
"BlazorSwaTemplate.Api.Isolated/**"
]
Expand All @@ -53,10 +56,10 @@
}
],
"symbols": {
"IncludeAzureFunction": {
"IncludeApi": {
"type": "parameter",
"datatype": "bool",
"defaultValue": "true",
"defaultValue": "false",
"displayName": "Include Azure Function backend project",
"description": "Whether to include the Azure Function backend project"
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ else

protected override async Task OnInitializedAsync()
{
@*#if (!IncludeApi)
forecasts = await Http.GetFromJsonAsync<WeatherForecast[]>("sample-data/weather.json");
##else
forecasts = await Http.GetFromJsonAsync<WeatherForecast[]>("api/WeatherForecast");
##endif*@
}
}

0 comments on commit 9c0e50d

Please sign in to comment.