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

Feature/proper wasm configuration #1270

Merged
merged 3 commits into from
Nov 17, 2023
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
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -209,4 +209,5 @@ src/Cake.Scripts/tools/tools/
codealike.json

# Rider
.idea/
.idea/
*.received.*
15 changes: 15 additions & 0 deletions Conventions.sln
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Rocket.Surgery.Conventions.
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Rocket.Surgery.Conventions.Configuration.Json", "src\Conventions.Configuration.Json\Rocket.Surgery.Conventions.Configuration.Json.csproj", "{E1057DB4-D09A-4D4D-BFDD-C14BDC725E58}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Sample.BlazorWasm", "sample\Sample.BlazorWasm\Sample.BlazorWasm.csproj", "{3609DE86-A1DB-4070-96EB-3BD19320DDFD}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -639,6 +641,18 @@ Global
{E1057DB4-D09A-4D4D-BFDD-C14BDC725E58}.Release|x64.Build.0 = Release|Any CPU
{E1057DB4-D09A-4D4D-BFDD-C14BDC725E58}.Release|x86.ActiveCfg = Release|Any CPU
{E1057DB4-D09A-4D4D-BFDD-C14BDC725E58}.Release|x86.Build.0 = Release|Any CPU
{3609DE86-A1DB-4070-96EB-3BD19320DDFD}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{3609DE86-A1DB-4070-96EB-3BD19320DDFD}.Debug|Any CPU.Build.0 = Debug|Any CPU
{3609DE86-A1DB-4070-96EB-3BD19320DDFD}.Debug|x64.ActiveCfg = Debug|Any CPU
{3609DE86-A1DB-4070-96EB-3BD19320DDFD}.Debug|x64.Build.0 = Debug|Any CPU
{3609DE86-A1DB-4070-96EB-3BD19320DDFD}.Debug|x86.ActiveCfg = Debug|Any CPU
{3609DE86-A1DB-4070-96EB-3BD19320DDFD}.Debug|x86.Build.0 = Debug|Any CPU
{3609DE86-A1DB-4070-96EB-3BD19320DDFD}.Release|Any CPU.ActiveCfg = Release|Any CPU
{3609DE86-A1DB-4070-96EB-3BD19320DDFD}.Release|Any CPU.Build.0 = Release|Any CPU
{3609DE86-A1DB-4070-96EB-3BD19320DDFD}.Release|x64.ActiveCfg = Release|Any CPU
{3609DE86-A1DB-4070-96EB-3BD19320DDFD}.Release|x64.Build.0 = Release|Any CPU
{3609DE86-A1DB-4070-96EB-3BD19320DDFD}.Release|x86.ActiveCfg = Release|Any CPU
{3609DE86-A1DB-4070-96EB-3BD19320DDFD}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down Expand Up @@ -687,6 +701,7 @@ Global
{888D214B-CD66-4122-81D2-27C9A2B0F34F} = {AE3FEC8E-20F1-492C-A131-3EFD0196E7A5}
{2B6D82A7-3C3A-49C5-9C00-A92CFAECCE0D} = {8FFDF555-DB50-45F9-9A2D-6410F39151C3}
{E1057DB4-D09A-4D4D-BFDD-C14BDC725E58} = {8FFDF555-DB50-45F9-9A2D-6410F39151C3}
{3609DE86-A1DB-4070-96EB-3BD19320DDFD} = {96A0AEB7-ACFA-491C-8FA5-2A1BE4E8B718}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {439897C2-CCBD-44FE-B2DC-A3E4670ADA59}
Expand Down
2 changes: 1 addition & 1 deletion Directory.Build.targets
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
Condition="'$(MSBuildProjectName)'!='.build'"
/>
<!-- <PackageReference Include="Microsoft.CodeAnalysis.PublicApiAnalyzers" IncludeAssets="analyzers;build;buildMultitargeting;buildTransitive" PrivateAssets="All" /> -->
<PackageReference Include="Rocket.Surgery.MSBuild.Metadata" IncludeAssets="analyzers;build;buildMultitargeting;buildTransitive" PrivateAssets="All" />
<PackageReference Include="Rocket.Surgery.MSBuild.SourceLink" IncludeAssets="analyzers;build;buildMultitargeting;buildTransitive" PrivateAssets="All" />
<PackageReference Include="Polyfill" IncludeAssets="analyzers;build;buildMultitargeting;buildTransitive" PrivateAssets="All" />
<PackageReference Include="Roslynator.Analyzers" IncludeAssets="analyzers;build;buildMultitargeting;buildTransitive" PrivateAssets="All" />
<PackageReference Include="Roslynator.Formatting.Analyzers" IncludeAssets="analyzers;build;buildMultitargeting;buildTransitive" PrivateAssets="All" />
<PackageReference Include="Roslynator.CodeAnalysis.Analyzers" IncludeAssets="analyzers;build;buildMultitargeting;buildTransitive" PrivateAssets="All" />
Expand Down
8 changes: 7 additions & 1 deletion Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,15 @@
<PackageVersion Include="Rocket.Surgery.MSBuild.GitVersion" Version="1.1.4" />
<PackageVersion Include="Rocket.Surgery.MSBuild.JetBrains.Annotations" Version="1.1.4" Condition="'$(MSBuildProjectName)'!='.build'" />
<!-- <PackageVersion Include="Microsoft.CodeAnalysis.PublicApiAnalyzers" Version="2.9.8" /> -->
<PackageVersion Include="Rocket.Surgery.MSBuild.Metadata" Version="1.1.0" />
<PackageVersion Include="Rocket.Surgery.MSBuild.SourceLink" Version="1.1.4" />
<PackageVersion Include="Polyfill" Version="1.32.1" />
<PackageVersion Include="Roslynator.Analyzers" Version="4.6.2" />
<PackageVersion Include="Roslynator.Formatting.Analyzers" Version="4.6.2" />
<PackageVersion Include="Roslynator.CodeAnalysis.Analyzers" Version="4.6.2" />
<PackageVersion Include="Spectre.Console.Analyzer" Version="0.47.0" />
<PackageVersion Include="Verify.AngleSharp" Version="4.3.1" />
<PackageVersion Include="Verify.ImageMagick" Version="3.2.2" />
<PackageVersion Include="YamlDotNet" Version="13.7.1" />
</ItemGroup>
<ItemGroup>
<PackageVersion Include="GitVersion.Tool" Version="5.12.0" />
Expand All @@ -29,6 +32,7 @@
<PackageVersion Include="DryIoc.dll" Version="5.4.3" />
<PackageVersion Include="DryIoc.Microsoft.DependencyInjection" Version="6.2.0" />
<PackageVersion Include="Microsoft.AspNetCore.Components.WebAssembly" Version="8.0.0" />
<PackageVersion Include="Microsoft.AspNetCore.Components.WebAssembly.Server" Version="8.0.0" />
<PackageVersion Include="Microsoft.AspNetCore.Components.WebAssembly.DevServer" Version="8.0.0" />
<PackageVersion Include="Microsoft.AspNetCore.TestHost" Version="8.0.0" />
<PackageVersion Include="Microsoft.Extensions.Configuration" Version="8.0.0" />
Expand Down Expand Up @@ -72,12 +76,14 @@
<PackageVersion Include="FluentAssertions" Version="6.12.0" />
<PackageVersion Include="FluentAssertions.Analyzers" Version="0.26.0" />
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="17.8.0" />
<PackageVersion Include="Microsoft.Playwright" Version="1.39.0" />
<PackageVersion Include="Rocket.Surgery.Extensions.Testing.FakeItEasy" Version="8.0.3" />
<PackageVersion Include="Rocket.Surgery.Extensions.Testing.XUnit" Version="8.0.3" />
<PackageVersion Include="xunit" Version="2.6.1" />
<PackageVersion Include="xunit.analyzers" Version="1.5.0" />
<PackageVersion Include="xunit.runner.visualstudio" Version="2.5.3" />
<PackageVersion Include="Verify.Xunit" Version="22.5.0" />
<PackageVersion Include="Verify.Playwright" Version="2.3.0" />
<PackageVersion Include="Verify.SourceGenerators" Version="2.2.0" />
</ItemGroup>
<Import
Expand Down
3 changes: 2 additions & 1 deletion sample/Sample.BlazorWasm/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@

var builder = await WebAssemblyHostBuilder
.CreateDefault(args)
.ConfigureRocketSurgery(provider => Enumerable.Empty<IConventionWithDependencies>());
.ConfigureRocketSurgery(Imports.GetConventions);
// .ConfigureRocketSurgery(provider => Enumerable.Empty<IConventionWithDependencies>());
builder.RootComponents.Add<App>("#app");
builder.RootComponents.Add<HeadOutlet>("head::after");

Expand Down
59 changes: 33 additions & 26 deletions sample/Sample.BlazorWasm/Sample.BlazorWasm.csproj
Original file line number Diff line number Diff line change
@@ -1,37 +1,44 @@
<Project Sdk="Microsoft.NET.Sdk.BlazorWebAssembly">
<Import Project="../../src/Conventions.Configuration.Json/build/Rocket.Surgery.Conventions.Configuration.Json.props" />
<Import Project="../../src/Conventions.Configuration.Yaml/build/Rocket.Surgery.Conventions.Configuration.Yaml.props" />

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>
<PropertyGroup>
<TargetFramework>net8.0-browser</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>

<ItemGroup>
<ItemGroup>
<ProjectReference
Include="..\..\src\Conventions.Analyzers\Rocket.Surgery.Conventions.Analyzers.csproj"
IncludeAssets="all"
OutputItemType="Analyzer"
ReferenceOutputAssembly="false"
/>
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly" />
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.DevServer" PrivateAssets="all" />
<ProjectReference Include="..\Sample.Core\Sample.Core.csproj" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\src\WebAssembly.Hosting\Rocket.Surgery.WebAssembly.Hosting.csproj" />
</ItemGroup>

<ItemGroup>
<Content Update="wwwroot\appsettings.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Update="wwwroot\appsettings.Development.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Update="wwwroot\appsettings.local.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
</ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly" />
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.DevServer" PrivateAssets="all" />
<ProjectReference Include="..\..\src\Conventions.Configuration.Yaml\Rocket.Surgery.Conventions.Configuration.Yaml.csproj" />
<ProjectReference Include="..\..\src\Conventions.Configuration.Json\Rocket.Surgery.Conventions.Configuration.Json.csproj" />
<ProjectReference Include="..\Sample.Core\Sample.Core.csproj" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\src\WebAssembly.Hosting\Rocket.Surgery.WebAssembly.Hosting.csproj" />
</ItemGroup>
<ItemGroup>
<AssemblyMetadata Include="ContentRootPath" Value="$([System.IO.Path]::GetDirectoryName($(MSBuildThisFileDirectory)))" />
</ItemGroup>
<ItemGroup>
<Content Update="wwwroot\appsettings.yml">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Update="wwwroot\appsettings.Development.yaml">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Update="wwwroot\appsettings.local.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
</ItemGroup>
<Import Project="../../src/Conventions.Configuration.Yaml/build/Rocket.Surgery.Conventions.Configuration.Yaml.targets" />
<Import Project="../../src/Conventions.Configuration.Json/build/Rocket.Surgery.Conventions.Configuration.Json.targets" />
</Project>
Binary file added sample/Sample.BlazorWasm/msbuild.binlog
Binary file not shown.
3 changes: 0 additions & 3 deletions sample/Sample.BlazorWasm/wwwroot/appsettings.Development.json

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
dev: true
3 changes: 0 additions & 3 deletions sample/Sample.BlazorWasm/wwwroot/appsettings.json

This file was deleted.

1 change: 1 addition & 0 deletions sample/Sample.BlazorWasm/wwwroot/appsettings.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
app: true
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,5 @@
<None Include="build/*.*" Pack="true" PackagePath="build" />
<None Include="buildMultiTargeting/*.*" Pack="true" PackagePath="buildMultiTargeting" />
<None Include="buildTransitive/*.*" Pack="true" PackagePath="buildTransitive" />
<!-- <None Include="$(MSBuildThisFileDirectory)\..\Conventions.Analyzers\bin\$(Configuration)\netstandard2.0\Rocket.Surgery.Conventions.Analyzers.dll" Pack="true" PackagePath="analyzers/dotnet/cs" Visible="false" />-->
</ItemGroup>
</Project>
29 changes: 29 additions & 0 deletions src/Conventions.Configuration.Json/JsonBrowserConvention.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#if BROWSER
using Microsoft.Extensions.Configuration.Json;
using Rocket.Surgery.Conventions.Setup;

namespace Rocket.Surgery.Conventions.Configuration.Json;

/// <summary>
/// Json configuration conventions
/// </summary>
[ExportConvention]
public class JsonBrowserConvention : ISetupConvention
{
/// <inheritdoc />
public void Register(IConventionContext context)
{
context.AppendEnvironmentConfiguration(
(configurationBuilder, environment) => environment == "local"
? new[]
{
new ConfigurationBuilderDelegateResult(
"appsettings.local.json",
stream => new JsonStreamConfigurationSource { Stream = stream ?? throw new ArgumentNullException(nameof(stream)) }
)
}
: Array.Empty<ConfigurationBuilderDelegateResult>()
);
}
}
#endif
31 changes: 5 additions & 26 deletions src/Conventions.Configuration.Json/JsonConvention.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System.Runtime.InteropServices;
#if !BROWSER
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Configuration.Json;
using Rocket.Surgery.Conventions.Setup;
Expand All @@ -15,34 +15,12 @@ public class JsonConvention : ISetupConvention
public void Register(IConventionContext context)
{
context.AppendApplicationConfiguration(
configurationBuilder =>
{
if (RuntimeInformation.IsOSPlatform(OSPlatform.Create("BROWSER")) || context.Properties.ContainsKey("BlazorWasm"))
{
return Array.Empty<ConfigurationBuilderDelegateResult>();
}

return new[]
{
new ConfigurationBuilderDelegateResult("appsettings.json", LoadJsonFile(configurationBuilder, "appsettings.json"))
};
}
configurationBuilder => new[] { new ConfigurationBuilderDelegateResult("appsettings.json", LoadJsonFile(configurationBuilder, "appsettings.json")) }
);
context.AppendEnvironmentConfiguration(
(configurationBuilder, environment) =>
(configurationBuilder, environment) => new[]
{
if (RuntimeInformation.IsOSPlatform(OSPlatform.Create("BROWSER")) || context.Properties.ContainsKey("BlazorWasm"))
{
return Array.Empty<ConfigurationBuilderDelegateResult>();
}

return new[]
{
new ConfigurationBuilderDelegateResult(
$"appsettings.{environment}.json",
LoadJsonFile(configurationBuilder, $"appsettings.{environment}.json")
)
};
new ConfigurationBuilderDelegateResult($"appsettings.{environment}.json", LoadJsonFile(configurationBuilder, $"appsettings.{environment}.json"))
}
);
}
Expand All @@ -58,3 +36,4 @@ public void Register(IConventionContext context)
};
}
}
#endif
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>netstandard2.1;netstandard2.0;net6.0;net7.0;net8.0</TargetFrameworks>
<TargetFrameworks>netstandard2.1;netstandard2.0;net6.0;net7.0;net8.0;net8.0-browser</TargetFrameworks>
<PackageDescription>Adds support for loading yaml configuration files</PackageDescription>
<PackageTags>$(PackageTags);reflection</PackageTags>
</PropertyGroup>
Expand All @@ -20,4 +20,9 @@
<InternalsVisibleTo Include="Rocket.Surgery.Web.Hosting" />
<InternalsVisibleTo Include="Rocket.Surgery.WebAssembly.Hosting" />
</ItemGroup>
<ItemGroup>
<None Include="build/*.*" Pack="true" PackagePath="build" />
<None Include="buildMultiTargeting/*.*" Pack="true" PackagePath="buildMultiTargeting" />
<None Include="buildTransitive/*.*" Pack="true" PackagePath="buildTransitive" />
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<Project>
</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<Project>
<ItemGroup>
<_BlazorJsonConfigurationFiles Include="wwwroot\appsettings*.json" />
<AssemblyMetadata Include="BlazorConfigurationFile" Value="@(_BlazorJsonConfigurationFiles -> '%(Filename)%(Extension)')" />
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<Project>
<Import Project="..\build\$(MSBuildThisFile)" />
</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<Project>
<Import Project="..\build\$(MSBuildThisFile)" />
</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<Project>
<Import Project="..\build\$(MSBuildThisFile)" />
</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<Project>
<Import Project="..\build\$(MSBuildThisFile)" />
</Project>
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>netstandard2.1;netstandard2.0;net6.0;net7.0;net8.0</TargetFrameworks>
<TargetFrameworks>netstandard2.1;netstandard2.0;net6.0;net7.0;net8.0;net8.0-browser</TargetFrameworks>
<PackageDescription>Adds support for loading yaml configuration files</PackageDescription>
<PackageTags>$(PackageTags);reflection</PackageTags>
</PropertyGroup>
Expand All @@ -15,10 +15,16 @@
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Configuration" />
<PackageReference Include="NetEscapades.Configuration.Yaml" />
<PackageReference Include="YamlDotNet" />
<PackageReference Include="Microsoft.Extensions.Configuration.FileExtensions" Condition="$(TargetFramework) != 'net8.0-browser'" />
<InternalsVisibleTo Include="Rocket.Surgery.Conventions.CommandLine" />
<InternalsVisibleTo Include="Rocket.Surgery.Hosting" />
<InternalsVisibleTo Include="Rocket.Surgery.Web.Hosting" />
<InternalsVisibleTo Include="Rocket.Surgery.WebAssembly.Hosting" />
</ItemGroup>
<ItemGroup>
<None Include="build/*.*" Pack="true" PackagePath="build" />
<None Include="buildMultiTargeting/*.*" Pack="true" PackagePath="buildMultiTargeting" />
<None Include="buildTransitive/*.*" Pack="true" PackagePath="buildTransitive" />
</ItemGroup>
</Project>
11 changes: 11 additions & 0 deletions src/Conventions.Configuration.Yaml/StaticConfigurationProvider.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
using Microsoft.Extensions.Configuration;

namespace Rocket.Surgery.Conventions.Configuration.Yaml;

internal class StaticConfigurationProvider : ConfigurationProvider
{
public StaticConfigurationProvider(IDictionary<string, string> data)
{
Data = data ?? throw new ArgumentNullException(nameof(data));
}
}
11 changes: 11 additions & 0 deletions src/Conventions.Configuration.Yaml/StaticConfigurationSource.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
using Microsoft.Extensions.Configuration;

namespace Rocket.Surgery.Conventions.Configuration.Yaml;

internal class StaticConfigurationSource: IConfigurationSource
{
public IDictionary<string,string> Data { get; set; }

public IConfigurationProvider Build(IConfigurationBuilder builder)
=> new StaticConfigurationProvider(Data);
}
Loading
Loading