Skip to content
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

update dotnet template to netcoreapp2.1, fix Index.cshtml #987

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions lib/commands/new/project-template.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,12 @@ exports.ProjectTemplate = class {
}

this.addToContent(
ProjectItem.directory('Properties').add(
ProjectItem.resource('launchSettings.json', 'content/javascriptservices/Properties/launchSettings.json').skipIfExists()
),
ProjectItem.directory('Models').add(
ProjectItem.resource('ErrorViewModel.cs', 'content/javascriptservices/Models/ErrorViewModel.cs').skipIfExists()
),
ProjectItem.directory('Controllers').add(
ProjectItem.resource('HomeController.cs', 'content/javascriptservices/Controllers/HomeController.cs').skipIfExists()
),
Expand Down Expand Up @@ -141,6 +147,7 @@ exports.ProjectTemplate = class {
this.content
),
ProjectItem.resource('appsettings.json', 'content/javascriptservices/appsettings.json').skipIfExists(),
ProjectItem.resource('appsettings.Development.json', 'content/javascriptservices/appsettings.Development.json').skipIfExists(),
ProjectItem.resource('global.json', 'content/javascriptservices/global.json').skipIfExists(),
ProjectItem.resource('webpack.netcore.config.js', 'content/javascriptservices/webpack.netcore.config.js').skipIfExists()
);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using WebApplicationBasic.Models;

namespace WebApplicationBasic.Controllers
{
Expand All @@ -13,9 +15,10 @@ public IActionResult Index()
return View();
}

[ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
public IActionResult Error()
{
return View();
return View(new ErrorViewModel { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier });
}
}
}
11 changes: 11 additions & 0 deletions lib/resources/content/javascriptservices/Models/ErrorViewModel.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
using System;

namespace WebApplicationBasic.Models
{
public class ErrorViewModel
{
public string RequestId { get; set; }

public bool ShowRequestId => !string.IsNullOrEmpty(RequestId);
}
}
9 changes: 5 additions & 4 deletions lib/resources/content/javascriptservices/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,20 @@
using System.Threading.Tasks;
using Microsoft.AspNetCore;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Logging;

namespace WebApplicationBasic
{
public class Program
{
public static void Main(string[] args)
{
BuildWebHost(args).Run();
CreateWebHostBuilder(args).Build().Run();
}

public static IWebHost BuildWebHost(string[] args) =>
public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
WebHost.CreateDefaultBuilder(args)
.UseStartup<Startup>()
.Build();
.UseStartup<Startup>();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
"iisSettings": {
"windowsAuthentication": false,
"anonymousAuthentication": true,
"iisExpress": {
"applicationUrl": "http://localhost:63439/",
"sslPort": 44330
}
},
"profiles": {
"IIS Express": {
"commandName": "IISExpress",
"launchBrowser": true,
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"project": {
"commandName": "Project",
"launchBrowser": true,
"applicationUrl": "https://localhost:5001;http://localhost:5000",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
}
}
}
14 changes: 9 additions & 5 deletions lib/resources/content/javascriptservices/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@
using System.Threading.Tasks;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.HttpsPolicy;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.SpaServices.Webpack;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;

namespace WebApplicationBasic
{
Expand All @@ -24,12 +26,12 @@ public Startup(IConfiguration configuration)
// This method gets called by the runtime. Use this method to add services to the container.
public void ConfigureServices(IServiceCollection services)
{
// Add framework services.
services.AddMvc();
// Add framework services.
services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1);
}

// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
if (env.IsDevelopment())
{
Expand All @@ -46,8 +48,10 @@ public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerF
else
{
app.UseExceptionHandler("/Home/Error");
app.UseHsts();
}

app.UseHttpsRedirection();
app.UseStaticFiles();

app.UseMvc(routes =>
Expand All @@ -56,7 +60,7 @@ public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerF
name: "default",
template: "{controller=Home}/{action=Index}/{id?}");

routes.MapSpaFallbackRoute(
routes.MapSpaFallbackRoute(
name: "spa-fallback",
defaults: new { controller = "Home", action = "Index" });
});
Expand Down
11 changes: 7 additions & 4 deletions lib/resources/content/javascriptservices/Startup.cs.readme.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
If you're not yet using ASP.NET Core 2.0 (or don't have the Microsoft.AspNetCore.All package installed) then you need to install JavascriptServices.
If you're not yet using ASP.NET Core 2.1 (or don't have the Microsoft.AspNetCore.App package installed) then you need to install JavascriptServices.
This can be done through the following command: "dotnet add package Microsoft.AspNetCore.SpaServices".

Afterwards, open the Startup.cs file and add the following "using" statement at the top of the file:
Expand All @@ -22,8 +22,10 @@ if (env.IsDevelopment())
else
{
app.UseExceptionHandler("/Home/Error");
app.UseHsts();
}

app.UseHttpsRedirection();
app.UseStaticFiles();

app.UseMvc(routes =>
Expand All @@ -42,18 +44,19 @@ Then, in the ConfigureServices method, make sure that the application uses Mvc:

public void ConfigureServices(IServiceCollection services)
{
services.AddMvc();
services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1);
}


That's it for the Startup.cs file.

If you're using Typescript then it's necessary to instruct Visual Studio not to transpile Typescript. This can be done by opening up the .csproj file.
In this .csproj file you need to specify a TypeScriptToolsVersion and TypeScriptCompileBlocked like so:

<PropertyGroup>
<TargetFramework>netcoreapp2.0</TargetFramework>
<TargetFramework>netcoreapp2.1</TargetFramework>
<TypeScriptCompileBlocked>true</TypeScriptCompileBlocked>
<TypeScriptToolsVersion>Latest</TypeScriptToolsVersion>
</PropertyGroup>

That's it for the .csproj file.
That's it for the .csproj file.
17 changes: 9 additions & 8 deletions lib/resources/content/javascriptservices/Views/Home/Index.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,16 @@
<div aurelia-app="main">Loading...</div>

@section scripts {
<environment names="Production">
<script type="text/javascript" asp-src-include="~/dist/common.*.chunk.js" asp-append-version="true"></script>
</environment>
<environment names="Development, Staging, Production">
<script type="text/javascript" asp-src-include="~/dist/vendor.*.chunk.js" asp-append-version="true"></script>
</environment>
<environment names="Development">
<script type="text/javascript" src="~/dist/vendor.bundle.js" asp-append-version="true"></script>
<script type="text/javascript" src="~/dist/app.bundle.js" asp-append-version="true"></script>
</environment>
<environment names="Production">
<script type="text/javascript" asp-src-include="~/dist/common.*.bundle.js" asp-append-version="true"></script>
</environment>
<environment names="Staging, Production">
<script type="text/javascript" asp-src-include="~/dist/vendor.*.bundle.js" asp-append-version="true"></script>
</environment>
<environment names="Staging, Production">
<script type="text/javascript" asp-src-include="~/dist/app.*.bundle.js" asp-append-version="true"></script>
</environment>
</environment>
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,18 @@ Take a look at Views/Home/Index.cshtml and make sure that it contains the follow
<div aurelia-app="main">Loading...</div>

@section scripts {
<environment names="Production">
<script type="text/javascript" asp-src-include="~/dist/common.*.chunk.js" asp-append-version="true"></script>
</environment>
<environment names="Development, Staging, Production">
<script type="text/javascript" asp-src-include="~/dist/vendor.*.chunk.js" asp-append-version="true"></script>
</environment>
<environment names="Development">
<script type="text/javascript" src="~/dist/vendor.bundle.js" asp-append-version="true"></script>
<script type="text/javascript" src="~/dist/app.bundle.js" asp-append-version="true"></script>
</environment>
<environment names="Production">
<script type="text/javascript" asp-src-include="~/dist/common.*.bundle.js" asp-append-version="true"></script>
</environment>
<environment names="Staging, Production">
<script type="text/javascript" asp-src-include="~/dist/vendor.*.bundle.js" asp-append-version="true"></script>
</environment>
<environment names="Staging, Production">
<script type="text/javascript" asp-src-include="~/dist/app.*.bundle.js" asp-append-version="true"></script>
</environment>
</environment>
}

That's it for Index.cshtml
That's it for Index.cshtml
16 changes: 16 additions & 0 deletions lib/resources/content/javascriptservices/Views/Shared/Error.cshtml
Original file line number Diff line number Diff line change
@@ -1,6 +1,22 @@
@model ErrorViewModel
@{
ViewData["Title"] = "Error";
}

<h1 class="text-danger">Error.</h1>
<h2 class="text-danger">An error occurred while processing your request.</h2>

@if (Model.ShowRequestId)
{
<p>
<strong>Request ID:</strong> <code>@Model.RequestId</code>
</p>
}

<h3>Development Mode</h3>
<p>
Swapping to <strong>Development</strong> environment will display more detailed information about the error that occurred.
</p>
<p>
<strong>Development environment should not be enabled in deployed applications</strong>, as it can result in sensitive information from exceptions being displayed to end users. For local debugging, development environment can be enabled by setting the <strong>ASPNETCORE_ENVIRONMENT</strong> environment variable to <strong>Development</strong>, and restarting the application.
</p>
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
@using WebApplicationBasic
@using WebApplicationBasic.Models
@addTagHelper "*, Microsoft.AspNetCore.Mvc.TagHelpers"
@addTagHelper "*, Microsoft.AspNetCore.SpaServices"
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"Logging": {
"LogLevel": {
"Default": "Debug",
"System": "Information",
"Microsoft": "Information"
}
}
}
8 changes: 3 additions & 5 deletions lib/resources/content/javascriptservices/appsettings.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
{
"Logging": {
"IncludeScopes": false,
"LogLevel": {
"Default": "Debug",
"System": "Information",
"Microsoft": "Information"
"Default": "Warning"
}
}
},
"AllowedHosts": "*"
}
2 changes: 1 addition & 1 deletion lib/resources/content/javascriptservices/global.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"sdk": { "version": "2.0.0" }
"sdk": { "version": "2.1.500" }
}
9 changes: 3 additions & 6 deletions lib/resources/content/javascriptservices/project.csproject
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>netcoreapp2.0</TargetFramework>
<TargetFramework>netcoreapp2.1</TargetFramework>
<TypeScriptCompileBlocked>true</TypeScriptCompileBlocked>
<TypeScriptToolsVersion>Latest</TypeScriptToolsVersion>
<IsPackable>false</IsPackable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.All" Version="2.0.0" />
<PackageReference Include="Microsoft.AspNetCore.SpaServices" Version="2.0.0" />
<PackageReference Include="Microsoft.AspNetCore.App" />
<PackageReference Include="Microsoft.AspNetCore.Razor.Design" Version="2.1.2" PrivateAssets="All" />
</ItemGroup>
<ItemGroup>
<!-- Files not to show in IDE -->
Expand All @@ -16,9 +16,6 @@
<ItemGroup>
<Folder Include="wwwroot\" />
</ItemGroup>
<ItemGroup>
<DotNetCliToolReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Tools" Version="2.0.0" />
</ItemGroup>
<Target Name="PublishRunWebpack" AfterTargets="ComputeFilesToPublish">
<!-- As part of publishing, ensure the JS resources are freshly built in production mode -->
<Exec Command="npm install" />
Expand Down