~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : NotSpecified: (No executable f...and "dotnet-ef":String) [], RemoteException
+ FullyQualifiedErrorId : NativeCommandError
</code></pre>
<h2><a name="p-38329-mise-jour-2-14-mars-2017-startupcs-2" class="anchor" href="#p-38329-mise-jour-2-14-mars-2017-startupcs-2" aria-label="Heading link"></a><strong>MISE À JOUR 2 - 14 mars 2017 - Startup.cs</strong></h2>
<pre><code class="lang-auto">using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Http;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Configuration;
using OdeToFood.Services;
using OdeToFood.Entities;
using Microsoft.AspNetCore.Routing;
using Microsoft.AspNetCore.StaticFiles;
using Microsoft.AspNetCore.Identity.EntityFrameworkCore;
namespace OdeToFood
{
public class Startup
{
public IConfiguration Configuration { get; set; }
public Startup(IHostingEnvironment env)
{
// TN - Read setting files
var builder = new ConfigurationBuilder()
.SetBasePath(env.ContentRootPath)
.AddJsonFile("appsettings.json")
.AddEnvironmentVariables();
Configuration = builder.Build();
}
// This method gets called by the runtime. Use this method to add services to the container.
// For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940
public void ConfigureServices(IServiceCollection services)
{
services.AddMvc();
services.AddSingleton(Configuration);
services.AddSingleton<IGreeter, Greeter>();
services.AddScoped<IRestaurantData, SqlRestaurantData>(); // TN - One instance of this service for each HTTP request.
services.AddDbContext<OdeToFoodDbContext>(options => options.UseSqlServer(Configuration.GetConnectionString("DefaultConnection")));
services.AddIdentity<User, IdentityRole>()
.AddEntityFrameworkStores<OdeToFoodDbContext>();
}
// 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)
{
loggerFactory.AddConsole();
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
else
{
//app.UseExceptionHandler("/error");
//app.UseExceptionHandler(new ExceptionHandlerOptions { ExceptionHandlingPath="/error" });
app.UseExceptionHandler(new ExceptionHandlerOptions
{
ExceptionHandler = context => context.Response.WriteAsync("Opps!")
});
}
//app.UseDefaultFiles();// TN - will pick index.html
//app.UseStaticFiles();
app.UseFileServer(); // TN - This will include UseDefaultFiles() and UseStaticFiles
/*
app.UseWelcomePage(new WelcomePageOptions
{
Path = "/welcome"
});
app.Run(async (context) =>
{
// TN - Read directly from configuration file
//var message = Configuration["Greeting"];
// TN - Dependency Injection - Read from configuration string via IOC
var message = greeter.GetGreeting();
await context.Response.WriteAsync(message);
});
*/
app.UseIdentity();
//app.UseMvcWithDefaultRoute();
app.UseMvc(ConfigureRoutes);
// TN - if no route matches
app.Run(ctx => ctx.Response.WriteAsync("Not found."));
}
private void ConfigureRoutes(IRouteBuilder routeBuilder)
{
//Home/Index
routeBuilder.MapRoute("Default",
"{controller=Home}/{action=Index}/{id?}");
}
}
}
</code></pre>
<p><strong>Mise à jour 3 - 14 mars 2017 - Fichier csproj ajouté</strong></p>
<pre><code class="lang-auto"><Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup Label="Globals">
<SccProjectName>SAK</SccProjectName>
<SccProvider>SAK</SccProvider>
<SccAuxPath>SAK</SccAuxPath>
<SccLocalPath>SAK</SccLocalPath>
</PropertyGroup>
<PropertyGroup>
<TargetFramework>netcoreapp1.1</TargetFramework>
<PackageTargetFallback>portable-net45+win8</PackageTargetFallback>
</PropertyGroup>
<ItemGroup>
<!--<Content Include="wwwroot\index.html" />-->
<DotNetCliToolReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Tools" Version="1.0.0" />
<DotNetCliToolReference Include="Microsoft.EntityFrameworkCore.Tools.DotNet" Version="1.0.0" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.ApplicationInsights.AspNetCore" Version="2.0.0" />
<PackageReference Include="Microsoft.AspNetCore" Version="1.1.1" />
<PackageReference Include="Microsoft.AspNetCore.Mvc" Version="1.1.2" />
<PackageReference Include="Microsoft.AspNetCore.StaticFiles" Version="1.1.1" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="1.1.1" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="1.1.1" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer.Design" Version="1.1.1" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="1.1.0" />
<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="1.1.1" />
<PackageReference Include="Microsoft.VisualStudio.Web.BrowserLink" Version="1.1.0" />
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="1.1.0" />
</ItemGroup>
<ItemGroup>
<Folder Include="Controllers\" />
<Folder Include="Data\" />
<Folder Include="Views\Home\" />
<Folder Include="wwwroot\images\" />
</ItemGroup>
</Project>
</code></pre>
<hr>
<p><em>Source : <a href="https://aka.ms/dotnet-docs." rel="noopener nofollow ugc">Stack Overflow</a></em></p>