Skip to content

Commit

Permalink
Updating to .NET Core 3.1
Browse files Browse the repository at this point in the history
Remove "PhysicalPath" from embedded file provider.
  • Loading branch information
pauldotknopf committed Dec 28, 2019
1 parent 8da9b30 commit 331fae9
Show file tree
Hide file tree
Showing 24 changed files with 72 additions and 92 deletions.
2 changes: 1 addition & 1 deletion examples/Statik.Examples.Mvc/Statik.Examples.Mvc.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp2.1</TargetFramework>
<TargetFramework>netcoreapp3.1</TargetFramework>
<LangVersion>7.1</LangVersion>
</PropertyGroup>
<ItemGroup>
Expand Down
3 changes: 0 additions & 3 deletions examples/Statik.Examples.Pages/Program.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
using System;
using System.IO;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.FileProviders;
using Newtonsoft.Json;
using Statik.Mvc;
using Statik.Pages;

Expand Down
13 changes: 6 additions & 7 deletions examples/Statik.Examples.Pages/Statik.Examples.Pages.csproj
Original file line number Diff line number Diff line change
@@ -1,21 +1,20 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp2.1</TargetFramework>
<TargetFramework>netcoreapp3.1</TargetFramework>
<LangVersion>7.1</LangVersion>
<!--
This is required for compiling razor views in a console app.
It is supposed to be fixed in 2.1, so we can remove it then.
https://github.com/aspnet/Razor/issues/1212
-->
This is required for compiling razor views in a console app.
It is supposed to be fixed in 2.1, so we can remove it then.
https://github.com/aspnet/Razor/issues/1212
-->
<PreserveCompilationContext>true</PreserveCompilationContext>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\..\src\Statik.Mvc\Statik.Mvc.csproj" />
<ProjectReference Include="..\..\src\Statik\Statik.csproj" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Markdig" Version="0.15.0" />
<PackageReference Include="Microsoft.AspNetCore.Mvc" Version="2.1.1" />
<PackageReference Include="Markdig" Version="0.18.0" />
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp2.1</TargetFramework>
<TargetFramework>netcoreapp3.1</TargetFramework>
<LangVersion>7.1</LangVersion>
</PropertyGroup>
<ItemGroup>
Expand Down
5 changes: 1 addition & 4 deletions src/Statik.Files/Statik.Files.csproj
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<TargetFrameworks>netcoreapp3.1</TargetFrameworks>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.StaticFiles" Version="2.1.1" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Statik\Statik.csproj" />
</ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion src/Statik.Files/WebBuilderExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ private static void RegisterFileInfo(this IWebBuilder webBuilder, IFileProvider

webBuilder.Register(requestPath, async context =>
{
var env = context.RequestServices.GetRequiredService<IHostingEnvironment>();
var env = context.RequestServices.GetRequiredService<IWebHostEnvironment>();
var statileFileOptions = Options.Create(new StaticFileOptions());
statileFileOptions.Value.FileProvider = fileProvider;
Expand Down
9 changes: 3 additions & 6 deletions src/Statik.Markdown/Statik.Markdown.csproj
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<TargetFramework>netcoreapp3.1</TargetFramework>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Markdig" Version="0.15.3" />
<PackageReference Include="YamlDotNet" Version="5.2.0" />
<PackageReference Include="Markdig" Version="0.18.0" />
<PackageReference Include="YamlDotNet" Version="8.0.0" />
</ItemGroup>

</Project>
5 changes: 1 addition & 4 deletions src/Statik.Mvc/Statik.Mvc.csproj
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<TargetFramework>netcoreapp3.1</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Mvc" Version="2.1.1" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Statik\Statik.csproj" />
</ItemGroup>
Expand Down
20 changes: 18 additions & 2 deletions src/Statik.Mvc/WebBuilderExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Reflection.Emit;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.Abstractions;
using Microsoft.AspNetCore.Mvc.Infrastructure;
using Microsoft.AspNetCore.Routing;
using Microsoft.Extensions.DependencyInjection;
Expand All @@ -9,11 +15,21 @@ namespace Statik.Mvc
{
public static class WebBuilderExtensions
{
public static void RegisterMvcServices(this IWebBuilder webBuilder)
public static void RegisterMvcServices(this IWebBuilder webBuilder, params Assembly[] additionalParts)
{
var callingAssembly = Assembly.GetCallingAssembly();
webBuilder.RegisterServices(services =>
{
services.AddMvc();
var parts = additionalParts.ToList();
if (!parts.Contains(callingAssembly))
{
parts.Add(callingAssembly);
}
var b = services.AddMvc();
foreach (var part in parts)
{
b.AddApplicationPart(part);
}
});
}

Expand Down
2 changes: 1 addition & 1 deletion src/Statik/Embedded/EmbeddedDirectoryInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public EmbeddedDirectoryInfo(string path)

public long Length => -1;

public string PhysicalPath => _path;
public string PhysicalPath => null;

public string Name => Path.GetFileName(_path);

Expand Down
4 changes: 1 addition & 3 deletions src/Statik/Embedded/EmbeddedFile.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
using Microsoft.AspNetCore.Http;

namespace Statik.Embedded
namespace Statik.Embedded
{
internal class EmbeddedFile
{
Expand Down
10 changes: 1 addition & 9 deletions src/Statik/Embedded/EmbeddedFileInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,7 @@ public long Length
}
}

public string PhysicalPath
{
get
{
EnsureExists();

return _file.ResourceName;
}
}
public string PhysicalPath => null;

public string Name
{
Expand Down
4 changes: 1 addition & 3 deletions src/Statik/Embedded/EmbeddedFileProvider.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection;
Expand Down
2 changes: 1 addition & 1 deletion src/Statik/Hosting/IHostModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ namespace Statik.Hosting
{
public interface IHostModule
{
void Configure(IApplicationBuilder app, IHostingEnvironment env);
void Configure(IApplicationBuilder app, IWebHostEnvironment env);

void ConfigureServices(IServiceCollection services);

Expand Down
26 changes: 7 additions & 19 deletions src/Statik/Hosting/Impl/HostBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
using System.Reflection;
using Microsoft.AspNetCore;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Hosting.Internal;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.TestHost;
using Microsoft.Extensions.DependencyInjection;
Expand Down Expand Up @@ -48,14 +47,9 @@ private class InternalWebHost : IWebHost
factory.AddConsole();
})
.ConfigureServices(services => {
services.AddSingleton<Startup>();
services.AddSingleton(modules);
services.AddSingleton(typeof(IStartup), sp =>
{
var hostingEnvironment = sp.GetRequiredService<IHostingEnvironment>();
return new ConventionBasedStartup(StartupLoader.LoadMethods(sp, typeof(Startup), hostingEnvironment.EnvironmentName));
});
})
.UseStartup<Startup>()
.Build();
}

Expand Down Expand Up @@ -96,19 +90,13 @@ private class InternalVirtualHost : IVirtualHost
_appBase = appBase;
Pages = new ReadOnlyCollection<Page>(modules.SelectMany(x => x.Pages).ToList());
_testServer = new TestServer(new WebHostBuilder()
.UseSetting(WebHostDefaults.ApplicationKey, Assembly.GetEntryAssembly().GetName().Name)
.ConfigureLogging(factory => {
factory.AddConsole();
})
.ConfigureServices(services => {
services.AddSingleton<Startup>();
.UseSetting(WebHostDefaults.ApplicationKey, Assembly.GetEntryAssembly().GetName().Name)
.ConfigureLogging(factory => { factory.AddConsole(); })
.ConfigureServices(services =>
{
services.AddSingleton(modules);
services.AddSingleton(typeof(IStartup), sp =>
{
var hostingEnvironment = sp.GetRequiredService<IHostingEnvironment>();
return new ConventionBasedStartup(StartupLoader.LoadMethods(sp, typeof(Startup), hostingEnvironment.EnvironmentName));
});
}));
})
.UseStartup<Startup>());
}

public IReadOnlyCollection<Page> Pages { get; }
Expand Down
2 changes: 1 addition & 1 deletion src/Statik/Hosting/Impl/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public void ConfigureServices(IServiceCollection services)
}

// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
app.UseDeveloperExceptionPage();
foreach(var module in _modules)
Expand Down
1 change: 0 additions & 1 deletion src/Statik/Pages/IPageDirectoryLoader.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using Microsoft.Extensions.FileProviders;
using Microsoft.Extensions.FileSystemGlobbing;

namespace Statik.Pages
{
Expand Down
12 changes: 7 additions & 5 deletions src/Statik/Statik.csproj
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<TargetFrameworks>netcoreapp3.1</TargetFrameworks>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore" Version="2.1.1" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="2.1.1" />
<PackageReference Include="Microsoft.AspNetCore.TestHost" Version="2.1.1" />
<PackageReference Include="System.Threading.Tasks.Dataflow" Version="4.9.0" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="3.1.0" />
<PackageReference Include="Microsoft.Extensions.FileProviders.Abstractions" Version="3.1.0" />
<PackageReference Include="Microsoft.AspNetCore.Http.Abstractions" Version="2.2.0" />
<PackageReference Include="Microsoft.AspNetCore.Hosting.Abstractions" Version="2.2.0" />
<PackageReference Include="Microsoft.Extensions.FileSystemGlobbing" Version="3.1.0" />
<PackageReference Include="Microsoft.AspNetCore.TestHost" Version="3.1.0" />
</ItemGroup>
</Project>
2 changes: 1 addition & 1 deletion src/Statik/Web/Impl/WebBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ class HostModule : IHostModule, IPageRegistry
Pages = new ReadOnlyCollection<Page>(_pages.Values.ToList());
}

public void Configure(IApplicationBuilder app, IHostingEnvironment env)
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
app.Use(async (context, next) => {
Expand Down
10 changes: 5 additions & 5 deletions test/Statik.Files.Tests/Statik.Files.Tests.csproj
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netcoreapp2.1</TargetFramework>
<TargetFramework>netcoreapp3.1</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.7.2" />
<PackageReference Include="xunit" Version="2.3.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.3.1" />
<DotNetCliToolReference Include="dotnet-xunit" Version="2.3.1" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.4.0" />
<PackageReference Include="xunit" Version="2.4.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.1" />
<DotNetCliToolReference Include="dotnet-xunit" Version="2.4.1" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\src\Statik.Files\Statik.Files.csproj" />
Expand Down
8 changes: 4 additions & 4 deletions test/Statik.Mvc.Tests/Statik.Mvc.Tests.csproj
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netcoreapp2.1</TargetFramework>
<TargetFramework>netcoreapp3.1</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.7.2" />
<PackageReference Include="xunit" Version="2.3.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.3.1" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.4.0" />
<PackageReference Include="xunit" Version="2.4.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.1" />
<DotNetCliToolReference Include="dotnet-xunit" Version="2.3.1" />
</ItemGroup>
<ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion test/Statik.Tests/EmbeddedFileProviderTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ private IFileProvider BuildFileProvider(string prefix, IAssemblyResourceResolver
{
if (assembly == null)
assembly = BuildTestAssemblyResourceResolver();
return new EmbeddedFileProvider(assembly, prefix);
return new Embedded.EmbeddedFileProvider(assembly, prefix);
}
}
}
4 changes: 2 additions & 2 deletions test/Statik.Tests/HostingTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ public async Task Can_create_virtual_host()
private IHostModule BuildTestHostModule()
{
var hostModule = new Mock<IHostModule>();
hostModule.Setup(x => x.Configure(It.IsAny<IApplicationBuilder>(), It.IsAny<IHostingEnvironment>()))
.Callback((IApplicationBuilder app, IHostingEnvironment env) => {
hostModule.Setup(x => x.Configure(It.IsAny<IApplicationBuilder>(), It.IsAny<IWebHostEnvironment>()))
.Callback((IApplicationBuilder app, IWebHostEnvironment env) => {
app.Run(async context => {
await context.Response.WriteAsync("Hello, World! " + context.Request.Path + " " + context.Request.PathBase);
});
Expand Down
14 changes: 7 additions & 7 deletions test/Statik.Tests/Statik.Tests.csproj
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netcoreapp2.1</TargetFramework>
<TargetFramework>netcoreapp3.1</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="FluentAssertions" Version="5.4.1" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.7.2" />
<PackageReference Include="Moq" Version="4.8.3" />
<PackageReference Include="xunit" Version="2.3.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.3.1" />
<DotNetCliToolReference Include="dotnet-xunit" Version="2.3.1" />
<PackageReference Include="FluentAssertions" Version="5.9.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.4.0" />
<PackageReference Include="Moq" Version="4.13.1" />
<PackageReference Include="xunit" Version="2.4.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.1" />
<DotNetCliToolReference Include="dotnet-xunit" Version="2.4.1" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\src\Statik\Statik.csproj" />
Expand Down

0 comments on commit 331fae9

Please sign in to comment.