Merge pull request #25 from d-barker/master

Migrate MVC project to netcoreapp3.1
This commit is contained in:
Alexandre SPIESER
2020-01-27 21:15:14 +00:00
committed by GitHub
16 changed files with 346 additions and 65 deletions
+3 -1
View File
@@ -296,4 +296,6 @@ __pycache__/
*.btp.cs
*.btm.cs
*.odx.cs
*.xsd.cs
*.xsd.cs
sample/MongoIdentitySample.Mvc/appsettings.local.json
test/AspNetCore.Identity.MongoDbCore.IntegrationTests/appsettings.local.json
+34
View File
@@ -0,0 +1,34 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": ".NET Core Launch (web)",
"type": "coreclr",
"request": "launch",
"preLaunchTask": "build",
"program": "${workspaceFolder}/sample/MongoIdentitySample.Mvc/bin/Debug/netcoreapp3.1/MongoIdentitySample.Mvc.dll",
"args": [],
"cwd": "${workspaceFolder}/sample/MongoIdentitySample.Mvc",
"stopAtEntry": false,
"serverReadyAction": {
"action": "openExternally",
"pattern": "^\\s*Now listening on:\\s+(https?://\\S+)"
},
"env": {
"ASPNETCORE_ENVIRONMENT": "Development"
},
"sourceFileMap": {
"/Views": "${workspaceFolder}/Views"
}
},
{
"name": ".NET Core Attach",
"type": "coreclr",
"request": "attach",
"processId": "${command:pickProcess}"
}
]
}
+42
View File
@@ -0,0 +1,42 @@
{
"version": "2.0.0",
"tasks": [
{
"label": "build",
"command": "dotnet",
"type": "process",
"args": [
"build",
"${workspaceFolder}/sample/MongoIdentitySample.Mvc/MongoIdentitySample.Mvc.csproj",
"/property:GenerateFullPaths=true",
"/consoleloggerparameters:NoSummary"
],
"problemMatcher": "$msCompile"
},
{
"label": "publish",
"command": "dotnet",
"type": "process",
"args": [
"publish",
"${workspaceFolder}/sample/MongoIdentitySample.Mvc/MongoIdentitySample.Mvc.csproj",
"/property:GenerateFullPaths=true",
"/consoleloggerparameters:NoSummary"
],
"problemMatcher": "$msCompile"
},
{
"label": "watch",
"command": "dotnet",
"type": "process",
"args": [
"watch",
"run",
"${workspaceFolder}/sample/MongoIdentitySample.Mvc/MongoIdentitySample.Mvc.csproj",
"/property:GenerateFullPaths=true",
"/consoleloggerparameters:NoSummary"
],
"problemMatcher": "$msCompile"
}
]
}
+58
View File
@@ -0,0 +1,58 @@
trigger:
- master
pool:
vmImage: 'ubuntu-latest'
variables:
solution: '**/*.sln'
buildPlatform: 'Any CPU'
buildConfiguration: 'Release'
steps:
- task: UseDotNet@2
displayName: 'Install .net core 3.1'
inputs:
packageType: 'sdk'
version: '3.1.101'
- task: NuGetToolInstaller@1
- task: NuGetCommand@2
displayName: 'Restore Library Dependencies'
inputs:
restoreSolution: '$(solution)'
- task: DotNetCoreCLI@2
displayName: 'Build Library'
inputs:
command: 'build'
projects: './src/AspNetCore.Identity.MongoDbCore.csproj'
arguments: '--configuration $(buildConfiguration)'
# - task: DotNetCoreCLI@2
# displayName: 'Test Library'
# inputs:
# command: 'test'
# projects: './test/AspNetCore.Identity.MongoDbCore.IntegrationTests/AspNetCore.Identity.MongoDbCore.IntegrationTests.csproj'
# arguments: '--configuration $(buildConfiguration)'
- task: DotNetCoreCLI@2
displayName: 'Package Library (nuget)'
inputs:
command: 'custom'
projects: './src/AspNetCore.Identity.MongoDbCore.csproj'
custom: 'pack'
arguments: '--no-build -p:NuspecFile=AspNetCore.Identity.MongoDbCore.nuspec -o $(build.artifactStagingDirectory)/Nuget'
verbosityPack: 'Detailed'
- task: NuGetCommand@2
displayName: 'Publish Library'
inputs:
command: 'push'
packagesToPush: '$(Build.ArtifactStagingDirectory)/**/*.nupkg;!$(Build.ArtifactStagingDirectory)/**/*.symbols.nupkg'
nuGetFeedType: 'internal'
publishVstsFeed: '72ef5435-c019-4338-8d35-7c3caec78f2a'
verbosityPush: 'Normal'
+10
View File
@@ -0,0 +1,10 @@
$project="./src/AspNetCore.Identity.MongoDbCore.csproj"
$testProject="./test/AspNetCore.Identity.MongoDbCore.IntegrationTests/AspNetCore.Identity.MongoDbCore.IntegrationTests.csproj"
$configuration="Release"
$nuspecFile="AspnetCore.Identity.MongoDbCore.nuspec"
$output="./nuget"
dotnet build
dotnet test $testProject
dotnet pack --no-restore --no-build $project --configuration $configuration -p:NuspecFile=$nuspecFile -o $output
+36
View File
@@ -0,0 +1,36 @@
{
// Use IntelliSense to find out which attributes exist for C# debugging
// Use hover for the description of the existing attributes
// For further information visit https://github.com/OmniSharp/omnisharp-vscode/blob/master/debugger-launchjson.md
"version": "0.2.0",
"configurations": [
{
"name": ".NET Core Launch (web)",
"type": "coreclr",
"request": "launch",
"preLaunchTask": "build",
// If you have changed target frameworks, make sure to update the program path.
"program": "${workspaceFolder}/bin/Debug/netcoreapp3.1/MongoIdentitySample.Mvc.dll",
"args": [],
"cwd": "${workspaceFolder}",
"stopAtEntry": false,
// Enable launching a web browser when ASP.NET Core starts. For more information: https://aka.ms/VSCode-CS-LaunchJson-WebBrowser
"serverReadyAction": {
"action": "openExternally",
"pattern": "^\\s*Now listening on:\\s+(https?://\\S+)"
},
"env": {
"ASPNETCORE_ENVIRONMENT": "Development"
},
"sourceFileMap": {
"/Views": "${workspaceFolder}/Views"
}
},
{
"name": ".NET Core Attach",
"type": "coreclr",
"request": "attach",
"processId": "${command:pickProcess}"
}
]
}
+42
View File
@@ -0,0 +1,42 @@
{
"version": "2.0.0",
"tasks": [
{
"label": "build",
"command": "dotnet",
"type": "process",
"args": [
"build",
"${workspaceFolder}/MongoIdentitySample.Mvc.csproj",
"/property:GenerateFullPaths=true",
"/consoleloggerparameters:NoSummary"
],
"problemMatcher": "$msCompile"
},
{
"label": "publish",
"command": "dotnet",
"type": "process",
"args": [
"publish",
"${workspaceFolder}/MongoIdentitySample.Mvc.csproj",
"/property:GenerateFullPaths=true",
"/consoleloggerparameters:NoSummary"
],
"problemMatcher": "$msCompile"
},
{
"label": "watch",
"command": "dotnet",
"type": "process",
"args": [
"watch",
"run",
"${workspaceFolder}/MongoIdentitySample.Mvc.csproj",
"/property:GenerateFullPaths=true",
"/consoleloggerparameters:NoSummary"
],
"problemMatcher": "$msCompile"
}
]
}
@@ -9,20 +9,18 @@
<ItemGroup>
<PackageReference Include="Microsoft.ApplicationInsights.AspNetCore" Version="2.13.0-beta1" />
<PackageReference Include="Microsoft.AspNetCore" Version="2.2.0" />
<PackageReference Include="Microsoft.AspNetCore.Identity" Version="2.2.0" />
<PackageReference Include="Microsoft.Extensions.Hosting" Version="3.1.1" />
<PackageReference Include="Microsoft.Extensions.Configuration" Version="3.1.1" />
<PackageReference Include="Microsoft.Extensions.Hosting" Version="3.1.1" />
<PackageReference Include="Microsoft.Extensions.Identity.Stores" Version="3.1.1" />
<PackageReference Include="Microsoft.Extensions.Identity.Core" Version="3.1.1" />
<PackageReference Include="Microsoft.AspNetCore.Authentication" Version="2.2.0" />
<PackageReference Include="Microsoft.AspNetCore.Authentication.Cookies" Version="2.2.0" />
<PackageReference Include="Microsoft.AspNetCore.Mvc" Version="2.2.0" />
<PackageReference Include="Microsoft.AspNetCore.StaticFiles" Version="2.2.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.UserSecrets" Version="3.1.1" />
<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="3.1.1" />
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="3.1.0" PrivateAssets="All" />
<PackageReference Include="Microsoft.VisualStudio.Web.BrowserLink" Version="2.2.0" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.NewtonsoftJson" Version="3.1.0" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.Razor.RuntimeCompilation" Version="3.1.0" Condition="'$(Configuration)' == 'Debug'" />
</ItemGroup>
<ItemGroup>
+9 -8
View File
@@ -1,5 +1,6 @@
using System.IO;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Hosting;
namespace MongoIdentitySample.Mvc
{
@@ -7,14 +8,14 @@ namespace MongoIdentitySample.Mvc
{
public static void Main(string[] args)
{
var host = new WebHostBuilder()
.UseKestrel()
.UseContentRoot(Directory.GetCurrentDirectory())
.UseIISIntegration()
.UseStartup<Startup>()
.Build();
host.Run();
CreateHostBuilder(args).Build().Run();
}
protected static IHostBuilder CreateHostBuilder(string[] args) =>
Host.CreateDefaultBuilder(args)
.ConfigureWebHostDefaults(webBuilder =>
{
webBuilder.UseStartup<Startup>();
});
}
}
+20 -11
View File
@@ -8,19 +8,23 @@ using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using MongoIdentitySample.Mvc.Models;
using MongoIdentitySample.Mvc.Services;
using System;
using Microsoft.Extensions.Logging;
using System;
namespace MongoIdentitySample.Mvc
{
public class Startup
{
const string DevEnvironmentName = "Development";
private IWebHostEnvironment _env;
public Startup(IWebHostEnvironment env)
{
_env = env;
var builder = new ConfigurationBuilder()
.AddJsonFile("appsettings.json", optional: true, reloadOnChange: true)
.AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: true);
.SetBasePath(env.ContentRootPath)
.AddJsonFile("appsettings.json", optional: false, reloadOnChange: true)
.AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: true)
//per user config that is not committed to repo, use this to override settings (e.g. connection string) based on your local environment.
.AddJsonFile($"appsettings.local.json", optional: true);
builder.AddEnvironmentVariables();
Configuration = builder.Build();
@@ -36,20 +40,25 @@ namespace MongoIdentitySample.Mvc
var settings = Configuration.GetSection(nameof(MongoDbSettings)).Get<MongoDbSettings>();
services.AddSingleton<MongoDbSettings>(settings);
services.AddIdentity<ApplicationUser, MongoIdentityRole>()
.AddMongoDbStores<ApplicationUser, MongoIdentityRole, Guid>(settings.ConnectionString, settings.DatabaseName)
.AddSignInManager()
.AddDefaultTokenProviders();
var builder = services.AddRazorPages();
#if DEBUG
if(_env.IsDevelopment())
{
builder.AddRazorRuntimeCompilation();
}
#endif
services.AddMvc();
//services.AddAuthentication(o =>
//{
// o.DefaultScheme = IdentityConstants.ApplicationScheme;
// o.DefaultSignInScheme = IdentityConstants.ExternalScheme;
//})
//.AddIdentityCookies(o => { });
services.AddApplicationInsightsTelemetry();
// Add application services.
services.AddTransient<IEmailSender, AuthMessageSender>();
@@ -31,7 +31,7 @@
@RenderBody()
<hr />
<footer>
<p>&copy; 2016 - IdentitySample</p>
<p>&copy; 2020 - IdentitySample</p>
</footer>
</div>
@@ -1,9 +1,6 @@
// Configure bundling and minification for the project.
// More info at https://go.microsoft.com/fwlink/?LinkId=808241
[
{
[
{
"outputFileName": "wwwroot/css/site.min.css",
// An array of relative input file paths. Globbing patterns supported
"inputFiles": [
"wwwroot/css/site.css"
]
@@ -13,12 +10,10 @@
"inputFiles": [
"wwwroot/js/site.js"
],
// Optionally specify minification options
"minify": {
"enabled": true,
"renameLocals": true
},
// Optionally generate .map file
"sourceMap": false
}
]
+15 -7
View File
@@ -2,11 +2,11 @@
<package >
<metadata>
<id>AspNetCore.Identity.MongoDbCore</id>
<version>1.1.1</version>
<version>2.1.0</version>
<title>AspNetCore.Identity.MongoDbCore</title>
<authors>Alexandre Spieser</authors>
<owners>Alexandre Spieser</owners>
<licenseUrl>http://www.opensource.org/licenses/mit-license.php</licenseUrl>
<license type="expression">MIT</license>
<projectUrl>https://github.com/alexandre-spieser/AspNetCore.Identity.MongoDbCore</projectUrl>
<requireLicenseAcceptance>false</requireLicenseAcceptance>
<description>A MongoDb UserStore and RoleStore adapter for Microsoft.AspNetCore.Identity 2.0.</description>
@@ -14,13 +14,21 @@
<copyright>Copyright 2018 (c) Alexandre Spieser. All rights reserved.</copyright>
<tags>aspnetcore mongo mongodb identity membership</tags>
<dependencies>
<dependency id="Microsoft.AspNetCore.Identity" version="2.2.0" />
<dependency id="Microsoft.Extensions.Identity.Stores" version="2.2.0" />
<dependency id="MongoDB.Driver" version="2.7.0" />
<dependency id="MongoDbGenericRepository" version="1.4.0" />
<group targetFramework="netstandard2.1">
<dependency id="Microsoft.AspNetCore.Identity" version="[2.2,3)" />
<dependency id="Microsoft.Extensions.Identity.Stores" version="[3.1,4)" />
<dependency id="MongoDB.Driver" version="[2.10,3)" />
<dependency id="MongoDbGenericRepository" version="[1.4,2)" />
</group>
<group targetFramework="netcoreapp3.1">
<dependency id="Microsoft.AspNetCore.Identity" version="[2.2,3)" />
<dependency id="Microsoft.Extensions.Identity.Stores" version="[3.1,4)" />
<dependency id="MongoDB.Driver" version="[2.10,3)" />
<dependency id="MongoDbGenericRepository" version="[1.4,2)" />
</group>
</dependencies>
</metadata>
<files>
<file src="lib\**" target="lib" />
<file src="bin\Release\**\*" exclude="*.pdb" target="lib" />
</files>
</package>
@@ -33,4 +33,9 @@
<ProjectReference Include="..\..\src\AspNetCore.Identity.MongoDbCore.csproj" />
</ItemGroup>
<ItemGroup>
<Content Include="appsettings*.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
</ItemGroup>
</Project>
@@ -1,5 +1,6 @@
using AspNetCore.Identity.MongoDbCore.Extensions;
using AspNetCore.Identity.MongoDbCore.Infrastructure;
using Microsoft.Extensions.Configuration;
using System;
namespace AspNetCore.Identity.MongoDbCore.IntegrationTests.Infrastructure
@@ -12,22 +13,47 @@ namespace AspNetCore.Identity.MongoDbCore.IntegrationTests.Infrastructure
public static class Container
{
public static MongoDbIdentityConfiguration MongoDbIdentityConfiguration = new MongoDbIdentityConfiguration
public static IConfiguration Configuration { get; set; }
static Container()
{
MongoDbSettings = new MongoDbSettings
var builder = new ConfigurationBuilder()
.SetBasePath(System.Environment.CurrentDirectory)
.AddJsonFile("appsettings.json", optional: false, reloadOnChange: true)
//per user config that is not committed to repo, use this to override settings (e.g. connection string) based on your local environment.
.AddJsonFile($"appsettings.local.json", optional: true);
builder.AddEnvironmentVariables();
Configuration = builder.Build();
var databaseSettings = Configuration.Load<MongoDbSettings>("MongoDbSettings");
MongoDbIdentityConfiguration = new MongoDbIdentityConfiguration()
{
ConnectionString = "mongodb://localhost:27017",
DatabaseName = "MongoDbTests"
},
IdentityOptionsAction = options =>
MongoDbSettings = databaseSettings,
IdentityOptionsAction = (options) =>
{
options.Password.RequireDigit = false;
options.Password.RequireLowercase = false;
options.Password.RequireNonAlphanumeric = false;
options.Password.RequireUppercase = false;
options.User.AllowedUserNameCharacters = null;
}
};
lock (Locks.MongoInitLock)
{
options.Password.RequireDigit = false;
options.Password.RequireLowercase = false;
options.Password.RequireNonAlphanumeric = false;
options.Password.RequireUppercase = false;
options.User.AllowedUserNameCharacters = null;
_mongoDbRepository = new MongoRepository(
databaseSettings.ConnectionString,
databaseSettings.DatabaseName);
_mongoDbRepository2 = new MongoRepository(
databaseSettings.ConnectionString,
databaseSettings.DatabaseName);
}
};
}
public static MongoDbIdentityConfiguration MongoDbIdentityConfiguration { get; set; }
public static IServiceProvider Instance { get; set; }
@@ -36,19 +62,6 @@ namespace AspNetCore.Identity.MongoDbCore.IntegrationTests.Infrastructure
private static readonly IMongoRepository _mongoDbRepository2;
static Container()
{
lock (Locks.MongoInitLock)
{
_mongoDbRepository = new MongoRepository(
MongoDbIdentityConfiguration.MongoDbSettings.ConnectionString,
MongoDbIdentityConfiguration.MongoDbSettings.DatabaseName);
_mongoDbRepository2 = new MongoRepository(
MongoDbIdentityConfiguration.MongoDbSettings.ConnectionString,
MongoDbIdentityConfiguration.MongoDbSettings.DatabaseName);
}
}
public static IMongoRepository MongoRepository
{
get
@@ -65,4 +78,20 @@ namespace AspNetCore.Identity.MongoDbCore.IntegrationTests.Infrastructure
}
}
}
public static class ConfigurationExtensions
{
public static T Load<T>(this IConfiguration configuration, string key) where T : new()
{
var instance = new T();
configuration.GetSection(key).Bind(instance);
return instance;
}
public static T Load<T>(this IConfiguration configuration, string key, T instance) where T : new()
{
configuration.GetSection(key).Bind(instance);
return instance;
}
}
}
@@ -0,0 +1,12 @@
{
"MongoDbSettings": {
"ConnectionString": "mongodb://localhost:27017",
"DatabaseName": "MongoDbTests"
},
"Logging": {
"IncludeScopes": false,
"LogLevel": {
"Default": "Warning"
}
}
}