Skip to content

Commit

Permalink
2023-11-10 EoD Prep for 2.0 release (#37)
Browse files Browse the repository at this point in the history
* 2023-11-10 EoD Prep for 2.0 release

* 2023-11-14 2.0.0
  • Loading branch information
MarkStega authored Nov 14, 2023
1 parent 18e921e commit f2c05fd
Show file tree
Hide file tree
Showing 12 changed files with 81 additions and 142 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/GithubActionsRelease.yml
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ jobs:
- name: Use prelease dotnet
uses: actions/setup-dotnet@v2
with:
dotnet-version: '7.0.x'
dotnet-version: '8.x'
include-prerelease: true

- name: Get the version
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/GithubActionsWIP.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ jobs:
- name: Use prelease dotnet
uses: actions/setup-dotnet@v2
with:
dotnet-version: '7.0.x'
dotnet-version: '8.x'
include-prerelease: true

- name: Build CompressedStaticFiles.AspNetCore 🔧
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
bld/
[Bb]in/
[Oo]bj/
.artifacts/
PublishedExample/

# Visual Studio 2015 cache/options directory
.vs/
Expand Down
Original file line number Diff line number Diff line change
@@ -1,22 +1,21 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>net7.0;</TargetFrameworks>
<IsTestProject>true</IsTestProject>
<IsPackable>false</IsPackable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.TestHost" Version="7.0.2" />
<PackageReference Include="coverlet.collector" Version="3.2.0">
<PackageReference Include="Microsoft.AspNetCore.TestHost" Version="8.0.0" />
<PackageReference Include="coverlet.collector" Version="6.0.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="FluentAssertions" Version="6.9.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.4.1" />
<PackageReference Include="NSubstitute" Version="4.4.0" />
<PackageReference Include="xunit" Version="2.4.2" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.5">
<PackageReference Include="FluentAssertions" Version="6.12.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.9.0-preview-23531-01" />
<PackageReference Include="NSubstitute" Version="5.1.0" />
<PackageReference Include="xunit" Version="2.6.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.3">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
Expand Down
2 changes: 2 additions & 0 deletions CompressedStaticFiles.AspNet.sln
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,11 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
.gitignore = .gitignore
.github\ISSUE_TEMPLATE\bug_report.md = .github\ISSUE_TEMPLATE\bug_report.md
.github\dependabot.yml = .github\dependabot.yml
Directory.Build.props = Directory.Build.props
.github\workflows\GithubActionsRelease.yml = .github\workflows\GithubActionsRelease.yml
.github\workflows\GithubActionsWIP.yml = .github\workflows\GithubActionsWIP.yml
LICENSE = LICENSE
LocalBuild.cmd = LocalBuild.cmd
README.md = README.md
ReleaseNotes.md = ReleaseNotes.md
EndProjectSection
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>net7.0;</TargetFrameworks>
<Version>1.0.0</Version>
<Version>2.0.0</Version>
<Authors>Simon Ziegler;Mark Stega;Peter Andersson;Andrey Kudashkin;Mathias Raacke,Arian Kadkhoda</Authors>
<Company>Simon Ziegler;Mark Stega;Peter Andersson;Andrey Kudashkin;Mathias Raacke,Arian Kadkhoda</Company>
<Description>
Expand Down
65 changes: 4 additions & 61 deletions CompressedStaticFiles.Example/CompressedStaticFiles.Example.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>
Expand All @@ -10,67 +9,11 @@
<ProjectReference Include="..\CompressedStaticFiles.AspNet\CompressedStaticFiles.AspNet.csproj" />
</ItemGroup>


<!--All subsequent code contributed by https://github.com/SQL-MisterMagoo-->

<!--Compression directives (Note that the patterns are relative to wwwroot)-->
<PropertyGroup>
<!--Paths to tools, tasks, and extensions are calculated relative to the BlazorWebAssemblySdkDirectoryRoot.
But there does not seem to be a property for that, so after much trial and error, using the property
ILLinkTasksAssembly seems most reliable as it contains the same value whether the build is run from VS
or the command line, unlike many others such as MSBuildSDKsPath.
If a better property is identified, this can be changed.
-->

<!-- First, we strip the property value back to the root SDKs level and then down into the WebAssembly SDK -->
<_SDKRoot>$(ILLinkTasksAssembly.Substring(0,$(ILLinkTasksAssembly.LastIndexOf('Microsoft.NET.ILLink.Tasks'))))</_SDKRoot>
<BlazorWebAssemblySdkDirectoryRoot>$(_SDKRoot)Microsoft.NET.Sdk.BlazorWebAssembly\</BlazorWebAssemblySdkDirectoryRoot>

<!-- The next two lines are derived from examples posted by the .NET Foundation. -->
<_BlazorWebAssemblySdkTasksAssembly>$(BlazorWebAssemblySdkDirectoryRoot)tools\net472\Microsoft.NET.Sdk.BlazorWebAssembly.Tasks.dll</_BlazorWebAssemblySdkTasksAssembly>
<_BlazorWebAssemblySdkToolAssembly>$(BlazorWebAssemblySdkDirectoryRoot)tools\$(TargetFramework)\Microsoft.NET.Sdk.BlazorWebAssembly.Tool.dll</_BlazorWebAssemblySdkToolAssembly>
<CompressionIncludePatterns>$(CompressionIncludePatterns);**/*.css;**/*.js</CompressionIncludePatterns>
<BuildCompressionFormats>gzip;brotli</BuildCompressionFormats>
<PublishCompressionFormats>gzip;brotli</PublishCompressionFormats>
</PropertyGroup>

<!-- The next two lines are Copyright (c) .NET Foundation. All rights reserved. -->
<UsingTask TaskName="Microsoft.NET.Sdk.BlazorWebAssembly.BrotliCompress" AssemblyFile="$(_BlazorWebAssemblySdkTasksAssembly)" />
<UsingTask TaskName="Microsoft.NET.Sdk.BlazorWebAssembly.GzipCompress" AssemblyFile="$(_BlazorWebAssemblySdkTasksAssembly)" />

<!--
This target runs after build. If you want to run after Publish, change:
- AfterTargets should be set to "Build"
- "ProjectDir" in MyStaticFiles should be changed to "PublishDir"
-->
<Target Name="CustomGZipAndBrotliCompression" AfterTargets="Build">

<Message Importance="High" Text="======= Gzip/Brotli task assembly details=$(_BlazorWebAssemblySdkTasksAssembly)" />
<Message Importance="High" Text="======= Brotli tool assembly details=$(_BlazorWebAssemblySdkToolAssembly)" />
<Message Importance="High" Text="======= Brotli tool executable details=$(_RazorSdkDotNetHostFileName)" />
<Message Importance="High" Text="======= Brotli tool path details=$(_RazorSdkDotNetHostDirectory)" />

<!--************* THIS IS WHERE YOU CHOOSE WHAT TO COMPRESS *****************
you probably don't want to change anything else - just this ItemGroup-->

<ItemGroup>
<MyStaticFiles Include="$(ProjectDir)/wwwroot/**/*.css" />
<MyStaticFiles Include="$(ProjectDir)/wwwroot/**/*.js" />
</ItemGroup>

<!--Call the BlazorWebAssembly Task GZipCompress and store the results in MyCompressedFiles-->
<GZipCompress FilesToCompress="@(MyStaticFiles)" OutputDirectory="$(IntermediateOutputPath)compress\">
<Output TaskParameter="CompressedFiles" ItemName="MyCompressedFiles" />
</GZipCompress>

<!--Call the BlazorWebAssembly Task BrotliCompress and store the results in MyCompressedFiles-->
<BrotliCompress FilesToCompress="@(MyStaticFiles)" OutputDirectory="$(IntermediateOutputPath)compress\" ToolAssembly="$(_BlazorWebAssemblySdkToolAssembly)" ToolExe="$(_RazorSdkDotNetHostFileName)" ToolPath="$(_RazorSdkDotNetHostDirectory)">
<Output TaskParameter="CompressedFiles" ItemName="MyCompressedFiles" />
</BrotliCompress>

<!--Log what we have done-->
<Message Importance="High" Text="======= Brotli/GZip Compression For @(MyCompressedFiles-&gt;Count()) Static Files =======" />
<Message Importance="High" Text=" Compressed: %(MyCompressedFiles.OriginalItemSpec)%(MyCompressedFiles.Extension)" />

<!--Rename/move the compressed files back to to the correct place/names as they have "hashed" names at this stage.-->
<Move SourceFiles="%(MyCompressedFiles.FullPath)" DestinationFiles="%(MyCompressedFiles.OriginalItemSpec)%(MyCompressedFiles.Extension)" />

</Target>

</Project>
76 changes: 10 additions & 66 deletions CompressedStaticFiles.Example/Pages/Index.razor
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@

<h1 style="margin-top: 48px;">How to detect file compression</h1>

<p>
To demonstrate the compressed files execute the 'LocalBuild.cmd' at the root of this repository and follow
the instructions to browse to the demonstration.
</p>
<p>
Press F12 to enter your browser's development tools and select the network tab (we did this on Edge here).
Click any css or js file (except for blazor.server.js, which as an ASP.NET framework file isn't compressed)
Expand All @@ -43,77 +47,17 @@
</p>

<pre><code>
&lt;PropertyGroup&gt;
&lt;!--Paths to tools, tasks, and extensions are calculated relative to the BlazorWebAssemblySdkDirectoryRoot.
But there does not seem to be a property for that, so after much trial and error, using the property
ILLinkTasksAssembly seems most reliable as it contains the same value whether the build is run from VS
or the command line, unlike many others such as MSBuildSDKsPath.
If a better property is identified, this can be changed.
--&gt;

&lt;!-- First, we strip the property value back to the root SDKs level and then down into the WebAssembly SDK --&gt;
&lt;_SDKRoot&gt;$(ILLinkTasksAssembly.Substring(0,$(ILLinkTasksAssembly.LastIndexOf('Microsoft.NET.ILLink.Tasks'))))&lt;/_SDKRoot&gt;
&lt;BlazorWebAssemblySdkDirectoryRoot&gt;$(_SDKRoot)\Microsoft.NET.Sdk.BlazorWebAssembly\&lt;/BlazorWebAssemblySdkDirectoryRoot&gt;

&lt;!-- The next four lines are Copyright (c) .NET Foundation. All rights reserved. --&gt;
&lt;_BlazorWebAssemblySdkTasksTFM Condition=" '$(MSBuildRuntimeType)' == 'Core'"&gt;net6.0&lt;/_BlazorWebAssemblySdkTasksTFM&gt;
&lt;_BlazorWebAssemblySdkTasksTFM Condition=" '$(MSBuildRuntimeType)' != 'Core'"&gt;net472&lt;/_BlazorWebAssemblySdkTasksTFM&gt;
&lt;_BlazorWebAssemblySdkTasksAssembly&gt;$(BlazorWebAssemblySdkDirectoryRoot)tools\$(_BlazorWebAssemblySdkTasksTFM)\Microsoft.NET.Sdk.BlazorWebAssembly.Tasks.dll&lt;/_BlazorWebAssemblySdkTasksAssembly&gt;
&lt;_BlazorWebAssemblySdkToolAssembly&gt;$(BlazorWebAssemblySdkDirectoryRoot)tools\net6.0\Microsoft.NET.Sdk.BlazorWebAssembly.Tool.dll&lt;/_BlazorWebAssemblySdkToolAssembly&gt;
&lt;/PropertyGroup&gt;

&lt;!-- The next two lines are Copyright (c) .NET Foundation. All rights reserved. --&gt;
&lt;UsingTask TaskName="Microsoft.NET.Sdk.BlazorWebAssembly.BrotliCompress" AssemblyFile="$(_BlazorWebAssemblySdkTasksAssembly)" /&gt;
&lt;UsingTask TaskName="Microsoft.NET.Sdk.BlazorWebAssembly.GzipCompress" AssemblyFile="$(_BlazorWebAssemblySdkTasksAssembly)" /&gt;




&lt;!--
This target runs after build. If you want to run after Publish, change:
- AfterTargets should be set to "Build"
- "ProjectDir" in MyStaticFiles should be changed to "PublishDir"
--&gt;
&lt;Target Name="CustomGZipAndBrotliCompression" AfterTargets="Build"&gt;

&lt;!--************* THIS IS WHERE YOU CHOOSE WHAT TO COMPRESS *****************
you probably don't want to change anything else - just this ItemGroup--&gt;

&lt;ItemGroup&gt;
&lt;MyStaticFiles Include="$(ProjectDir)/wwwroot/**/*.css" /&gt;
&lt;MyStaticFiles Include="$(ProjectDir)/wwwroot/**/*.js" /&gt;
&lt;/ItemGroup&gt;

&lt;!--Call the BlazorWebAssembly Task GZipCompress and store the results in MyCompressedFiles--&gt;
&lt;GZipCompress FilesToCompress="@@(MyStaticFiles)" OutputDirectory="$(IntermediateOutputPath)compress\"&gt;
&lt;Output TaskParameter="CompressedFiles" ItemName="MyCompressedFiles" /&gt;
&lt;/GZipCompress&gt;

&lt;!--Call the BlazorWebAssembly Task BrotliCompress and store the results in MyCompressedFiles--&gt;
&lt;BrotliCompress OutputDirectory="$(IntermediateOutputPath)compress\" FilesToCompress="@@(MyStaticFiles)" ToolAssembly="$(_BlazorWebAssemblySdkToolAssembly)" ToolExe="$(_RazorSdkDotNetHostFileName)" ToolPath="$(_RazorSdkDotNetHostDirectory)"&gt;
&lt;Output TaskParameter="CompressedFiles" ItemName="MyCompressedFiles" /&gt;
&lt;/BrotliCompress&gt;

&lt;!--Log what we have done--&gt;
&lt;Message Importance="High" Text="======= Brotli/GZip Compression For @@(MyCompressedFiles-&gt;Count()) Static Files =======" /&gt;
&lt;Message Importance="High" Text=" Compressed: %(MyCompressedFiles.OriginalItemSpec)%(MyCompressedFiles.Extension)" /&gt;

&lt;!--Rename/move the compressed files back to to the correct place/names as they have "hashed" names at this stage.--&gt;
&lt;Move SourceFiles="%(MyCompressedFiles.FullPath)" DestinationFiles="%(MyCompressedFiles.OriginalItemSpec)%(MyCompressedFiles.Extension)" /&gt;

&lt;/Target&gt;
&lt;ItemGroup&gt;
&lt;ProjectReference Include="..\CompressedStaticFiles.AspNetCore\CompressedStaticFiles.AspNetCore.csproj" /&gt;
&lt;/ItemGroup&gt;
&lt;ItemGroup&gt;
&lt;Folder Include="wwwroot\images\" /&gt;
&lt;/ItemGroup&gt;
<!--Compression directives (Note that the patterns are relative to wwwroot)-->
&lt;PropertyGroup&gt;
&lt;CompressionIncludePatterns&gt;$(CompressionIncludePatterns);**/*.css;**/*.js&lt;/CompressionIncludePatterns&gt;
&lt;BuildCompressionFormats&gt;gzip;brotli&lt;/BuildCompressionFormats&gt;
&lt;PublishCompressionFormats&gt;gzip;brotli&lt;/&lt;PublishCompressionFormats&gt;
&lt;/PropertyGroup&gt;
</code></pre>

<h1 style="margin-top: 48px;">Attribution</h1>

<p>Thanks to the following:</p>
<ul>
<li>This project is a fork of Peter Andersson's from whose original <a href="https://github.com/AnderssonPeter/CompressedStaticFiles" target="_blank">CompressedStaticFiles repo</a>; and</li>
<li><a href="https://github.com/SQL-MisterMagoo" target="_blank">SQL-MisterMagoo</a> for providing the MSBUILD code that performs Brotli and GZIP static file compression.</li>
</ul>
16 changes: 16 additions & 0 deletions Directory.Build.props
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<Project>
<PropertyGroup>
<ArtifactsPath>$(MSBuildThisFileDirectory).artifacts</ArtifactsPath>
</PropertyGroup>

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>disable</ImplicitUsings>
<Nullable>disable</Nullable>
</PropertyGroup>

<PropertyGroup>
<AccelerateBuildsInVisualStudio>false</AccelerateBuildsInVisualStudio>
</PropertyGroup>

</Project>
21 changes: 21 additions & 0 deletions LocalBuild.cmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
@echo off
set argDestination=%1
if "%1" == "" set argDestination=PublishedExample

echo Destination is %argDestination%
echo ...
echo Beginning publish
echo ...
dotnet publish CompressedStaticFiles.Example/CompressedStaticFiles.Example.csproj --configuration Debug --output %argDestination%
echo ...
echo Build results
echo ...
dir "%argDestination%" /s
echo ...
echo Executing published example
echo ...
cd %argDestination%
compressedstaticfiles.example.exe"
cd ..
rd %argDestination% /s /q
pause
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ This project allows you to serve precompressed files to the browser without havi
## Getting Started

### Precompress content
Static nonimage files have to be precompressed using [Gzip](https://en.wikipedia.org/wiki/Gzip) and/or [Brotli](https://en.wikipedia.org/wiki/Brotli), see the example CompressedStaticFiles.csproj for an automated methodology for producing compressed css & js files.
The files must have the exact same filename as the source + `.br` or `.gzip` (`index.html` would be `index.html.br` for the Brotli version).
Static nonimage files have to be precompressed using [Gzip](https://en.wikipedia.org/wiki/Gzip) and/or [Brotli](https://en.wikipedia.org/wiki/Brotli), see CompressedStaticFiles.Example.csproj for an automated methodology for producing compressed css & js files.
The files must have the same filename as the source + `.br` or `.gzip` (`index.html` would be `index.html.br` for the Brotli version).

### Encode images
Modern browsers support new image formats like webp and avif they can store more pixels per byte.
Expand All @@ -67,4 +67,4 @@ We built this cloned project because:

- We wanted to update to the currently supported version of .NET;
- To make some refinements that were to our taste; and
- To add MSBuild code to the [example CSPROJ file](https://github.com/Material-Blazor/CompressedStaticFiles.AspNet/blob/main/CompressedStaticFiles.Example/CompressedStaticFiles.Example.csproj#L37) to build Brotli and Gzip compressed CSS and JS files, using a method contributed by [SQL-MisterMagoo](https://github.com/SQL-MisterMagoo).
- To add MSBuild code to the [example CSPROJ file](https://github.com/Material-Blazor/CompressedStaticFiles.AspNet/blob/main/CompressedStaticFiles.Example/CompressedStaticFiles.Example.csproj#L13) to build Brotli and Gzip compressed CSS and JS files.
13 changes: 13 additions & 0 deletions ReleaseNotes.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,19 @@ title: ReleaseNotes
# Release Notes


#### [2.0.0](https://github.com/Material-Blazor/CompressedStaticFiles.AspNet/tree/2.0.0)

Released 2023-11-14

**Updates**
- .Net 8.0
- Example uses MSBuild to produce compressed static files when published
- LocalBuild.cmd introduced to perform a local publish/run for demonstration purposes

**Breaking Changes**

**Known issues**

#### [1.0.0](https://github.com/Material-Blazor/CompressedStaticFiles.AspNet/tree/1.0.0)

Released 2022-10-26
Expand Down

0 comments on commit f2c05fd

Please sign in to comment.