From d223a5e05cbad407eb6b595cb85680a560701528 Mon Sep 17 00:00:00 2001 From: Sai Manoj Kumar Yadlapati Date: Sat, 3 Jun 2017 19:48:36 +0530 Subject: [PATCH] Migrating to csproj from xproj, Fixing connection string in Prod --- WakeYourPcWebApp.sln | 22 +++++ WebApp.sln | 31 ------- global.json | 7 +- src/WakeYourPcWebApp/Models/WakeupContext.cs | 10 ++- src/WakeYourPcWebApp/Startup.cs | 16 ++-- src/WakeYourPcWebApp/WakeYourPcWebApp.csproj | 52 ++++++++++++ src/WakeYourPcWebApp/WakeYourPcWebApp.xproj | 25 ------ .../appsettings.Development.json | 5 ++ src/WakeYourPcWebApp/appsettings.json | 4 + src/WakeYourPcWebApp/config.json | 9 --- src/WakeYourPcWebApp/project.json | 81 ------------------- src/WakeYourPcWebApp/web.config | 4 +- 12 files changed, 105 insertions(+), 161 deletions(-) create mode 100644 WakeYourPcWebApp.sln delete mode 100644 WebApp.sln create mode 100644 src/WakeYourPcWebApp/WakeYourPcWebApp.csproj delete mode 100644 src/WakeYourPcWebApp/WakeYourPcWebApp.xproj create mode 100644 src/WakeYourPcWebApp/appsettings.Development.json create mode 100644 src/WakeYourPcWebApp/appsettings.json delete mode 100644 src/WakeYourPcWebApp/config.json delete mode 100644 src/WakeYourPcWebApp/project.json diff --git a/WakeYourPcWebApp.sln b/WakeYourPcWebApp.sln new file mode 100644 index 0000000..269c299 --- /dev/null +++ b/WakeYourPcWebApp.sln @@ -0,0 +1,22 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio 15 +VisualStudioVersion = 15.0.26403.7 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "WakeYourPcWebApp", "src\WakeYourPcWebApp\WakeYourPcWebApp.csproj", "{69153DAD-655F-4E43-9B29-17FC3DFDB083}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {69153DAD-655F-4E43-9B29-17FC3DFDB083}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {69153DAD-655F-4E43-9B29-17FC3DFDB083}.Debug|Any CPU.Build.0 = Debug|Any CPU + {69153DAD-655F-4E43-9B29-17FC3DFDB083}.Release|Any CPU.ActiveCfg = Release|Any CPU + {69153DAD-655F-4E43-9B29-17FC3DFDB083}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal diff --git a/WebApp.sln b/WebApp.sln deleted file mode 100644 index 4468c8a..0000000 --- a/WebApp.sln +++ /dev/null @@ -1,31 +0,0 @@ -Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio 14 -VisualStudioVersion = 14.0.25420.1 -MinimumVisualStudioVersion = 10.0.40219.1 -Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{775C5B72-BE70-4876-AD5E-66D0A63CD1A3}" -EndProject -Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{681D2F97-C287-4E52-91D5-9F27F9CDB9F0}" - ProjectSection(SolutionItems) = preProject - global.json = global.json - EndProjectSection -EndProject -Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "WakeYourPcWebApp", "src\WakeYourPcWebApp\WakeYourPcWebApp.xproj", "{3FD65277-3577-4ADF-BF83-05A471BE901C}" -EndProject -Global - GlobalSection(SolutionConfigurationPlatforms) = preSolution - Debug|Any CPU = Debug|Any CPU - Release|Any CPU = Release|Any CPU - EndGlobalSection - GlobalSection(ProjectConfigurationPlatforms) = postSolution - {3FD65277-3577-4ADF-BF83-05A471BE901C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {3FD65277-3577-4ADF-BF83-05A471BE901C}.Debug|Any CPU.Build.0 = Debug|Any CPU - {3FD65277-3577-4ADF-BF83-05A471BE901C}.Release|Any CPU.ActiveCfg = Release|Any CPU - {3FD65277-3577-4ADF-BF83-05A471BE901C}.Release|Any CPU.Build.0 = Release|Any CPU - EndGlobalSection - GlobalSection(SolutionProperties) = preSolution - HideSolutionNode = FALSE - EndGlobalSection - GlobalSection(NestedProjects) = preSolution - {3FD65277-3577-4ADF-BF83-05A471BE901C} = {775C5B72-BE70-4876-AD5E-66D0A63CD1A3} - EndGlobalSection -EndGlobal diff --git a/global.json b/global.json index 9d09ab5..31a5f7f 100644 --- a/global.json +++ b/global.json @@ -1,6 +1 @@ -{ - "projects": [ "src", "test" ], - "sdk": { - "version": "1.0.0-preview2-003131" - } -} +{"projects":["src","test"]} \ No newline at end of file diff --git a/src/WakeYourPcWebApp/Models/WakeupContext.cs b/src/WakeYourPcWebApp/Models/WakeupContext.cs index 1921e10..cf8beab 100644 --- a/src/WakeYourPcWebApp/Models/WakeupContext.cs +++ b/src/WakeYourPcWebApp/Models/WakeupContext.cs @@ -5,17 +5,22 @@ using System.Text; using System.Threading.Tasks; using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.Configuration; +using Microsoft.Extensions.Logging; namespace WakeYourPcWebApp.Models { public class WakeupContext : DbContext { private readonly IConfigurationRoot _configuration; + private ILogger _logger; - public WakeupContext(IConfigurationRoot configuration, DbContextOptions dbContextOptions) + public WakeupContext(IConfigurationRoot configuration, + DbContextOptions dbContextOptions, + ILogger logger) : base(dbContextOptions) { _configuration = configuration; + _logger = logger; } public DbSet Users { get; set; } @@ -25,7 +30,8 @@ namespace WakeYourPcWebApp.Models protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) { base.OnConfiguring(optionsBuilder); - optionsBuilder.UseSqlServer(_configuration["Data:connectionStrings:DefaultConnection"]); + var connString = _configuration["ConnectionStrings:DefaultConnection"]; + optionsBuilder.UseSqlServer(connString); } } } diff --git a/src/WakeYourPcWebApp/Startup.cs b/src/WakeYourPcWebApp/Startup.cs index 20363c8..eac2bd3 100644 --- a/src/WakeYourPcWebApp/Startup.cs +++ b/src/WakeYourPcWebApp/Startup.cs @@ -30,7 +30,8 @@ namespace WakeYourPcWebApp var builder = new ConfigurationBuilder() .SetBasePath(_env.ContentRootPath) - .AddJsonFile("config.json") + .AddJsonFile("appsettings.json", optional: false, reloadOnChange: true) + .AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: false) .AddEnvironmentVariables(); _config = builder.Build(); @@ -59,7 +60,7 @@ namespace WakeYourPcWebApp // This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, ILoggerFactory loggerFactory, - IHostingEnvironment env, + IHostingEnvironment env, WakeupContextSeedData seeder, WakeupContext context) { @@ -69,12 +70,16 @@ namespace WakeYourPcWebApp config.CreateMap().ReverseMap(); }); - - //if (env.IsDevelopment()) + if (env.IsDevelopment()) { - loggerFactory.AddDebug(); + loggerFactory.AddDebug(LogLevel.Information); + loggerFactory.AddConsole(LogLevel.Information); app.UseDeveloperExceptionPage(); } + else + { + loggerFactory.AddDebug(LogLevel.Error); + } app.UseStaticFiles(); @@ -95,7 +100,6 @@ namespace WakeYourPcWebApp }); context.Database.Migrate(); - seeder.EnsureSeedData().Wait(); } diff --git a/src/WakeYourPcWebApp/WakeYourPcWebApp.csproj b/src/WakeYourPcWebApp/WakeYourPcWebApp.csproj new file mode 100644 index 0000000..d5db3de --- /dev/null +++ b/src/WakeYourPcWebApp/WakeYourPcWebApp.csproj @@ -0,0 +1,52 @@ + + + netcoreapp1.1 + true + WakeYourPcWebApp + Exe + WakeYourPcWebApp + 1.0.4 + $(PackageTargetFallback);dotnet5.6;portable-net45+win8 + False + + + + + + + + + + + PreserveNewest + + + + + + + + + + + + + + + + + + All + + + All + + + + + + + + + + diff --git a/src/WakeYourPcWebApp/WakeYourPcWebApp.xproj b/src/WakeYourPcWebApp/WakeYourPcWebApp.xproj deleted file mode 100644 index 5f9af3b..0000000 --- a/src/WakeYourPcWebApp/WakeYourPcWebApp.xproj +++ /dev/null @@ -1,25 +0,0 @@ - - - - 14.0 - $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion) - - - - - 3fd65277-3577-4adf-bf83-05a471be901c - WakeYourPcWebApp - .\obj - .\bin\ - v4.5.2 - - - - 2.0 - - - - - - - diff --git a/src/WakeYourPcWebApp/appsettings.Development.json b/src/WakeYourPcWebApp/appsettings.Development.json new file mode 100644 index 0000000..a1f210d --- /dev/null +++ b/src/WakeYourPcWebApp/appsettings.Development.json @@ -0,0 +1,5 @@ +{ + "ConnectionStrings": { + "DefaultConnection": "Server=(localdb)\\MSSQLLocalDB;Database=WakeupDb;Trusted_Connection=true;MultipleActiveResultSets=true;" + } +} diff --git a/src/WakeYourPcWebApp/appsettings.json b/src/WakeYourPcWebApp/appsettings.json new file mode 100644 index 0000000..c10c297 --- /dev/null +++ b/src/WakeYourPcWebApp/appsettings.json @@ -0,0 +1,4 @@ +{ + "Data": { + } +} diff --git a/src/WakeYourPcWebApp/config.json b/src/WakeYourPcWebApp/config.json deleted file mode 100644 index 8ba3457..0000000 --- a/src/WakeYourPcWebApp/config.json +++ /dev/null @@ -1,9 +0,0 @@ -{ - "Data": { - "connectionStrings": { - "defaultConnection": "Server=(localdb)\\MSSQLLocalDB;Database=WakeupDb;Trusted_Connection=true;MultipleActiveResultSets=true;" - } - - }, - "Password": "Temp Password" -} \ No newline at end of file diff --git a/src/WakeYourPcWebApp/project.json b/src/WakeYourPcWebApp/project.json deleted file mode 100644 index c8ec67a..0000000 --- a/src/WakeYourPcWebApp/project.json +++ /dev/null @@ -1,81 +0,0 @@ -{ - "dependencies": { - "Microsoft.NETCore.App": { - "version": "1.0.1", - "type": "platform" - }, - "Microsoft.AspNetCore.Diagnostics": "1.0.0", - "Microsoft.AspNetCore.Server.IISIntegration": "1.0.0", - "Microsoft.AspNetCore.Server.IISIntegration.Tools": "1.0.0-preview2-final", - "Microsoft.AspNetCore.Server.Kestrel": "1.0.1", - "Microsoft.Extensions.Logging.Console": "1.0.0", - "Microsoft.AspNetCore.StaticFiles": "1.0.0", - "Microsoft.AspNetCore.Mvc": "1.0.1", - "Microsoft.AspNetCore.Mvc.TagHelpers": "1.0.1", - "Microsoft.EntityFrameworkCore": "1.0.1", - "Microsoft.Extensions.Configuration.FileExtensions": "1.0.0", - "Microsoft.Extensions.Configuration.Json": "1.0.0", - "Microsoft.EntityFrameworkCore.SqlServer": "1.0.1", - "Microsoft.EntityFrameworkCore.Tools": { - "version": "1.0.0-preview3-final", - "type": "build" - }, - "Microsoft.EntityFrameworkCore.Tools.DotNet": { - "version": "1.0.0-preview3-final", - "type": "build" - }, - "Microsoft.EntityFrameworkCore.Design": "1.0.1", - "AutoMapper": "5.2.0", - "Microsoft.Extensions.Logging.Debug": "1.1.1" - }, - - "tools": { - "Microsoft.AspNetCore.Server.IISIntegration.Tools": "1.0.0-preview2-final", - "Microsoft.EntityFrameworkCore.Tools": { - "version": "1.0.0-preview3-final", - "imports": [ - "portable-net45+win8+dnxcore50", - "portable-net45+win8" - ] - }, - "Microsoft.EntityFrameworkCore.Tools.DotNet": { - "version": "1.0.0-preview3-final", - "imports": [ - "portable-net45+win8+dnxcore50", - "portable-net45+win8" - ] - } - }, - - "frameworks": { - "netcoreapp1.0": { - "imports": [ - "dotnet5.6", - "portable-net45+win8" - ] - } - }, - - "buildOptions": { - "emitEntryPoint": true, - "preserveCompilationContext": true - }, - - "runtimeOptions": { - "configProperties": { - "System.GC.Server": true - } - }, - - "publishOptions": { - "include": [ - "wwwroot", - "web.config" - ] - }, - - "scripts": { - "prepublish": [ "npm install", "bower install" ], - "postpublish": [ "dotnet publish-iis --publish-folder %publish:OutputPath% --framework %publish:FullTargetFramework%" ] - } - } diff --git a/src/WakeYourPcWebApp/web.config b/src/WakeYourPcWebApp/web.config index a23b656..86d30a8 100644 --- a/src/WakeYourPcWebApp/web.config +++ b/src/WakeYourPcWebApp/web.config @@ -7,6 +7,8 @@ - + +